$(document).ready(function(){
						   
	$('#tabContainer .tabpage').hide();
	$('#tabContainer .tabpage:first').show();
	$('#tabContainer ul li:first a').addClass('active');

	$('#tabContainer ul li a').click(function(e){
									  
		$(".hiddenBlock").hide();											  
											  
		$('#tabContainer ul li a').removeClass('active');
		$(this).addClass('active');
		
		var currentTab = $(this).attr('href');
		var currentA = currentTab + ' a';
		$('#tabContainer .tabpage').hide();
		$('#tabContainer .tabpage a').removeClass('active');
		$(currentA).addClass('active');
		$(currentTab).show();
		e.preventDefault();
	
		$('#tabContainer .tabpage').each(function(index) {
			
			$(this).find(".currentLayer").show();
			$(this).find(".hiddenBlock").first().show();
			$(this).find(".currentLayer").first().hide();
			
		});
	
	});

	var linkID = window.location.hash;

	if(window.location.hash) {
		
		$('#tabContainer ul li a').removeClass('active');
		$('#tabContainer .tabpage').hide();
		$(linkID).show();
	   
		var linkWithoutID = window.location.hash.substring(1);
		
		var activeLink = $('a.' + linkWithoutID);
		$(activeLink).addClass("active");
	}
	
	//prevent anchor jump
	if (location.hash) {
    window.scrollTo(0, 0);
  	}

	$(".hiddenBlock").hide();
		
	//show first section of each tab on page load	
	$('.tabpage').each(function(index) {
								
								
   			 $(this).find(".hiddenBlock").first().show();
			 $(this).find(".currentLayer").first().hide();
  	});
		
		
	$(".button").click(function (e) {
								 
								 
   			//after sub nav click get title of button to show sub section
			$(".currentLayer").show();
			$(".hiddenBlock").hide();
			
			 var divShow = "#" + $(this).attr("title");
			$(divShow).show();
			$(this).find('.currentLayer').hide();
   			 
			e.preventDefault();
			
			//if the button contained a link rel jump to the appropriate tab
			
				var tabSelector = $(this).find("a").attr("rel");
			
				if (typeof tabSelector !== 'undefined' && tabSelector !== false) {
   
   					var thisTab = "#" + $(this).find("a").attr("rel");
					$('#tabContainer .tabpage').hide();
		    		$(thisTab).show();
					
					//show current tab as hightlight
					$('.tabList li a').removeClass('active');
					var activeTab = '.tabList li a.' + tabSelector;
					$(activeTab).addClass('active');
					
					
					var thisTitle = $(this).attr("title");
					
					//show appropriate nav items highlighted
					
					var titleButtons = $('div[title|="' + thisTitle + '"]');
   					$(titleButtons).find('.currentLayer').hide();
   
				}
			 
		});
	
	
	    //gets appropriate tab and sub section if outside link used	
		
		function getUrlVars()
		{
			//gets url parameters
			var vars = [], hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for(var i = 0; i < hashes.length; i++)
			{
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			return vars;
		}
		
		var first = getUrlVars()["p"];
		
		if (typeof first !== 'undefined' && first !== false) {
			
			//if p is defined show that section
				
			$(".currentLayer").show();
			$(".hiddenBlock").hide();
			
			
			var selectedSection = "#" + first;
			$(selectedSection).show();
			
			
			var selectionSectionBtn = $('div[title|="' + first + '"]');
   			$(selectionSectionBtn).find('.currentLayer').hide();
			
			//var thisTitle = $(this).attr("title");
					
					//show appropriate nav items highlighted
					
					//var selectionSectionBtn = $('div[class|="' + first + '"]');
   					//$(selectionSectionBtn).find('.currentLayer').hide();
		}
});

