/******************--------- TAB Nav homepage----------*************************/
tabs = {
	///Initialise variables///
	// Page section IDs
	contentWrapperId:'content-container',
	detailsContainer:'navigate-container',
	detailsNav:'event_tab',
	defaultTab:'event1',
/* 	listCourses: 'list-courses', */
	
	// CSS classes
	dynamicClass:'fp',
	showClass:'show',
	currentClass:'current',
	hideClass:'hide',
	
	init:function(){
		
		if(!document.getElementById || !document.createTextNode){return;}
		var container=document.getElementById(tabs.contentWrapperId);
		
		if(!container){return;}
		helper.cssjs('add',container,tabs.dynamicClass);
		tabs.initTabs();
		//tabs.initList();
	},
	
/*	showPara:function(e)
	{
		var whichPara=helper.getTarget(e);
		var toDisplay=whichPara.getAttribute('href').replace('.php', "");
		var toDisplay=toDisplay.replace(/^.*[\/\\]/g, '');
		
		if(document.getElementById(toDisplay))
			{
				var toDisplay=document.getElementById(toDisplay);
				toDisplay.style.display='block';
			}
	},*/
	
	deletePara:function(e)
	{
		var whichPara=helper.getTarget(e);
		var toDisplay=whichPara.getAttribute('href').replace('.php', "");
		var toDisplay=toDisplay.replace(/^.*[\/\\]/g, '');
		
		if(document.getElementById(toDisplay))
			{
				var toDisplay=document.getElementById(toDisplay);
				toDisplay.style.display='none';
			}
	},
	
	initTabs:function() {		
		var anchorValue = false;
		var nav=document.getElementById(tabs.detailsNav);
		if(nav && nav.getElementsByTagName('a')[0])
		{
			var links=nav.getElementsByTagName('a');
			var firstSection=links[0].href.toString().match(/#(.*)/)[1];
			firstSection=document.getElementById(firstSection);
		
			if(firstSection){
				
				if(!anchorValue) {
					var firsttab=document.getElementById(tabs.defaultTab);
					
					var essai=firsttab.getElementsByTagName('p');
					essai[essai.length-1].style.display='none';
					helper.cssjs('add',firsttab,tabs.showClass);
					tabs.currentSection=firstSection;
					// Add currentClass to first link
					helper.cssjs('add',links[0],tabs.currentClass);
					tabs.currentLink=links[0];
				}

				for(var i=0;i<links.length;i++){
					helper.addEvent(links[i],'click',tabs.showTab,false);
					helper.fixSafari(links[i]);
				}
			}
		}
	},
	
	showTab:function(e)
	{
		// Determine if an event has occoured. The anchor value could be being passed directly
		var section=helper.getTarget(e); 
		var toshow=section.getAttribute('href').toString().match(/#(.*)/)[1];
	
		/*----Get rid off the "Back Menu" link-----*/
		var backMenu=document.getElementById(toshow).getElementsByTagName('p');
		backMenu[backMenu.length-1].style.display='none';
		
		
		if(tabs.currentSection && tabs.currentLink)
		{
			helper.cssjs('remove',tabs.currentSection,tabs.showClass);
			helper.cssjs('remove',tabs.currentLink,tabs.currentClass);
		}
		// alert(toshow);
		if(document.getElementById(toshow))
		{
			var toshow=document.getElementById(toshow);
			helper.cssjs('add',toshow,tabs.showClass);
			helper.cssjs('add',section,tabs.currentClass);
			tabs.currentSection=toshow;
			tabs.currentLink=section;
		}
		helper.cancelClick(e);
	}
}
// start the show.
helper.addEvent(window, 'load', tabs.init, false);
