var pathname = window.location.pathname;
var URL = window.location.href;
var queryString = "";


$(document).ready(function(){	

	tabReady = true;		
	/*When going back to a tabbed page a variable containing what tab they were on last is collected */
	
		// Checks to see if paramater attached to URL - if so, it collects the query string and stores it
		var query = '?';
		queryString = "";
		
		if (URL.indexOf(query) !=-1){
			var pathArray = URL.split( '?' );
			queryString = pathArray[1];
			
		}
		
		// Checks if there is a query string to get tab number appended to it, else it just gets tab number
		var tabPath = "";
		if(queryString != null && queryString != undefined && queryString != ""){
		
			tabPath = queryString.split( '#=' );
			queryString = tabPath[0];	
		} else {
			tabPath = URL.split( '#=' );			
		}
				
			var tabNumber = "";
			tabNumber += tabPath[1];
			
				
	/*If the URL contained a tab number then it would call the select tab (passing the collected variable) 
	and also the display tab functions to show the last tab*/
	if (URL.indexOf(tabNumber) !=-1 && URL.indexOf("tab") !=-1){
		
		selectTab(tabNumber, queryString);
		tabNumber = tabNumber.substring(3);
		displayTab("c" + tabNumber);	
		
	}	 
	
});


function displayTab(tab){
	   
	
	
	if (tabReady){		
/* This hides all tab content */
	$('.tabs').fadeOut('fast', function() {tabReady = false});
	$('.tabs').css('display', 'none');
	
	$('#'+tab).fadeIn('slow', function() {  $('#'+tab).css('display','inline'); tabReady = true; });
	 
	}	
	
	
}

function selectTab(tabS){	
	
	
	
/*	if (tabS != "tab1"){ */
		var parameter = "";
		if(queryString != null && queryString != undefined && queryString != ""){
			parameter = "?" + queryString;
		}
		
		window.location.replace(pathname + parameter + "#=" + tabS);
		
/*	}
	else
	{
		window.location.replace(pathname);
	} */
	
	
	$('.link').css('backgroundImage', 'url(/resources/images/tabs/tab4.jpg)');
	$('.linkTall').css('backgroundImage', 'url(/resources/images/tabs/tab4.jpg)');
	$('.linkSmall').css('backgroundImage', 'url(/resources/images/tabs/tab4.jpg)');
	$('#' + tabS).css('backgroundImage', 'url(/resources/images/tabs/tab6.jpg)');	
	
}
	
 var usingTabs = true;