// preload rollovers
preload("Images/MNavOurProducts_o.jpg");
preload("Images/MNavEducation_o.jpg");
preload("Images/MNavOurStory_o.jpg");
preload("Images/MNavVisitorsCenter_o.jpg");
preload("Images/MNavKids_o.jpg");
preload("Images/MNavRecipes_o.jpg");
preload("Images/MNavWebCam_o.jpg");

preload("Images/btnFPCalltoAction_o.gif");
preload("Images/btnFRCalltoAction_o.gif");

//populate the image array for random homepage image
arImage = new Array();
arImage[0] = "Images/HomeHero01.jpg";
arImage[1] = "Images/HomeHero02.jpg";
arImage[2] = "Images/HomeHero03.jpg";
arImage[3] = "Images/HomeHero04.jpg";
arImage[4] = "Images/HomeHero05.jpg";
arImage[5] = "Images/HomeHero06.jpg";

//Write div tag for homepage with random image
function randomBG() {
var randnum;
randnum = Math.floor(Math.random() * arImage.length);
document.write("<div id='HeroImage' style='background-image:url(" + arImage[randnum] + ");'>");
}


// handle rollovers
function mOver(Image) {
	if(Image) {
		if(Image.src.indexOf("_o") == -1) {
   			Image.src = Image.src.replace(".jpg", "_o.jpg");
	    }
	 }
	 
	 if(lastImage) {
		lastImage.src = lastImage.src.replace("_o.jpg", ".jpg");
		}	
	lastImage = Image;
}

function mOverGif(Image) {
	if(Image) {
		if(Image.src.indexOf("_o") == -1) {
   			Image.src = Image.src.replace(".gif", "_o.gif");
	    }
	 }
	 
	 if(lastImage) {
		lastImage.src = lastImage.src.replace("_o.gif", ".gif");
		}	
	lastImage = Image;
}



var lastImage;


// simple preload function
function preload(sPath) {
	var o = new Image();
	o.src = sPath;
	return o;
}



function getWindowHeight() 
{
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') 
	{
		windowHeight=window.innerHeight;
	}
	else 
	{
		if (document.documentElement&& document.documentElement.clientHeight) 
		{
			windowHeight = document.documentElement.clientHeight;
		}
		else 
		{
			if (document.body&&document.body.clientHeight) 
			{
				windowHeight = document.body.clientHeight;
			}
		}
	}
	
	return windowHeight;
}


// determine height for <div> element 
function getDivSize(DivID) {	
	d= document.getElementById(DivID)
	var divHeight = 0
	
	
	
	if(d.offsetHeight)
		{ 
		 divHeight=d.offsetHeight; 
		} 
		else if(d.style.pixelHeight)
		{ 
		 divHeight=d.style.pixelHeight; 
		} 

		
	return divHeight;
	
}

function recalcContainerHeight()
{

	var maxHeight= 768;
	var maxHeight = Math.max(maxHeight, getDivSize("MainContent") + 183);
	var maxHeight = Math.max(maxHeight, getWindowHeight());
	document.getElementById("ContentContainer").style.height = maxHeight + "px";	
	
	
	//document.getElementById("Content").style.height = CurrentMainContentSize + "px";	
	
	//alert("MH" + maxHeight);
	

	//alert("CurrentMainContentSize" + CurrentMainContentSize);
	//alert("MainContent" + getDivSize("MainContent"));
	//alert("Content" + getDivSize("Content"));
	
	
	//alert(getDivSize("MainNav") + getDivSize("Header"));
	

	
	//document.getElementById("MainContent").style.height = (getDivSize("ContentContainer") - (getDivSize("Footer") + getDivSize("Header") + getDivSize("MainNav"))) + "px"


	//maxHeight= Math.max(getDivSize("MainContent"), maxHeight);
	//maxHeight= Math.max(getWindowHeight(), maxHeight);
	//document.getElementById("MainContent").style.height = (maxHeight - 300) + "px";	


	//var	CurrentMainContentSize = maxHeight - (183);
	//document.getElementById("MCLeftColumn").style.height = getDivSize("MainContent") + "px";	
	//document.getElementById("MCMiddleColumn").style.height = getDivSize("MainContent") + "px";	
	//document.getElementById("MCRightColumn").style.height = getDivSize("MainContent") + "px";		



	//shift position of footer for IE 5.5
	document.getElementById("Footer").style.bottom = "";
	document.getElementById("Footer").style.top = (maxHeight - getDivSize("Footer")) + "px";
	document.getElementById("Footer").style.visibility = "visible";


	document.getElementById("MCLeftColumnBottom").style.bottom = "";
	document.getElementById("MCLeftColumnBottom").style.top = (maxHeight - (getDivSize("MCLeftColumnBottom") + 183)) + "px";
	
	document.getElementById("MCRightColumnBottom").style.bottom = "";
	document.getElementById("MCRightColumnBottom").style.top = (maxHeight - (getDivSize("MCRightColumnBottom") + 183)) + "px";
	
	
	document.getElementById("BottomContentGradient").style.bottom = "";
	document.getElementById("BottomContentGradient").style.top = (maxHeight - (getDivSize("BottomContentGradient") + 65)) + "px";
	document.getElementById("BottomContentGradient").style.visibility = "visible";
	
}


window.onload = function() 
{

	recalcContainerHeight();
	
}
window.onresize = function() 
{
	recalcContainerHeight();
}

function SwapImageBackground(id, imagebackground) 
{
	var identity = document.getElementById(id);
	identity.style.backgroundImage = 'url( ' + imagebackground + ')';
}

