var AddToY = 0;
var AddToX = 0;
var W3C = document.getElementById ? true : false; // IE5+, Netscape 6+, Opera 5+, Konqueror 2.1+, Mozilla and various Mozilla/Gecko-based browsers.
var NN4 = document.layers ? true : false; //Netscape Navigator 4.x.
var IE4 = document.all ? true : false; // IE version 4 (and above).
var IE = IE4;
var innerstr="";
var innerhtml = "";
if (!IE) document.captureEvents(Event.MOUSEMOVE)

	var CanHideSubMenu	=	true;

	setEvent( window, "onLoad", AddMenuIFrame )
	
	function AddMenuIFrame()
	{
		var sMenuIFrame	=	'<iframe id="DivShim" onmouseover="CanHideSubMenu = false" onmouseout="CanHideSubMenu = true; HideMenuIFrame()" name="DivShim" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; visibility:hidden;z-index:100 "></iframe>'

		document.body.insertAdjacentHTML("beforeEnd", sMenuIFrame)
	}

	function setEvent( obj, eventName, functionName )
	{
		if (document.addEventListener)
			obj.addEventListener (eventName.toLowerCase().replace("on", ""), functionName , false)
		else
			obj.attachEvent (eventName.toLowerCase(), functionName)
	}
	
	
	function HideMenuIFrame()
	{
		setTimeout('if (CanHideSubMenu) { document.getElementById("DivShim").style.visibility = "hidden"; }', 2000);
	}

	function DivSetVisible(DivRefId, state)
  {
		var DivRef = document.getElementById(DivRefId);
		var IfrRef = document.getElementById('DivShim');

		var t=0;
		var l=0;

		var xNode = document.getElementById(DivRefId);

		try
		{
			while(xNode.tagName!='BODY'){ 
       		l+=xNode.offsetLeft; 
       		t+=xNode.offsetTop; 
       		xNode=xNode.offsetParent; 
			}
		}
		catch(e)
		{
		}
		
		if(state && DivRef && IfrRef)
		{
			CanHideSubMenu	=	false;
			
			DivRef.style.visibility = "hidden";
			
			IfrRef.style.width = DivRef.offsetWidth;
			IfrRef.style.height = DivRef.offsetHeight;
			IfrRef.style.top = t 
			IfrRef.style.left = l

			IfrRef.style.visibility = "visible";
			
			var Host = location.protocol + "//" + location.hostname;

			if (frames['DivShim'].document.body.innerHTML.length == 5)
				frames['DivShim'].document.write('<html><head><link rel="stylesheet" href="' + Host + '/includes/styles.css"></head><body bgcolor="#ffcc00" topmargin=0 leftmargin=0>' + DivRef.innerHTML + '</body></html>');
			else
				frames['DivShim'].document.body.innerHTML = DivRef.innerHTML;
				
		}
		else
		{
			CanHideSubMenu	=	true;
			DivRef.style.visibility = "hidden";
			HideMenuIFrame()
				//setTimeout('if (CanHideSubMenu) { document.getElementById("' + IfrRef.id + '").style.visibility = "hidden"; }', 2000);
				//backorg("' + IfrRef.id + '") 
/*			if (IfrRef)
				IfrRef.style.visibility = "hidden"
	*/
			backorg(DivRefId);	
		}
  }


function maincolorback(whichmenu)
{
  document.all[whichmenu+'_heading'].style.backgroundColor="#ffcc00"
  document.all[whichmenu+'_main'].style.backgroundColor="#ffcc00"
  document.all[whichmenu+'_main'].style.color = "#003399"
  document.all[whichmenu+'_heading'].style.color = "#003399"
  whichmenu=""
}

function backorg(whichmenu)
{
  document.all[whichmenu+'_heading'].style.backgroundColor="#ffcc00"
  document.all[whichmenu+'_main'].style.backgroundColor="#ffcc00"
  document.all[whichmenu+'_main'].style.color = "#003399"
  document.all[whichmenu+'_heading'].style.color = "#003399"
  whichmenu=""
}

function noiddisplay(whichmenu)
{
  document.all[whichmenu+'_heading'].style.backgroundColor="#003399"
  document.all[whichmenu+'_main'].style.backgroundColor="#003399"
  document.all[whichmenu+'_main'].style.color = "#ffcc00"
  whichmenu=""
}




function display(whichmenu, xoffset, yoffset)
{
	if (whichmenu!="idMainMenu")
	{
		document.all[whichmenu+'_heading'].style.backgroundColor="#003399"
		document.all[whichmenu+'_main'].style.backgroundColor="#003399"
		document.all[whichmenu+'_main'].style.color = "#ffcc00"
		
	  DivSetVisible(whichmenu, true, xoffset, yoffset)
	}
	
	return

	//if (self.location.href.indexOf("ferrysearch.asp") == -1)
	//{
		if(IE4)
		{
			if(navigator.appVersion.indexOf("Mac") != -1) {AddToY = 0;AddToX = 0;} else {AddToY = 0;}
			document.all[whichmenu].style.pixelLeft = getAnchorPosition(whichmenu + "_heading").x + xoffset;
			document.all[whichmenu].style.pixelTop = getAnchorPosition(whichmenu + "_heading").y + yoffset;
			document.all[whichmenu].style.visibility = "visible";
		}
		else
			if(NN4)
			{
				AddToY = 0;
				document.layers[whichmenu].left = getAnchorPosition(whichmenu + "_heading").x + xoffset;
				document.layers[whichmenu].top = getAnchorPosition(whichmenu + "_heading").y + yoffset + AddToY;
				document.layers[whichmenu].visibility = "show";
			}
			else
				if(W3C)
				{
					AddToY = 0;
					document.getElementById(whichmenu).style.left = (getAnchorPosition(whichmenu + "_heading").x + xoffset) + "px";
					document.getElementById(whichmenu).style.top = (getAnchorPosition(whichmenu + "_heading").y + yoffset + AddToY) + "px";
					document.getElementById(whichmenu).style.visibility = "visible";
				}
	//}
	whichmenu=""
}

function hide(whichmenu)
{
/*	if (CanHideSubMenu)
	{
		DivSetVisible(whichmenu, false)
		backorg(whichmenu);	
	}
	*/
	
	DivSetVisible(whichmenu, false)
	return
	
  if(IE4)
    document.all[whichmenu].style.visibility = "hidden";
  else
    if(NN4)
      document.layers[whichmenu].visibility = "hidden";
    else
      if(W3C)
        document.getElementById(whichmenu).style.visibility = "hidden";
  
}

function getAnchorPosition(anchorname)
{
  var useWindow = false; // This function will return an Object with x and y properties
  var coordinates = new Object();
  var x = 0, y = 0;
  var use_gebi = false, use_css = false, use_layers = false; // Browser capability sniffing
    if(document.getElementById) { use_gebi = true; }
    else if (document.all) { use_css = true; }
    else if (document.layers) { use_layers = true; }
	  // Logic to find position
 	  if(use_gebi && document.all)
    {
      x = getPageOffsetLeft(document.all[anchorname]);
      y = getPageOffsetTop(document.all[anchorname]);
    }
    else
      if(use_gebi)
      {
        var o=document.getElementById(anchorname);
        x = getPageOffsetLeft(o);
        y = getPageOffsetTop(o);
      }
      else
        if(use_css)
        {
          x = getPageOffsetLeft(document.all[anchorname]);
          y = getPageOffsetTop(document.all[anchorname]);
        }
        else
          if(use_layers)
          {
            var found = 0;
            for (var i = 0; i < document.anchors.length; i++)
            {
              if(document.anchors[i].name == anchorname) { found = 1; break; }
            }
            if(found == 0)
            {
              coordinates.x = 0; coordinates.y = 0; return coordinates;
            }
            x = document.anchors[i].x;
            y = document.anchors[i].y;
          }
          else
          {
            coordinates.x = 0; coordinates.y = 0; return coordinates;
          }
    coordinates.x = x;
    coordinates.y = y;
    return coordinates;
}


function getPageOffsetLeft(el) // Functions for IE to get position of an object
{
  var ol = el.offsetLeft;
    //while((el = el.offsetParent) != null)
      //ol += el.offsetLeft;
    return ol;
}

function getPageOffsetTop(el)
{
  var ot = el.offsetTop;
    while((el = el.offsetParent) != null)
      ot += el.offsetTop;
    return ot;
}
