var currUrl=new String(window.location);

function playVideo() {
	$("#videoTextBG").css("height", "216px");
	$("#fermiByNatureImg").css("width", "0px");
	$("#fermiByNatureImg").css("height", "0px");
	$("#fermiByNatureImg").css("display", "none");
	$("#fermiByNatureVideo").css("display", "block");
	$("#click2Watch").css("display", "none");
}

$(document).ready(function() {

	var d=new Date();
	var currYear=d.getFullYear();
	$("#footerYear").html(currYear);

	var windowLocation = window.document.URL.toString();
	var currentPageHTMLFileName = windowLocation.substring(windowLocation.lastIndexOf('/') + 1, windowLocation.indexOf(".html"));

	switch(currentPageHTMLFileName)
	{
		case "index" :
		{
			document.title="Nuclear Generation";
			break;
		}
		case "aboutUs" :
		{
			document.title="Nuclear Generation - About Us"
			break;
		}
		case "howNuclearPlantsWork" :
		{
			document.title="Nuclear Generation - How Nuclear Plants Work"
			break;
		}
		case "fuelAndFission" :
		{
			document.title="Nuclear Generation - Fuel and Fission"
			break;
		}
		case "spentFuelStorage" :
		{
			document.title="Nuclear Generation - Spent Fuel Storage"
			break;
		}
		case "communityBenefits" :
		{
			document.title="Nuclear Generation - Community Benefits"
			break;
		}
		case "environment" :
		{
			document.title="Nuclear Generation - Environment"
			break;
		}
		case "safeAndSecure" :
		{
			document.title="Nuclear Generation - Safe and Secure"
			break;
		}
		case "emergencyPreparedness" :
		{
			document.title="Nuclear Generation - Emergency Preparedness"
			break;
		}
		case "radiationFacts" :
		{
			document.title="Nuclear Generation - Radiation Facts"
			break;
		}
		case "newsAndResources" :
		{
			document.title="Nuclear Generation - News and Resources"
			break;
		}
		case "frequentQuestions" :
		{
			document.title="Nuclear Generation - Frequent Questions"
			break;
		}
		case "dryCaskStorageProject" :
		{
			document.title="Nuclear Generation - Dry Cask Storage Project"
			break;
		}
	}
	
	$("#click2Watch").click(function() {
		playVideo();
	});
		
	$("#fermiByNatureImg").click(function() {
		playVideo();
	});
		
	var colHeight = 500;
	$.each($(".columns"), function(){
		var tmpHeight=$(this).attr("offsetHeight");
		if(tmpHeight > 0)
		{
			colHeight=Math.max(colHeight, $(this).attr("offsetHeight"));
		}
	});
	$(".columns").css("height", colHeight);
	$(".basic p").css("display", "none");

	var iter=0;
	$.each($(".basic p"), function(){
		$(this).attr("id", "submenu"+iter);
		iter+=1;
	});

	$.each($(".basic a"), function(){
		var tmp=$(this).attr("href");
		$(this).attr("id", tmp.substring(0, tmp.indexOf(".")));
	});

	var iter2=0;
	$.each($(".basic p"), function(){
		$(this).attr("class", "submenu"+iter2);
		$(this).prev().attr("class", "submenu"+iter2);
		$.each($(this).children(), function(){
			$(this).attr("class", "submenu"+iter2);
		});
		iter2+=1;
	});
	
	$(".rightColLinks").corners({
		radio: 10,
		inColor: '#FFFFFF',
		borderSize: 1,
		borderColor: '#d2cfcf'
	});
	
	var toPage=currUrl.substring(currUrl.lastIndexOf("/") + 1, currUrl.indexOf(".html"));
	var fromPage=$.cookie('fromPage');

	$(".basic a").hover(function(){$(this).css("background-color", "#E9E9FF");}, function(){$(this).css("background-color", "");$("#"+toPage).css("background-color", "#E9E9FF");});
	$("#"+toPage).css("background-color", "#E9E9FF");

	$(window).unload(function(){
		$.cookie('fromPage', toPage);
	});

	var iter3=0;
	for(iter3;iter3 < $(".basic p").length; iter3++)
	{
		if($("#"+fromPage).attr("class")==$(".basic p:eq("+iter3+")").attr("id"))
		{
			if($("#"+toPage).attr("class")!=$(".basic p:eq("+iter3+")").attr("id"))
			{
				$(".basic p:eq("+iter3+")").show();
				$(".basic p:eq("+iter3+")").animate({
						height: "0px"
				}, 400);
				$(".basic p:eq("+iter3+")").children().hide();
			}
			else
			{
				$(".basic p:eq("+iter3+")").show();
			}
		}
		else if($("#"+toPage).attr("class")==$(".basic p:eq("+iter3+")").attr("id"))
		{
			$(".basic p:eq("+iter3+")").slideDown(400);
		}
	}

});