/* 
	Requires Jquery
	Requres Jquery.cookie.js
  Coder: VC (and HC) 2008-08
 */

$(document).ready(function() {
	//hides stuff
	jQuery('.tab-content').hide();
	jQuery('.tab-content h2').hide();
	
	//read the cookie value for country (requires jquery.cookie.js)
	//alert($.cookie('COUNTRY'));
	
	if($.cookie('COUNTRY') != null){
		//set the relevant country tab as active
		if($.cookie('COUNTRY') == 'england'){
			showTabContent($('.tabset li .tab-1'));
		} else if ($.cookie('COUNTRY') == 'ni'){
			showTabContent($('.tabset li .tab-2'));
		} else if ($.cookie('COUNTRY') == 'wales'){
			showTabContent($('.tabset li .tab-3'));
		} else if ($.cookie('COUNTRY') == 'scotland'){
			showTabContent($('.tabset li .tab-4'));
		}
	} else {
		//sets the first one as active
		jQuery('.tabset li:first a').addClass('active');
		jQuery('.tab-content:first').show();
	}
	
	//event handlers
	jQuery('.tabset li').click(function(event){
		showTabContent(jQuery(this).children('a'));
		event.preventDefault();
	});
	jQuery('.tabset li a').click(function(event){
		showTabContent(this);
		event.preventDefault();
		event.stopPropagation();
	});
});

function showTabContent(link){
	try{
		var href = jQuery(link).attr('href');
		
		//hide prev
		jQuery('.tab-content').hide();
		jQuery('.tabset li a.active').removeClass('active');

		//show this
		jQuery(href).show();
		jQuery(link).addClass('active');
	}
	catch(err) { }
}