$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.subContentNaviWrapper li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	
	$("#vehiclePlatform").hide();
	$("#prototypeCentre").hide();
	$("#powerTrain").hide();
	$("#homologationTesting").hide();

	//On Click Event
	$("ul.subContentNaviWrapper li").click(function() {

		$("ul.subContentNaviWrapper li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	

	$("#showHide1").click(function() {
		if($("#showHide1").html() == "Read more.") {
			$("#vehiclePlatform").fadeIn();
			$(this).addClass("active"); //Add "active" class to selected tab
			$("#showHide1").html("Hide.");
		}
		else {
			$("#vehiclePlatform").fadeOut();
			$(this).addClass("inactive"); //Add "inactive" class to selected tab
			$("#showHide1").html("Read more.");
		}
		return false;
	});
	
	$("#showHide2").click(function() {
		if($("#showHide2").html() == "Read more.") {
			$("#prototypeCentre").fadeIn();
			$(this).addClass("active"); //Add "active" class to selected tab
			$("#showHide2").html("Hide.");
		}
		else {
			$("#prototypeCentre").fadeOut();
			$(this).addClass("inactive"); //Add "inactive" class to selected tab
			$("#showHide2").html("Read more.");
		}
		return false;
	});	
	
	$("#showHide3").click(function() {
		if($("#showHide3").html() == "Read more.") {
			$("#powerTrain").fadeIn();
			$(this).addClass("active"); //Add "active" class to selected tab
			$("#showHide3").html("Hide.");
		}
		else {
			$("#powerTrain").fadeOut();
			$(this).addClass("inactive"); //Add "inactive" class to selected tab
			$("#showHide3").html("Read more.");
		}
		return false;
	});	
	
	$("#showHide4").click(function() {
		if($("#showHide4").html() == "Read more.") {
			$("#homologationTesting").fadeIn();
			$(this).addClass("active"); //Add "active" class to selected tab
			$("#showHide4").html("Hide.");
		}
		else {
			$("#homologationTesting").fadeOut();
			$(this).addClass("inactive"); //Add "inactive" class to selected tab
			$("#showHide4").html("Read more.");
		}
		return false;
	});	


});

function switchHistoryLesson(whichLesson) {	
	if(window.location.href.substr(-6,6) == "#story") { window.location.href = window.location.href.replace("#story", "") + "#story"; }
	else { window.location.href += "#story"; }	
			
	for(i=1; i<26; i++) { 
		if(i != whichLesson) { 			
			$("#history" + i).css("display", "none"); 			
		} 
	}
		
	//$("#history" + whichLesson).css("display", "block");	
	$("#history" + whichLesson).animate({opacity: 'toggle'}, 1000);
}
