var undefined;
var browser;
var version;
var OS;

var hide  = true;
var Yoffset = 1;	// y-axis offset for sub-menu.
var Xoffset = 0;	// x-axis offset for sub-menu.
var abort = false;	// Auto-shut off abort switch.
var TimerSet;		// Timer switch.
var Delay = 500; 	// Auto-shut off time delay in milliseconds.

var layers = new Array();

	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring;
	
	if (checkIt('konqueror'))
		{
	    browser = "Konqueror";
        OS = "Linux";
		}
	else if (checkIt('safari')) browser = "Safari";
	else if (checkIt('omniweb')) browser = "OmniWeb";
	else if (checkIt('opera')) browser = "Opera";
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab";
	else if (checkIt('msie')) browser = "Internet Explorer";
	else if (!checkIt('compatible'))
		{
        browser = "Netscape Navigator";
        version = detect.charAt(8);
		}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
		{
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac";
        else if (checkIt('win')) OS = "Windows";
        else OS = "an unknown operating system";
		}

if (OS=="Mac" && browser=="Internet Explorer")
	{
	Xoffset = Xoffset + 9;
	Yoffset = Yoffset + 12;
	}
// This function resets the location of the specified layer.

function init()
	{
	for (j=0;j<layers.length;j++)
		{
		thisObj = layers[j];
		thisObj = thisObj.substring(0,thisObj.indexOf("Menu"));
		}
	}

function setLyr(obj,lyr, XX, YY)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if (lyr == 'testP') newY -= 50;
	var x = new getObj(lyr);
	if (YY=="" || YY==undefined) YY=0;
	if (XX=="" || XX==undefined) XX=0;
	Y = Yoffset + YY;
	X = Xoffset + XX;
	x.style.top = newY + Y +'px';
	x.style.left = newX + X + 'px';
}


// This function returns the x-coordinate of a specified page element.

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;
}

//This functiono returns the y-coordinate of a specified page element.

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	//window.status = printstring;
	return curtop;
}

// This layer finds the sub-menu layer to be moved.

function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

// This function sets the timer for hiding the sub-menu.

function setTimer()
	{
	abort = false;
	if (TimerSet) TimerSet = clearTimeout(TimerSet);	
	if (!TimerSet) TimerSet = setTimeout('AutoOff()',Delay);
	}
	
// This function hides the sub-menu.
	
function AutoOff(obj)
	{
	if (!abort) HideAll();
	TimerSet = false;
	}
	
function HideAll(current_menu)
	{
	myParent = FindParent(current_menu);
	for (i=1;i<menu.length;i++) 
		{
		if (!InArray(i,myParent)) MM_showHideLayers('menu' + i + 'Menu','','hide');
		}
	}

function FindParent(thisMenu)
	{
	pos = thisMenu;
	parentMenu = new Array();
	b=0;
	if (thisMenu==undefined || thisMenu=="") return null;
	while (menu[pos][13]!=null) {
		pos = menu[pos][13];
		parentMenu[b] = pos;
		b = b + 1;
		}
	return parentMenu;
	}

function InArray(needle,haystack)
	{
	if (haystack!=null)
		{
		for (i=0;i<haystack.length;i++)
			{
			if (needle==haystack[i]) return true;
			}
		}
	return false;
	}

// The following 2 functions are Dreamweaver functions for finding objects and showing/hiding layers.

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

	
function checkIt(string)
{
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}

function HREF(myURL,target)
	{
        if (target=="_blank") return;
	if (target==undefined || target=="") target = "_self";
	window.open(myURL,target);
	}

function Rollover(obj, new_style) {
	obj.className = new_style;
}

function replaceQuotes(obj)
	{
	newObj = obj.replace(/'/g,"\\'");
	//alert(newObj.replace(/'/g,"\\'"));
	return newObj;
	}


function writeMenu()
	{
	for (i=0;i<menu.length;i++)
    {
		myMenu = myMenu + '\n<div class="nav"';
		myMenu = myMenu + ' id="menu' + i + 'Menu"';
		myMenu = myMenu + ' style=\"position: ' + menu[i][4] + "; z-index: " + i + ";"; // write this layer's styles
		myMenu = myMenu + 'visibility: ' + menu[i][6] + ";";
		if (menu[i][4]=="absolute") { // write position of absolute menu
			if (menu[i][0]!="") { myMenu = myMenu + 'top: ' + menu[i][0] + "px;"; }
			if (menu[i][1]!="") { myMenu = myMenu + 'left: ' + menu[i][1] + "px;"; }
			}
		myMenu = myMenu + '\"';
		myMenu = myMenu +'>\n<table cellspacing=0 cellpadding=0 border=0';
		if (menu[i][9]==0 && menu[i][2]!=0) myMenu = myMenu +' width=' +  menu[i][2];
		if (i==0) myMenu = myMenu + '>\n<tr>';
		else  myMenu = myMenu + '>\n<tr>';
		if (menu[i][9]==1) { // This is a horizontal menu
			links = menu[i].length-14;
			for (j=0;j<links;j=j+5)
				{
				abortThis = "true";
				if ((menu[i][15+j]=="" || menu[i][15+j]==undefined) && i==0) abortThis = "false";
				Over = " onMouseover=\"abort=" + abortThis + ";"; // build cell MouseOver
				Hide = "HideAll(" + i + ");";
				ImgClass = "menuSpacer";
				if (i>0) {
					Hide = "";
					Over = Over + "Rollover(this,'SubNavigationOn');";
					ImgClass = "menuSpacerSub";
					}
				if (menu[i][15+j]!="" && menu[i][15+j]!=undefined) Over = Over + Hide + " ;setLyr(MM_findObj('img" + i+ menu[i][15+j] + "'),'menu" + menu[i][15+j] + "Menu');MM_showHideLayers('menu" + menu[i][15+j] + "Menu','','show');";
				if (abortThis=="false") Over = Over + "HideAll(" + i + ");";
				Over = Over + "\"";
				
				Out = " onMouseOut=\""; // build cell MouseOut
				if (i>0) Out = Out + "Rollover(this,'SubNavigation');";
				Out = Out + "setTimer();\"";
				
				myMenu = myMenu + '\n<td valign="bottom" class="' + ImgClass + '" width="1"><img src="images/spacer.gif" alt="" border="0" width="1" height="1" name=\"img' + i + menu[i][15+j] + '\"></td>';
				myMenu = myMenu + '\n<td';
				if (i==0) myMenu = myMenu + ' class="nav"';
				else myMenu = myMenu + ' class="Subnavigation"'
				myMenu = myMenu + Over + Out;
				if (menu[i][7]!="") myMenu = myMenu + ' align="' + menu[i][7] +'"'; // align menu elements
				if (menu[i][8]!="") myMenu = myMenu + ' nowrap="nowrap"'; // set cell wrapping
				if (menu[i][9]==1 && menu[i][2]!=0) myMenu = myMenu + ' width=' + menu[i][2]; // set cell width
				myMenu = myMenu + " onClick=\"HREF('" + replaceQuotes(menu[i][16+j]) +"','" + menu[i][18+j] + "');\" id=Link";
				
				abortThis = "true";
				if ((menu[i][15+j]=="" || menu[i][15+j]==undefined) && i==0) abortThis = "false";
				Over = " onMouseover=\"abort=" + abortThis + ";"; // build link MouseOver
				Hide = "HideAll(" + i + ");";
				if (i>0) Hide = "";
				if (menu[i][15+j]!="" && menu[i][15+j]!=undefined) Over = Over + Hide + " ;setLyr(MM_findObj('img" + i + menu[i][15+j] + "'),'menu" + menu[i][15+j] + "Menu');MM_showHideLayers('menu" + menu[i][15+j] + "Menu','','show');";
				if (abortThis=="false") Over = Over + "HideAll(" + i + ");";
				Over = Over + "\"";
				
				Out = " onMouseOut=\""; // build link MouseOut
				Out = Out + "setTimer();\"";
				
				thisLink = "subnav";
				if (i==0) thisLink = "nav";
				myMenu = myMenu + '><a href=' + menu[i][16+j] + ' target=' + menu[i][18+j] + ' class="' + thisLink + '" ';
				myMenu = myMenu + Over + Out;
				myMenu = myMenu + '>' + menu[i][14+j] + '</a></td>';
				}
			myMenu = myMenu + '\n<td valign=bottom class=menuSpacer><img src=images/spacer.gif border=0 width=1 height=1 name=\"img' + links + menu[i][15+j] + '\"></td>';
			}
		else { // This is a vertical menu
			links = menu[i].length-14;
			for (j=0;j<links;j=j+5)
            {
				abortThis = "true";
				if ((menu[i][15+j]=="" || menu[i][15+j]==undefined) && i==0) abortThis = "false";
				Over = " onMouseover=\"abort=" + abortThis + ";"; // build cell MouseOver
				Hide = "HideAll(" + i + ");";
				ImgClass = "menuSpacer";
				if (i>0) {
					Hide = "";
					Over = Over + "Rollover(this,'SubNavigationOn');";
					ImgClass = "menuSpacerSub";
					}
				if (menu[i][15+j]!="" && menu[i][15+j]!=undefined) Over = Over + Hide + " ;setLyr(MM_findObj('img" + i + menu[i][15+j] + "'),'menu" + menu[i][15+j] + "Menu');MM_showHideLayers('menu" + menu[i][15+j] + "Menu','','show');";
				if (abortThis=="false") Over = Over + "HideAll(" + i + ");";
				Over = Over + "\"";
				
				Out = " onMouseOut=\""; // build cell MouseOut
				if (i>0) Out = Out + "Rollover(this,'SubNavigation');";
				Out = Out + "setTimer();\"";
				
				myMenu = myMenu + '<td align=right class=' + ImgClass + ' height=1><img src=images/spacer.gif border=0 width=1 height=1 name=\"img' + i + menu[i][15+j] + '\"></td></tr><tr class=subnav>';
				myMenu = myMenu + '<td';
				if (i==0) myMenu = myMenu + ' class=' + menu[i][5];
				else myMenu = myMenu + ' class="Subnavigation"'
				myMenu = myMenu + Over + Out;
				if (menu[i][7]!="") myMenu = myMenu + ' align=' + menu[i][7]; // align menu elements
				if (menu[i][8]!="") myMenu = myMenu + ' nowrap'; // set cell wrapping
				if (menu[i][9]==1 && menu[i][2]!=0) myMenu = myMenu + ' width=' + menu[i][2]; // set cell width
				myMenu = myMenu + " onClick=\"HREF('" + replaceQuotes(menu[i][16+j]) +"','" + menu[i][18+j] + "');\" id=Link";
				
				abortThis = "true";
				if ((menu[i][15+j]=="" || menu[i][15+j]==undefined) && i==0) abortThis = "false";
				Over = " onMouseover=\"abort=" + abortThis + ";"; // build link MouseOver
				Hide = "HideAll(" + i + ");";
				if (i>0) Hide = "";
				if (menu[i][15+j]!="" && menu[i][15+j]!=undefined) Over = Over + " setLyr(MM_findObj('img" + i + menu[i][15+j] + "'),'menu" + menu[i][15+j] + "Menu');MM_showHideLayers('menu" + menu[i][15+j] + "Menu','','show');";
				if (abortThis=="false") Over = Over + "HideAll(" + i + ");";
				Over = Over + "\"";
				
				Out = " onMouseOut=\""; // build link MouseOut
				Out = Out + "setTimer();\"";
				
				thisLink = "subnav";
				if (i==0) thisLink = "nav";
				myMenu = myMenu + '><a href="' + menu[i][16+j] + '" target="' + menu[i][18+j] + '" class="' + thisLink + '"';
				myMenu = myMenu + Over + Out;
				myMenu = myMenu + '>' + menu[i][14+j] + '</a></td></tr><tr>';
			}
        }
		myMenu = myMenu + '</tr></table></div>';
    }
		//document.HTML.check.value=myMenu;
		return(myMenu);
}

