
function getImageName(image) {
	var gifPath = image.src.split("/");
	var gifName =  gifPath[gifPath.length-1];	
	return gifName;
}

var SubNavs = new Array();

var IndustryNavItems = [ ["Login","client_login.aspx"],
						 ["Company","Company.htm"]];

var ProductNavItems = [ ["Industry","Industry.htm"],
						 ["Request","request.htm"]]; 

var CompanyNavItems = [ ["Design","design.asp"],
						 ["Equipment","equipment.htm"]];
				

var ResourcesNavItems = [ ["Brochures","brochures.htm"],
						  ["Demo","javascript:void(window.open('LSTDemo.html','LST_10','width=1024,height=768,top=10,left=10'))"]];
						  
						  
var SupportNavItems = [ [ ]];
						   //["Video","video.htm"], 
						   //["Drawings","index.htm"],
						   //["SpecifiersGuides","index.htm"]];
							
menuIsActive = false;
var ULs;
var productline, pastproducts, upcomingevents, resources, downloads, departments;
var wait = 850;

window.onload = function() {

	CreatePrimarySubNavigation(IndustryNavItems);
	CreatePrimarySubNavigation(ProductNavItems);
	CreatePrimarySubNavigation(CompanyNavItems);
	CreatePrimarySubNavigation(ResourcesNavItems);
	CreatePrimarySubNavigation(SupportNavItems);
	AssignPrimarySubNavs();	
	

}
function AssignPrimarySubNavs() {
	var primaryNav = document.getElementById("primaryNav");
	if(primaryNav) {
		var navItems = primaryNav.getElementsByTagName("LI");
		departments = navItems.item(0);
		departments.isOpen = false;
		departments.subNav = SubNavs[0];
		departments.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(departments)', wait);
		};
		departments.onmouseover = OpenPrimaryNav;
		departments.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { departments.subNav.style.visibility = 'hidden';}",wait);
		}

		productline = navItems.item(0);
		productline.isOpen = false;
		productline.subNav = SubNavs[0];
		productline.onmouseover = OpenPrimaryNav;
		productline.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(productline)', wait);
		};
		productline.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { productline.subNav.style.visibility = 'hidden';}",wait);
		}
		
		pastproducts = navItems.item(1);
		pastproducts.isOpen = false;
		pastproducts.subNav = SubNavs[1];
		pastproducts.onmouseover = OpenPrimaryNav;
		pastproducts.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(pastproducts)', wait);
		};
		pastproducts.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { pastproducts.subNav.style.visibility = 'hidden';}",wait);
		}
		
		upcomingevents = navItems.item(2);
		upcomingevents.isOpen = false;
		upcomingevents.subNav = SubNavs[2];
		upcomingevents.onmouseover = OpenPrimaryNav;
		upcomingevents.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(upcomingevents)', wait);
		};
		upcomingevents.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { upcomingevents.subNav.style.visibility = 'hidden';}",wait);
		}
		
		resources = navItems.item(3);
		resources.isOpen = false;
		resources.subNav = SubNavs[3];
		resources.onmouseover = OpenPrimaryNav;
		resources.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(resources)', wait);
		};
		resources.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { resources.subNav.style.visibility = 'hidden';}",wait);
		}
		
		downloads = navItems.item(4);
		downloads.isOpen = false;
		downloads.subNav = SubNavs[4];
		downloads.onmouseover = OpenPrimaryNav;
		downloads.subNav.onmouseout = function() {
			menuIsActive = false;
			setTimeout('CloseNav(downloads)', wait);
		};
		downloads.onmouseout = function() {
			menuIsActive = false;
			var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
			this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
			setTimeout("if(!menuIsActive) { downloads.subNav.style.visibility = 'hidden';}",wait);
		}
	}
}
function checkNavState(navItem) {
	menuIsActive = false;
	setTimeout('CloseNav('+ navItem +')', wait);
}
function OpenPrimaryNav() {
	menuIsActive = true;
	var imageName = getImageName(this.getElementsByTagName("IMG")[0]);
    downloadOffsetLeft = 5
	this.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OnPrimary/" + imageName;
	this.subNav.style.left = findPosX(this) + "px";
	
	if(is_ie6) {
		this.subNav.style.top =  (findPosY(this) + this.offsetHeight + 12) + "px";
		this.subNav.style.left =  (findPosX(this) + this.offsetWidth - this.subNav.offsetWidth + 13) + "px";

	}
	else if(is_ie7) {
		this.subNav.style.top =  (findPosY(this) + this.offsetHeight + 12) + "px";
		this.subNav.style.left =  (findPosX(this) + this.offsetWidth - this.subNav.offsetWidth + 11) + "px";

	}
	else if(is_safari) {
		this.subNav.style.top =  (findPosY(this) + this.offsetHeight + 8) + "px";
		this.subNav.style.left =  (findPosX(this) + this.offsetWidth - this.subNav.offsetWidth + 11) + "px";

	}
	else {
		this.subNav.style.top =  (findPosY(this) + this.offsetHeight - 3) + "px";
		this.subNav.style.left =  (findPosX(this) + this.offsetWidth - this.subNav.offsetWidth + 3) + "px";

	}
		if(downloads.subNav == this.subNav) {
		this.subNav.style.left =  (findPosX(this) + this.offsetWidth - this.subNav.offsetWidth - downloadOffsetLeft) + "px";
	}

	departments.subNav.style.visibility = "hidden";
	productline.subNav.style.visibility = "hidden";
	pastproducts.subNav.style.visibility = "hidden";
	upcomingevents.subNav.style.visibility = "hidden";
	resources.subNav.style.visibility = "hidden";
	downloads.subNav.style.visibility = "hidden";
	
	this.subNav.style.visibility = "visible";
}
function CloseNav(nav) {	
	if(!menuIsActive) {
	var imageName = getImageName(nav.getElementsByTagName("IMG")[0]);
	nav.getElementsByTagName("IMG")[0].src = primarypath + "/primarynav/OffPrimary/" + imageName;
	nav.subNav.style.visibility = "hidden";
	}
}

function FocusNavItem() {
	menuIsActive = true;
	var imagePathArray = this.src.split("/");
	var imageName = imagePathArray[imagePathArray.length-1];
	this.src = primarypath + "/primarynav/On/" + imageName;
}
function DimNavItem() {
	var imagePathArray = this.src.split("/");
	var imageName = imagePathArray[imagePathArray.length-1];
	this.src = primarypath + "/primarynav/Off/" + imageName;
}

function CreatePrimarySubNavigation(navItems) {

	var primarySubNav = document.createElement("DIV"); 
	primarySubNav.className = "PrimarySubNav";

    if(navItems.length > 1) {
	primarySubNav.appendChild(CreateNavEdgeItem("navOpening", "NavHeader"));
	}
	for(i=0; i<=navItems.length-1; i++) {
		primarySubNav.appendChild(CreateNavItem(navItems[i]));
	}
	
	if(navItems.length > 1) {
	primarySubNav.appendChild(CreateNavEdgeItem("navFooter", "NavFooter"));
	}
	
	var docBody = document.getElementsByTagName("body")[0];
	docBody.appendChild(primarySubNav);
	SubNavs[SubNavs.length] = primarySubNav;

}
function CreateNavEdgeItem(thisClass, imageName) {
	var edgeItem = document.createElement("DIV");
	edgeItem.className = thisClass;
	var edgeImage = document.createElement("IMG");	
	edgeImage.src = primarypath + "/primarynav/backgrounds/" + imageName + ".gif";
	edgeItem.appendChild(edgeImage);
	return edgeItem;
}
function CreateNavItem(navItem) {
      var newNavItem = document.createElement("DIV");
      var imgWrapper = document.createElement("DIV");
      imgWrapper.className = "wrapper";
	  var imgText = document.createElement("IMG");
      newNavItem.className = "item";
      imgText.src = primarypath + "/primarynav/Off/" + navItem[0] + ".gif";
      imgText.className = "arrow";
      imgText.onmouseover = FocusNavItem;
      imgText.onmouseout = DimNavItem;
      imgText.onclick = function() {
            document.location = navItem[1];
      }
      imgWrapper.appendChild(imgText);                
      newNavItem.appendChild(imgWrapper);       
      //newNavItem.appendChild(imgText);  
      return newNavItem;
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function popup(url, width, height, features) {
	var newWinWidth = width;
	var newWinHeight = height;
	var newWinTop = (screen.availHeight/2) - (newWinHeight/2);
	var newWinLeft = (screen.availWidth/2) - (newWinWidth/2);
	var newWin = window.open(url, "newWin", 
							 "top="+ newWinTop +
							 ",left="+ newWinLeft +
							 ",width="+ newWinWidth +
							 ",height="+ newWinHeight +
							 "," + features);
	newWin.focus();
}

