var VEHICLE_PATH ="styles/compsys/images/web/rollovers/rollover-";
var PRODUCT_PATH ="styles/compsys/images/products/sections/";

var VEHICLES = new Array();
var DEFAULT_TEXT = "";

var IS_FIXED = 0;

var d = document;

function popWindowTitle(Location, WindowTitle, WindowWidth, WindowHeight) {

msgWindow3=window.open(Location,WindowTitle,"location=no,toolbar=no,width="+WindowWidth+",height="+WindowHeight+",directories=no,status=np,scrollbars=no,resizable=yes,menubar=no");

msgWindow3.focus();

}


function preLoad()
{	
	//preload vehicle images
	var types = new Array('coach','excavator','bus','generator','truck');

	for(i=0;i<types.length;i++)
	{
		VEHICLES[types[i]] = new Image();
		VEHICLES[types[i]].src = VEHICLE_PATH + types[i] + ".jpg";
	}

	areaTags = d.getElementsByTagName("area");
	for(i=0;i<areaTags.length;i++)
	{
		
		if(areaTags[i].getAttribute("name"))
		{	
			areaTags[i].setAttribute("href","#")
			areaTags[i].setAttribute("title",areaTags[i].getAttribute("name"))
			areaTags[i].setAttribute("onmouseover","showPopUp('"+areaTags[i].getAttribute("name") +"')" );
			areaTags[i].setAttribute("onmouseout","showPopUp()" );
			areaTags[i].setAttribute("onclick","fix()" );
		}
		else
		{
			alert("area needs name attribute");
		}
	}
}

function swapTo(vType)
{
	IS_FIXED = 0;
	if(d.getElementById('rollover') && d.getElementById('rollover-'+vType))
	{
		el_rollOver = d.getElementById('rollover');
		el_swapTo = d.getElementById('rollover-'+vType);
		el_rollOver.innerHTML = el_swapTo.innerHTML;
		showPopUp();
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function fix(){
	IS_FIXED = !IS_FIXED;
}
function showPopUp(productName)
{
	if(!IS_FIXED)
	{
		el_rollOver = d.getElementById('rollover');
		pos = findPos(el_rollOver)
		el_popup = d.getElementById('popup');	
		el_popup.style.left = (pos[0]+270)+"px";
		el_popup.style.top = (pos[1]+65)+"px";
		
		if(productName == "Electronic Hand Controls")
		{
			productName = "Hand Controls" 
		}
		else if(productName == "Electronic Accelerator Pedal")
		{
			productName = "Pedals";  	
		}
					
		if(productName)
		{
			backGrdIm = 'url('+PRODUCT_PATH+'/section_thumb_'+productName.replace(" ", "_").toLowerCase()+'.jpg)';
			d.getElementById('instructions').innerHTML = d.getElementById('instructions_'+productName.replace(" ", "_").toLowerCase() ).innerHTML;
			el_popup.style.backgroundImage = backGrdIm;
		}
		else
		{
			d.getElementById('instructions').innerHTML = DEFAULT_TEXT;
			window.setTimeout(el_popup.style.backgroundImage = "", 1000);
		}
	}
}
function getElementsByClassName(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = d.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) 
		{
			break; 
		}
	}
	return elem[i];
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function MO(dt,dd)
{	
	dt.style.cursor="pointer";

	dt.onmousedown=function(){
		op = getElementsByClassName('outputPanel')
		op.innerHTML = dd.innerHTML;
	}
	/*dt.onmouseout=function(){
		op = getElementsByClassName('outputPanel')
		op.innerHTML = DEFAULT_TEXT;
	}*/
}

function doLoad()
{
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

	if(d.getElementById("panel_rhsID").childNodes.length <= 1)
	{
		d.getElementById("panel_rhsID").style.width = "0px"; 
		d.getElementById("panel_rhsID").style.padding = "0px"; 
		d.getElementById("panel_content").style.width = "624px"; 
	}
	else
	{
		if(!IE6){
			d.getElementById("panel_rhsID").style.backgroundImage = "url(styles/compsys/images/web/panel_30.png)" ; 
		}
	}
	if(d.getElementById("panel_rhsID2") && !IE6)
	{
		d.getElementById("panel_rhsID2").style.backgroundImage = "url(styles/compsys/images/web/panel_30.png)" ;
	}
	
	if(d.getElementById('rollover'))
	{
		DEFAULT_TEXT = d.getElementById('instructions').innerHTML;
		preLoad();swapTo('coach');
	}


	if(getElementsByClassName('certification') &&  getElementsByClassName('outputPanel'))
	{
		certificationEl = getElementsByClassName('certification')
		
		op = getElementsByClassName('outputPanel');
		
		DEFAULT_TEXT = op.innerHTML;
		
		for(i=0;i<certificationEl.getElementsByTagName('dt').length;i++)
		{
			new MO(certificationEl.getElementsByTagName('dt')[i], certificationEl.getElementsByTagName('dd')[i])
		}
	}


}