var pageLoaded=false;
window.onload = function(){
	for(var i=1; i<=5; i++){
		var b = document.getElementById("b"+i);
		b.style.marginTop="25px";
	}
	autoPop();
	correctPNG();	
	pageLoaded = true;
}

function moveB(id, y){
	if(pageLoaded && y>0){
		var obj = document.getElementById(id);
    	if(obj.tw!=null) obj.tw.stop();
    	obj.tw = new Tween(obj.style, "marginTop", Tween.strongEaseOut, parseInt(obj.style.marginTop), y, .5, "px");
    	obj.tw.start();
	}
}
var browser = navigator.appName;

var ie = (browser == "Microsoft Internet Explorer");

var cProductObj=-1;
var cProducts=-1;
var liHeight = "100px";
var h2OverImage = "url(../upload/images/food_content_h_out.png)";

function exProduct(pl,obj, hpl){
	if(obj!=cProductObj){
		var h = document.getElementById(hpl).value;
		var d = document.getElementById(pl);
		
		if(cProductObj!=-1) {
			cProductObj.className="out";
			cProductObj.style.backgroundImage = h2OverImage;
		}
		if(cProducts!=-1) {
			//cProducts.style.height="100px";
			if(cProducts.tw!=undefined) cProducts.tw.stop();
			cProducts.tw = new Tween(cProducts.style, "height", Tween.strongEaseOut, parseInt(cProducts.style.height), parseInt(liHeight), 1, "px");
			cProducts.tw.start();
		}
		if (d.tw != undefined) d.tw.stop();

		var _height = (ie == true) ? parseInt(h) + 50 : parseInt(h);

		d.tw = new Tween(d.style, "height", Tween.strongEaseOut, parseInt(_height), _height, 1, "px");
		d.tw.start();
		obj.className='select';
		cProductObj=obj;
		cProducts=d;
	}else{
		cProductObj.className="out";
		cProductObj.style.backgroundImage = h2OverImage;		
		if(cProducts.tw!=undefined) cProducts.tw.stop();
		cProducts.tw = new Tween(cProducts.style, "height", Tween.strongEaseOut, parseInt(cProducts.style.height), parseInt(liHeight), 1, "px");
		cProducts.tw.start();	
		cProductObj=-1;
	}
}

function autoPop(){
	var page="productListings";	
	//il=document.getElementById('mainBodyNav').getElementsByTagName('li');
	 //for(i=0;i<il.length;i++){
		//il[i].className = "out";
		//il[i].setAttribute("onmouseover", "this.className='over';");
		//il[i].setAttribute("onmouseout", "this.className='out'");
	 //}
	 if(document.getElementById("productListings")==undefined){
		 page="gaslocations";
		 liHeight="40px";
		 h2OverImage = "url(../upload/images/gas_locations_h_over.png)";
	 }
	 var il = document.getElementById(page).getElementsByTagName("li");
	 for(i=0; i<il.length; i++){
		il[i].className = "out";
		il[i].setAttribute("id", "pl"+i);
		
		
		ih2 = il[i].getElementsByTagName("h2");
		//ih2[0].setAttribute("onclick", "exProduct('pl"+i+"', this, "+il[i].offsetHeight+")");
		document.getElementById("hpl"+i).value = il[i].offsetHeight;
		il[i].style.height=liHeight;
		//ih2[0].setAttribute("onmouseover", "this.className=(this.className=='select') ? 'select' : 'over'");
		//ih2[0].setAttribute("onmouseout", "this.className=(this.className=='select') ? 'select' : 'out'");	
		//ih2[0].setAttribute("onmouseover", "productHeaderOver(this, 'over')");
		//ih2[0].setAttribute("onmouseout", "productHeaderOver(this, 'out')");
	 }
	 document.getElementById("productLoader").style.display="none";
	 document.getElementById(page).style.visibility="visible";
}

function productHeaderOver(obj, s){
	if(obj.className=="select"){
		obj.className = "select";
	}else if(s=="over"){
		obj.className = "over";
		obj.style.backgroundImage = h2OverImage;
		
	}else if(s=="out"){
		obj.style.backgroundImage = "url(../upload/images/food_content_h_out.png)";
		obj.className = "out";
	}
}

function leftNavSections(obj, s){
	if(s=="over"){
		obj.style.backgroundImage = "url(../upload/images/food_nav_over.png)";
		obj.className = "over";
	}else{
		obj.style.backgroundImage = "url(../upload/images/food_nav_out.png)";
		obj.className = "out";
	}
}

function leftNavSectionsSm(obj, s){
	if(s=="over"){
		obj.style.backgroundImage = "url(../upload/images/sideNavSmallBrown.png)";
		obj.className = "over";
	}else{
		obj.style.backgroundImage = "url(../upload/images/sideNavSmallGreen.png)";
		obj.className = "out";
	}
}
