/*
	Menu Controls v 1.0
	by Cary Clayton <cclayton@epierce.com>
	and Matt Cannon <mcannon@epierce.com>
*/

var DEBUG_MENU = false;
//=========================commented until pop up menu is done===================================
//var MENUS_ACTIVE = (is.version4);
var MENUS_ACTIVE = true;
//=========================commented until pop up menu is done===================================

var POPPED = false;
var ON_MENU = false;
var CURRENT_MENU = "";
var CURRENT_LEVEL1 = "";
var CURRENT_LEVEL2 = "";  
var CURRENT_TOP = ""; 
var thisagt=navigator.userAgent.toLowerCase();
	
setInterval("cleanUpMenus()",30000);
showGlobals();

function getMenuObject(id){
	var o = null;
	
		if (document.getElementById) { //W3C
			o = document.getElementById(id); 				
		}
		else if(document.all) { //IE4
			o = document.all[id];			
		}
		else if(document.layers) { //NN4
			o = document.layers[id];			
		}
	return o;
}

function showGlobals(){
	if (DEBUG_MENU) {
		var global_variables = "Global Variables:\n";
		global_variables += "\nMENUS_ACTIVE - "+MENUS_ACTIVE;
		global_variables += "\nPOPPED - "+POPPED;
		global_variables += "\nON_MENU - "+ON_MENU;
	}
}

/*function mouseOver(object,object1) {	

	if (MENUS_ACTIVE) {
   	ON_MENU = true;
	CURRENT_MENU = object;
		if (CURRENT_LEVEL1 != '' && CURRENT_LEVEL1 != CURRENT_MENU) {
			menuDown(CURRENT_LEVEL1);
		}	
		CURRENT_LEVEL1 = CURRENT_MENU;
		return popUp(object);
	}
	return false;
}
function mouseOut(object) {
	
	if (MENUS_ACTIVE) {
		ON_MENU = false;
		setTimeout('cleanUpMenus()',3500);
	}
	return false;
}*/

function mouseOver(img_name, img_src)

{

document[img_name].src = img_src;

}
function mouseOut(img_name, img_src)

{
document[img_name].src = img_src;
	if (MENUS_ACTIVE) {
		ON_MENU = false;
		setTimeout('cleanUpMenus()',3500);
	}

return false;
}

function popUp(object){
	if (MENUS_ACTIVE) {
//	if (DEBUG_MENU) {alert("popUp('"+object+"')");}
		return menuUp(object);
	}
	return false;
}

function popDown() {
	if (MENUS_ACTIVE) {
	if (CURRENT_LEVEL1 != '') {
			menuDown(CURRENT_LEVEL1);
			CURRENT_LEVEL1 = '';
		}	
	}
	return false;
}

function menuUp(object) {
	if (MENUS_ACTIVE) {
//		if (DEBUG_MENU) {alert("menuUp('"+object+"')");}
		var span = getMenuObject("span_"+object);
		var div = getMenuObject("div_"+object);
		var divUP = false;
		var spanUP = false;
		if (div != null) {show(div);divUP = true;}
		if (span != null) {show(span);spanUP = true;}
		
		POPPED = (spanUP && divUP);
		
	}
	return false;
}

function menuDown(object) {
	if (MENUS_ACTIVE) {
	//	if (DEBUG_MENU) {alert("menuDown('"+object+"')");}
		var span = getMenuObject("span_"+object);
		var div = getMenuObject("div_"+object);
		if (div != null) {hide(div);}
		if (span != null) {hide(span);}
	}
	return false;
}

function cleanUpMenus() {
	if (MENUS_ACTIVE) {
		if (!ON_MENU) {
			popDown();
			}
	}
	return true;
}

function show(o){
	 createIframeLayer(o);
	if (document.layers) {
		o.visibility = 'show';
		o.zIndex = '100';	//need to set zIndex for NS 4.x			
	}
	else {
		o.style.visibility = 'visible';		
		if ((thisagt.indexOf("mac")!=-1) && (thisagt.indexOf("msie") != -1) && (thisagt.indexOf("opera") == -1)){
			o.style.zIndex = '100';		//need to set zIndex for MAC IE!!!	
		}
	}
}

function hide(o){
	var toClass = (o.id.indexOf("span") >= 0) ? "menulineoff" : "menupopupoff";
	if (document.layers) {
		o.visibility = "hide";		
	}
	else {
		o.style.visibility = "hidden";	
	}
	
	removeIframeLayer(o);
	
}

function roll(img_name, img_src)

{

document[img_name].src = img_src;

}

if(!window.event && window.captureEvents) {
// set up event capturing for mouse events (add or subtract as desired) 
window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);

// set window event handlers (add or subtract as desired) 
window.onmouseover = E_getCursorHandler; 
window.onmouseout = E_getCursorHandler; 
window.onclick = E_getCursorHandler; 
window.ondblclick = E_getCursorHandler; 

// create an object to store the event properties 
window.event = new Object; 
} 

function E_getCursorHandler(e) { 
 // set event properties to global vars (add or subtract as desired) 
 window.event.clientX = e.pageX; 
 window.event.clientY = e.pageY; 
 window.event.x = e.layerX; 
 window.event.y = e.layerY; 
 window.event.screenX = e.screenX; 
 window.event.screenY = e.screenY; 

 // route the event back to the intended function 
 if ( routeEvent(e) == false ) { 
  return false; 
 } else {
  return true; 
 } 
} 

function getScrollCoords () { 
if (typeof window.pageXOffset != 'undefined') return {x: window.pageXOffset, y: window.pageYOffset}; 
else if ((!document.compatMode || document.compatMode == 'BackCompat') && document.body && typeof document.body.scrollLeft != 'undefined') return {x: document.body.scrollLeft, y: document.body.scrollTop}; 
else if (document.compatMode == 'CSS1Compat' && document.documentElement && typeof document.documentElement.scrollLeft != 'undefined') 
return {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop}; 
else return null; 
} 

function setDivXY(divID) { 
 var scroll_offset_x = 0; 
 var scroll_offset_y = 0; 

 if (document.all){ 
  //only for I.E. 
  var scrollCoords = getScrollCoords(); 
  if (scrollCoords){ 
   scroll_offset_x = scrollCoords.x; 
   scroll_offset_y = scrollCoords.y; 
  } 
 }
 
 if (document.all && (navigator.appVersion.indexOf("Mac") != -1)){ 
  //Hack for Mac - I.E. 
  scroll_offset_x += -205; 
  
  //Div positioning for mac ie is relative to the containing table (Content Table) 
  scroll_offset_y += -70; 
 } 

 var mousex = window.event.x + scroll_offset_x; // mouse location capture event 
 var mousey = window.event.y + scroll_offset_y; // mouse location capture event 
 var div = getMenuObject("div_"+divID); //getMenuObject defigned in menu_controls.js 
 //alert("x = " +mousex + " -- y = " + mousey); 

 if (div != null) { 
  if (document.layers) { 
   div.left = mousex - 200;// place popup at the mouse X (left) location 
   div.top = mousey + 10;// place popup at the mouse Y (top) location 
  }
  else { 
   div.style.left = mousex - 200; // place popup at the mouse X (left) location 
   div.style.top = mousey + 10; // place popup at the mouse Y (top) location 
  } 
 } 
} 

function showPopupMenu(menuObject)
{

if (MENUS_ACTIVE) {
   	ON_MENU = true;
	CURRENT_MENU = menuObject;
		if (CURRENT_LEVEL1 != '' && CURRENT_LEVEL1 != CURRENT_MENU) {
			menuDown(CURRENT_LEVEL1);
		}	
		CURRENT_LEVEL1 = CURRENT_MENU;
		
		return popUp(menuObject);
}
}

function setHeight(target,source,adj)
{
	
	var tarObj;
	var srcObj;
	
	if (document.getElementById) { //W3C
			tarObj = document.getElementById(target); 	
			srcObj = document.getElementById(source); 			
		}
		else if(document.all) { //IE4
			tarObj = document.all[target];	
			srcObj = document.all[source];		
		}
		else if(document.layers) { //NN4
			tarObj = document.layers[target];	
			srcObj = document.layers[source];		
		}
		
		if(tarObj != null && adj!='NaN')
		{
			if (document.layers) {
				
				tarObj.top = (GetTop(srcObj)) - adj;
				//alert(GetTop(srcObj));
			}
			else
			{			
				tarObj.style.top = (GetTop(srcObj)) - adj;
				//alert("else:"+GetTop(srcObj));
			}
		}
		
		
}

function GetLeft(c)
{
 var left = 0;
 if (c.offsetParent)while (c.offsetParent){left += c.offsetLeft;c = c.offsetParent;}
 else if (c.x) left += c.x;
 return left;
}
function GetTop(c)
{
 var top = 0;
 if (c.offsetParent) while (c.offsetParent) {top += c.offsetTop; c = c.offsetParent;}
 else if (c.y) top += c.y;
 return top;
}


function createIframeLayer(menu)
{
	var layer = document.createElement('iframe');
	layer.tabIndex = '-1';
	layer.src = 'javascript:""';
	layer.frameBorder = '0';
	layer.scrolling = 'no';
	menu.parentNode.appendChild(layer);
	
	layer.style.left = menu.offsetLeft + 'px';
	layer.style.top = menu.offsetTop + 'px';
	layer.style.width = menu.offsetWidth + 'px';
	layer.style.height = menu.offsetHeight + 'px';
}

function removeIframeLayer(menu)
{
	var layers = menu.parentNode.getElementsByTagName('iframe');
	while(layers.length > 0)
	{
		layers[0].parentNode.removeChild(layers[0]);
	}
}
