// JavaScript Document


Event.observe(window, "load", function() {
	hideAllTabs(); //hide all the tabs
	$$('ul.productTabs a').invoke('observe','click', swapTabs); //add listener to each tab
	setUpDefaultTab();
});

function swapTabs(e){
	var tab = Event.findElement(e, 'a').id; //get the id of the tab	
	var startPoint = tab.length - 3; 
	var whichTab = tab.substr(0, startPoint) + "Content"; 
	
	hideAllTabs(); //hide all the tabs
	resetHighlight();
	//$(whichTab).show() //show the selected content
	$(whichTab).removeClassName('hideTabContent');
	$(tab).addClassName('selectedTab'); //highlight tab
	
	//do some tracking * SR - this seems to be causing some problems at the mo
	//googleEventTrack('click',tab);
	
	Event.stop(e);
	return true;
}

function hideAllTabs(){
	//$$('div.productTabContent').invoke('hide'); //hide all the tabs
	$$('div.productTabContent').invoke('addClassName', 'hideTabContent');
}

function resetHighlight(){
	$$('ul.productTabs a').invoke('removeClassName','selectedTab');	
}

function setUpDefaultTab(){
	
	if($('exposureContent')){
		defaultTab = 'exposure';
	} else {
		defaultTab = 'keyfacts';
	}
	
	//$(defaultTab+'Content').show() //show default content
	$(defaultTab+'Content').removeClassName('hideTabContent');
	$(defaultTab+'Tab').addClassName('selectedTab'); // select default tab
	
}


