// --------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------
// behaviours - Shows and hides tabs;
// depends: 	jQuery library;
// author:		nr;
// --------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------

(function tabs() {
	
	// Set up ARIA for tabs
	$('.tabPanel .header li a').each(function(i) {
		$(this).attr('role', 'tab');
		$(this).attr('aria-selected', 'false');
		var ariaLabel = 'ariaLabel' + i;
		$(this).attr('id', ariaLabel);
		$(this.hash).attr('aria-labelledby', ariaLabel);
	});
	
	$('.tabPanel .header li.selected a').each(function() {
		$(this).attr('aria-selected', 'true');
	});
	
	// Set up ARIA for tab panels
	$('.tabPanel .content').each(function() {
		$(this).attr('role', 'tabpanel');
		$(this).attr('aria-hidden', 'true');
	});
	
	// Set up ARIA for tab panels
	$('.tabPanel .contentSelected').each(function() {
		$(this).attr('aria-hidden', 'false');
	});
	
	// Add event listener to tab header
	$('.tabPanel .header').children('p').remove().end().click(function(e) {
		var $target = $(e.target);
		var sideColClass = "sideColumn";
		if($target.is('a')) {
		
			$(this).siblings('.content').removeClass('contentSelected').attr('aria-hidden', 'true');
			$(this).siblings($target[0].hash).addClass('contentSelected').attr('aria-hidden', 'false');
			$target.attr('aria-selected', 'true').parent('li').siblings().removeClass('selected').children().attr('aria-selected', 'false').end().end().addClass('selected');
			$(".tabPanel")[ ($target.hasClass(sideColClass) ? "add" : "remove") + "Class" ](sideColClass);
			return false;
		}
	});
	
	$(".linkToTab").click(function(e) {
		$(".tabPanel .header a").each(function() {
			if (this.hash === e.target.parentNode.hash || this.hash === e.target.hash) {
				$(this).trigger("click");
			}
		});
		return false;
		
	});
	
})();

Barclaycard.sortNumber = function(a, b) {
	return a - b;
}; 

(function() {
	
	$('.stackedTabs').each(function() {
		// fix height
		
		var heights = [];
		
		$(this).find('.content').each(function() {
			heights.push($(this).height());
		});
		
		heights = heights.sort(Barclaycard.sortNumber);
		var maxHeight = heights[heights.length - 1];
		$(this).find('.content').height(maxHeight);
		
		$(this).height(maxHeight + 43);
		
	});
	
})();

// --------------------------------------------------------------------------------------------------------------------------------
// --- end of file --- 
// -------------------------------------------------------------------------------------------------------------------------------

