var isIE = ((document.all)? true  : false );
var isNS6 = ((document.getElementById && !document.all)? true: false );
var isHP = false;
var pageLoaded = false;

if (!document.getElementById){
	document.getElementById = function (id){
							if (document.all){
								return document.all[id];
							}
						}
}
function noErrorMessages () { return true; }
//window.onerror = noErrorMessages;

var keepSub = 0;
var closeInterval ;
var resFix = 0;

allSubs = ['1','2','3','4', '5','6','7','8'];
// this array holds the total width from the left of the father buttons
//fathersLoc = [71, 237, 379, 477, 542, 561, 561];
//fathersWidthAr = [168, 144, 110, 85, 85, 152,152];
fathersLoc = [71, 237, 379, 492, 549, 591, 591,591];
fathersWidthAr = [168, 144, 110, 100, 85, 152,152,152];


function openSub(num){
	if (!pageLoaded){return; }

	keepSub = num ;
	// closes all menus and children, except for keepSub
	if (num<=5){closeAllSub()};

	if (num==6)
	{
		document.getElementById("sub7").style.visibility = "hidden";
		document.getElementById("sub8").style.visibility = "hidden";
	}
	if (num==7)
	{
		document.getElementById("sub6").style.visibility = "hidden";
		document.getElementById("sub8").style.visibility = "hidden";
	}
	if (num==8)
	{
		document.getElementById("sub6").style.visibility = "hidden";
		document.getElementById("sub7").style.visibility = "hidden";
	}

	// displays the correct div
	document.getElementById("sub" + num).style.visibility = "visible";

	// father is the images that trigger the subMenu
	fatherWidth = fathersWidthAr [num-1];
	document.getElementById("sub" + num).style.width = fatherWidth ;

	if (isIE){
		resFix = (document.body.clientWidth - 668) / 2 ;

	}else if (isNS6){
		resFix = ((window.innerWidth - 668) / 2) - 10 ;
	}
	if (resFix<53) resFix=53;

	fatherLeft = fathersLoc[num-1];

	if (isHP){
		fatherLeft += 39;
	}

	document.getElementById("sub" + num).style.left = resFix + fatherLeft ;
}

function closeAllSub(){

	for (i=0; i<allSubs.length; i++){
		if (document.getElementById("sub" + allSubs[i])){
			if (allSubs[i]!=keepSub ) {
				document.getElementById("sub" + allSubs[i]).style.visibility = "hidden";
			}
		}
	}


}

function closeSubMenu()
	{
		document.getElementById("sub6").style.visibility = "hidden";
		document.getElementById("sub7").style.visibility = "hidden";
		document.getElementById("sub8").style.visibility = "hidden";
	}

function checkIfClose (num,e){
	if (isIE) e = window.event;
	if (e){
		var related;
		if(isIE) 
		{
			related = e.toElement;
		}
		else
		{
			related = e.relatedTarget;
		}
		if (related){
			eId = related.id;
			if (eId){
				if (eId.indexOf ("ditem")==-1 && eId.indexOf ("menuRow")==-1  && eId.indexOf ("subTable")==-1 && eId.indexOf ("menuFather")==-1 ){
					keepSub = 0;
					closeAllSub();
				}
			}else{
				keepSub = 0;
				closeAllSub();
			}

		}else{
			keepSub = 0;
			closeAllSub();
		}
	}
}



function hide(){
}

function init(){
	pageLoaded = true;
}


// preloading toolbar images
this["product"] = new Image();
this["product_over"] = new Image();
this["contact_us"] = new Image();
this["contact_us_over"] = new Image();
this["corp_info"] = new Image();
this["corp_info_over"] = new Image();
this["support"] = new Image();
this["support_over"] = new Image();
this["media_center"] = new Image();
this["media_center_over"] = new Image();
this["indsolutions"] = new Image();
this["indsolutions_over"] = new Image();
this["home"] = new Image();
this["home_over"] = new Image();

this["product"].src = "images/menu/product.jpg";
this["product_over"].src = "images/menu/product_over.jpg";
this["contact_us"].src = "images/menu/contact_us.jpg";
this["contact_us_over"].src = "images/menu/contact_us_over.jpg";
this["corp_info"].src = "images/menu/corp_info.jpg";
this["corp_info_over"].src = "images/menu/corp_info_over.jpg";
this["support"].src = "images/menu/support.jpg";
this["support_over"].src = "images/menu/support_over.jpg";
this["media_center"].src = "images/menu/media_center.jpg";
this["media_center_over"].src = "images/menu/media_center_over.jpg";
this["indsolutions"].src = "images/menu/industrysolutions.jpg";
this["indsolutions_over"].src = "images/menu/industrysolutions_over.jpg";
this["home"].src = "images/menu/home.jpg";
this["home_over"].src = "images/menu/home_over.jpg";

//----------------------------------------
function rollover (imgId, isOver){

	e = document.getElementById (imgId);
	var onAdd = (isOver)?("_over"):("")
	if (e){
		e.src = this[imgId+onAdd].src;
	}
}

init();