﻿// JavaScript Document
var ErrorGapX = 0;   
var ErrorGapY =0;
var dmID = '';
var anchorID = '';
var activeMenuDivID = '';
var dmShowing = false;
var hdMouseoverImgShowing = false;
var dmTimeout = '';
var newPageAnchor = '';
var newPageMenu = '';
var isIE = false;

// Get List Item object for each menu list item in the main nav
//var li0 = document.getElementById("menu0");
//var a0 = document.getElementById("ancwhy");
//a0.addEventListener('onmouseover',showDropMenu(i),false);

//var li0 = document.getElementById("menu1");
// $(li1).mouseover(function() {
//		showDropMenu(0);
//	}, function() {
// 		delayHideMenu(0);
// 	}
// 
// 
// 
// 
// 
// 
// 
//var li1 = document.getElementById("menu2");
//var li2 = document.getElementById("menu3");
//var li3 = document.getElementById("menu4");
//var li4 = document.getElementById("menu5");
//var li5 = document.getElementById("menu6");
//var li6 = document.getElementById("menu7");


if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	isIE = true;
// var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
// if (ieversion>=8)
//  document.write("You're using IE8 or above")
// else if (ieversion>=7)
//  document.write("You're using IE7.x")
// else if (ieversion>=6)
//  document.write("You're using IE6.x")
// else if (ieversion>=5)
//  document.write("You're using IE5.x")
}

var arrMouseOverTab = [false,false,false,false,false,false,false];
var arrMouseOverMenu = [false,false,false,false,false,false,false];
// This array must be updated if any of the main navigation menu pages change!!!
var arrMenuPages = ['dm_8229','dm_8222','dm_8270','dm_8274','dm_8226','dm_8227'];
var arrMenuTabs = ['ancwhy','ancproducts','ancindustries','ancpurchase','ancsupport','anccommunity'];

function delayHideMenu(i) {
//	var divID = arrMenuPages[i];
//	var ancID = arrMenuTabs[i];
//	//	dmTimeout = window.setTimeout("hideMenu('"+divID+"','"+ancID+"',"+i+");",0);
//	hideMenu(divID,ancID,i);
}

function hideMenu(menu,ancID,i) {
	// if menu and grey tab still showing
//	if (dmShowing && hdMouseoverImgShowing)
//		// if user has exited both tab and menu when status for both lists showing as true 
//		if (!arrMouseOverTab[i] && !arrMouseOverMenu[i]) {
//			// hide the menu and remove the grey tab image
//			hideDropdown(menu,ancID);
//			//changeTabImage(0,menu);
//		}
}

function hideDropdown(menu,ancID) {
/*	var mnu = document.getElementById(menu);
	var anc = document.getElementById(ancID);
	mnu.style.display = 'none';
	anc.style.background = "transparent";
	if (ancID == newPageAnchor) {
		anc.style.color = '#FFF';
	}
	hdMouseoverImgShowing = false;
	//changeTabImage(0,menu);
	dmShowing = false; */
}

function changeTabImage(imgOn,anc) {
/*	if (imgOn) {
		anc.style.background = "transparent url(/sw/images/interface/bg_navheader_lt.gif) top right no-repeat";
		hdMouseoverImgShowing = true;
	} else {
		anc.style.background = "transparent";
		hdMouseoverImgShowing = false;
	}*/
}

function showDropMenu(i) {
/*	var ancID = '';
	var divID = arrMenuPages[i];
	var ancID = arrMenuTabs[i];
	var anc = document.getElementById(ancID);
	var mnu = document.getElementById(divID);
	var arr_Pos = findPos(anc);
	mouseOverMenu = true;
	// Reset GLOBAL variables
	dmID = divID;
	anchorID = anc;
	// maintain hover text color on the main navigation item here
	if (ancID == newPageAnchor) 
		anc.style.color = '#818285';	
	if (mnu.style.display == 'none') {
		mnu.style.top = arr_Pos[1]+23 + "px";
		mnu.style.left = arr_Pos[0] + "px";
		// adjustment to right-justify the last menu on the right
		if (divID==arrMenuPages[arrMenuPages.length-1]) {
			mnu.style.width = "300px";
			mnu.style.left = arr_Pos[0]-188 + "px";
		}
		mnu.style.display = 'block';
	}
	changeTabImage(1,anc)
	// set status of open areas (tab and menu)
	dmShowing = true; 
	hdMouseoverImgShowing = true;*/
}

function findPos(obj) {
	var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}

// function isMouseLeaveOrEnter is from http://www.dynamic-tools.net/toolbox/isMouseLeaveOrEnter/
// this function determines whether the event is the equivalent of the microsoft
// mouseleave or mouseenter events.
function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}
