// JavaScript Document
// By Simon Kelly
// For Samelco 
// Copyright Samelco Autiomation Systems Ltd. 2010

// remember time the page loaded, as the menu is a pain and pops up, lets delay it by a second
var hover=false;
setTimeout(okToHover,1000);
function okToHover(){
	hover=true;	
}
var cbLoad
var mainMenu=new Array();
function $(en){
	return document.getElementById(en);	
}
function loadComplete(){
	try{
		clearTimeout(cbLoad);
	}catch(e){}
	if($("aMenu")){
		popMenu();
	}else{
		cbLoad=setTimeout(loadComplete,200);
	}
}
function popMenu(){
	var menu1=new Array();
	menu1.push(new linkObj('Energy Monitoring','http://www.energy.samelco.com/monitoring.html','Energy Monitoring'));
	menu1.push(new linkObj('PowerLogic Meters','http://www.powerlogic.samelco.com/index.html','Powerlogic Meters'));
	menu1.push(new linkObj('Branch Power Meters','http://www.energy.samelco.com/bpm.html','Branch Power Meters'));
	menu1.push(new linkObj('Ethernet Gateways','http://www.powerlogic.samelco.com/egx.html','Ethernet Gateways'));
	menu1.push(new linkObj('ION Enterprise','http://www.powerlogic.samelco.com/ion.html','ION Enterprise'));
	menu1.push(new linkObj('Temporary Monitoring','http://www.energy.samelco.com/temporarymonitoring.html','Temporary Monitoring'));
	menu1.push(new linkObj('SEMS','http://www.sems.samelco.com/Samelco%20-%20SEMS%20%28Simple%20Energy%20Management%20Solutions%29.html','SEMS (Simple Energy Management Solutions)'));
	mainMenu.push(menu1);
	
	var menu2=new Array();
	menu2.push(new linkObj('Energy Reduction','http://www.energy.samelco.com/reduction.html','Energy Reduction'));
	menu2.push(new linkObj('CBUS Lighting Control','http://www.cbus.samelco.com/index.html','CBUS Lighting Control'));
	menu2.push(new linkObj('Lubio','http://www.lubio.samelco.com/index.html','Lubio Lighting Controllers'));
	menu2.push(new linkObj('Variable Speed Drives','http://www.energy.samelco.com/variablespeeddrives.html','Variable Speed Drives'));
	menu2.push(new linkObj('Energy Efficiency','http://www.sems.samelco.com/energyefficiency.html','Energy Efficiency'));
	menu2.push(new linkObj('Environmental Impact','http://www.sems.samelco.com/environmentalimpact.html','Environmental Impact'));
	mainMenu.push(menu2);
	
	var menu3=new Array();
	menu3.push(new linkObj('Panel Design &amp; Build','http://www.samelco.com/paneldesignandbuild.html','Panel Design &amp; Build'));
	menu3.push(new linkObj('C.A.D.','http://www.samelco.com/cad.html','C.A.D. (Computer Aided Design'));
	menu3.push(new linkObj('Electrical Design','http://www.samelco.com/electricaldesign.html','Electrical Design'));
	menu3.push(new linkObj('Panel Build','http://www.samelco.com/panelbuild.html','Panel Build'));
	mainMenu.push(menu3);
	
	var menu4=new Array();
	menu4.push(new linkObj('Infrastructure','http://www.samelco.com/infrastructure.html','Infrastructure'));
	menu4.push(new linkObj('Installation','http://www.samelco.com/installation.html','Installation'));
	menu4.push(new linkObj('Commissioning','http://www.samelco.com/commissioning.html','Commissioning'));
	menu4.push(new linkObj('Training','http://www.samelco.com/training.html','Training'));
	menu4.push(new linkObj('Documentation','http://www.samelco.com/documentation.html','Documentation'));
	menu4.push(new linkObj('Reporting Services','http://www.samelco.com/reportingservices.html','Reporting Services'));
	mainMenu.push(menu4);
	
	var menu5=new Array();
	menu5.push(new linkObj('About Samelco','http://www.samelco.com/aboutsamelco.html','About Samelco'));
	menu5.push(new linkObj('News','http://www.samelco.com/news.html','News'));
	menu5.push(new linkObj('Contact Samelco','http://www.samelco.com/contactsamelco.html','Contact Samelco'));
	menu5.push(new linkObj('Downloads','http://www.samelco.com/downloads.html','Downloads'));
	menu5.push(new linkObj('Tutorials','http://www.samelco.com/tutorials.html','Tutorials'));
	mainMenu.push(menu5);
	
	var html='<div class="mPad">&nbsp;</div>';
	var footer='';
	var fCount=0;
	for (var x=0; x<mainMenu.length; x++){
		html+='<a href="'+mainMenu[x][0].Link+'"';
	    html+=' onmouseover="menuOver('+x+')"';
		html+=' id="m'+x+'" title="'+mainMenu[x][0].Title+'">'+mainMenu[x][0].Label+'</a>';
		if(x<mainMenu.length-1){
			html+='<div class="cPad">&nbsp;</div>';
		}
	}
	$("aMenu").innerHTML=html;
	$("footer").innerHTML=footRub();
}
function footRub(){
	var mCount=1;
	for(var z=0; z<mainMenu.length; z++){
		mCount+=mainMenu[z].length;	
	}
	mCount=parseInt(mCount/4,10);
	var oText='<div id="footBox"><div class="footHead"><div class="hSpc2">&nbsp;</div>';
	oText+='Samelco Automation Systems Ltd.</div><div class="vSpc1">&nbsp;</div><div>';
	oText+='<div class="hSpc2">&nbsp;</div><div class="footCol">';
	var fCount=0;
	var cCount=0;
	for(z=0; z<mainMenu.length; z++){
		for(var x=0; x<mainMenu[z].length; x++){
			if(x==0){
				if(fCount!=0)oText+='<div class="footLog">&nbsp;</div>';
				oText+='<b>';
			}
			oText+='<a href="'+mainMenu[z][x].Link+'" title="'+mainMenu[z][x].Title+'">'+mainMenu[z][x].Label+'</a>';
			if(x==0)oText+='</b>';
			fCount+=1;
			if(fCount>6){
				fCount=0;
				cCount+=1;
				if(cCount<3){
					oText+='</div><div class="hSpc3">&nbsp;</div><div class="footCol">';
				}else{
					oText+='</div><div class="hSpc3">&nbsp;</div><div class="footEnd">';
				}
			}
		}	
	}
	oText+='</div></div><div class="vSpc1">&nbsp;</div></div>';
	oText+='<div class="footbase">Samelco Automation Systems Ltd.<br>Unit 6, ';
	oText+='Price Street Business Park, Park Street, Birkenhead, CH41 3PR<br>';
	oText+='Tel/Fax : 0151 647 7999 ~ Email:<a href="mailto:info@samelco.com">info@samelco.com</a>';
	oText+=' ~ Web:<a href="http://www.samelco.com">www.samelco.com</a>';
	return oText;
}
function menuOver(x){
	if(hover==false)return;
	var m=$("popUpMenu");
	var o=$("m"+x);
	var p=elementPosition(o)-o.offsetLeft+"px";
	m.style.left=p;
// pop popupmenu
	var html="";
	for(var y=0; y<mainMenu[x].length; y++){
		html+='<a href="'+mainMenu[x][y].Link+'" title="'+mainMenu[x][y].Title+'">';
		html+=mainMenu[x][y].Label+'</a>';
		//if(y<mainMenu[x].length-1)html+='<div class="cPad">&nbsp;</div>';
	}
	m.innerHTML=html;
	m.style.display="block";
}
function linkPairObj(aTitle,aLink){
	this.Title=aTitle;
	this.Link=aLink;
}
function linkObj(aLabel,aLink,aTitle){
	this.Label=aLabel;
	this.Title=aTitle;
	this.Link=aLink;
}
function pullMenu(){
	$("popUpMenu").style.display="none";
}
function elementPosition(thing){
	var objImage = thing;
	var objChild = objImage;
	var TotalLeft = 0;
	// do this as long as the current object is in a container
	while (objChild){
			 TotalLeft = TotalLeft + objChild.offsetLeft;
			 objChild = objChild.offsetParent;
	}
	TotalLeft = TotalLeft + objImage.offsetLeft;
	return TotalLeft;
}

if (top != self) top.location.replace(location.href);
document.write('<div class="aBanner" onClick="location=\'http://www.samelco.com/index.html\';"></div><div id="popUpMenu"></div><div id="aMenu"></div>');

