/* define variables for "if n4 (Netscape 4), if IE (IE 4.x), 
and if n6 (if Netscape 6/W3C-DOM compliant)" */

var n4, ie, n6;
var doc, doc2, doc3, sty;

// the variables for the window dimensions
var win_width, win_height;
var centerx, centery;
// the menu close timeout variable
var menu_close_timeout = 0;

// Delay in miliseconds
var delay = 500;

// mouse over (on) and mouseoff(off) color values
var bgcolor_on = "#FFE600";
var bgcolor_off = "#FCFCBC";
var bg_on = "images/gui2/subnav_btn2.gif";
var bg_off = "images/gui2/subnav_btn2.gif";
/* detecting browser support for certain key objects/methods and 
assembling a custom document object */

if (document.layers) {
	doc = "document.";
	doc2 = ".document.";
	doc3 = "";
	sty = "";
	n4 = true;
} else if (document.all) {
	doc = "document.all.";
	doc2 = "";
	doc3 = "";
	sty = ".style";
	ie = true;
} else if (document.getElementById) {
	doc = "document.getElementById('";
	doc2 ="')";
	doc3 ="')";
	sty = "').style";
	n6 = "true";
}

// Get dimensions of the window
function get_dimensions() {
	if (n4 || n6) {
		win_width = window.innerWidth;
		win_height = window.innerHeight;
	} else if (ie) {
		win_width = document.body.clientWidth;
		win_height = document.body.clientHeight;
	}
	centerx = win_width/2;
	centery = win_height/2;
}


// position the element on the page.
function set_pos(elem, leftPos, topPos) {
	docObj = eval(doc + elem + sty);
	if (n4 || n6) {
		docObj.left = leftPos;
		docObj.top = topPos;
	}
	if (ie) {
		docObj.pixelLeft = leftPos;
		docObj.pixelTop = topPos;
	}
}

// preload navigation images
var loaded = 0;
var navdir = "images/gui/";

function preload() {
	preloadImages();
	loaded = 1;
}

// img src swap function
function showmenu(parent, elem, state) {
	if (loaded) {
		newstate = eval(elem + "_" + state);
		if (n4) {
			menuObj = eval (doc + parent + doc2 + elem);
		} else if (ie || n6) {
			menuObj = eval (doc + elem + doc2);
		}
		menuObj.src = newstate.src;
	}
}


function change_bgcolor(divname, colorname) {
	stopall();
	if (!n4) {
		menuObj = eval(doc + divname + sty);
		menuObj.backgroundColor = colorname;
	}
}

function changebg(divname, bgname) {
	stopall();
	if (!n4) {
		menuObj = eval(doc + divname + sty);
		menuObj.background = bgname;
	}
}


// Show or hide div
function showhide(divname, state) {
	if (n4) {
		divObj = eval(doc + divname);
	} else {
		divObj = eval(doc + divname + sty);
	}
	divObj.visibility = state;
}


// variables that hold the value of the currently active (open) menu
var active_submenu1 = null;
var active_submenu2 = null;
var active_menuelem = null;
var active_topelem = null;

// Close all active menus and turns back to 'off' state
function close_menus() {
	if (active_submenu1 != null) {
		showhide(active_submenu1,'hidden');
	}
	if (active_submenu2 != null) {
		showhide(active_submenu2,'hidden');
	}
	if (active_menuelem != null) {
		changecolor(active_menuelem, offcolor);
	}
	if (active_topelem != null) {
		showmenu('nav', active_topelem,'off');
	}
}

// Close menus after a delay
function closeall() {
	menu_close_timeout = setTimeout('close_menus()', delay);
}

// Stop menus from closing
function stopall() {
	clearTimeout(menu_close_timeout);
}

// Set submenus 
function set_menu(submenu1, submenu2, menuelem, topelem) {
	stopall();
	close_menus();
	if (submenu1 != null) {
	showhide(submenu1,'visible');
	active_submenu1 = submenu1;
	}
	if (submenu2 != null) {
		showhide(submenu2,'visible');
		active_submenu2 = submenu2;
	}
	if (menuelem != null) {
		changecolor(menuelem, oncolor);
		active_menuelem = menuelem;
	}
	if (topelem != null) {
		showmenu('nav', topelem,'over');
		active_topelem = topelem;
	}
}

function init_menu() {
	preload();
	close_menus();
	stopall();
	get_dimensions();
	rootleft = 0;
	roottop = 0;
	offsetx = 150;
	offsety = 24;
	set_pos('nav', 0, 230);
	set_pos('products', rootleft + offsetx, roottop + offsety * 0);
	set_pos('news', rootleft + offsetx, roottop + offsety * 1);
	set_pos('downloads', rootleft + offsetx, roottop + offsety * 2);
	set_pos('locations', rootleft + offsetx, roottop + offsety * 3);
	set_pos('support', rootleft + offsetx, roottop + offsety * 4);
	set_pos('contactus', rootleft + offsetx, roottop + offsety * 5);
	set_pos('home', rootleft + offsetx, roottop + offsety * 6);
}
