var ZINDEX = 20;
var IE = (document.all) ? 1 : 0;
var LYRS = (document.layers) ? 1 : 0;
var MASTER = -1;
var PARENT = 0;
var CHILD = 1;
var TYPE_MENU = 0;
var TYPE_NAVMENU = 1;
var SPACER = "/images/spacer.gif";
var RELATIVEX = true;
var RELATIVE_BASE = 0;
var RELATIVE_DELTA = 610;//619
var RELATIVE_MIN = 183;
var ENABLE_INDEX_TOP_MENU = true;
var ENABLE_MENUS = true;
var MENUS_INITIALIZED = false;

// will overwrite any existing var of same name
if( window ){
  window.xmenus = new Array();
  window.xcurrentMenu = "";
}
// Courtesy of Macromedia
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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
} // End Macromedia

//===================
//The remainder of this file is Copyright 2003 CONNX Solutions
function popimage( imagesrc, winwidth, winheight ){
  var look, button;
  
  winwidth += 20;
  winheight += 65;
  look ='width=' + winwidth + ', height=' + winheight;
  button = "<center><input type='button' value='Close Window' onClick='window.close();'></center>";
  popwin = window.open( "", "", look );
  popwin.document.open();
  popwin.document.write('<title>Image Window</title><body>' );
  popwin.document.write('<img src="' + imagesrc + '"><br><br>' );
  popwin.document.write( button );
  popwin.document.write('</body>' );
  popwin.document.close();
  
  return false
}

function NavMenu(){
  var args, param, x;

  this.name = "NavMenu";

  this.expandOnClick = false;
  this.left = 10;
  this.top = 10;

  this.itemWidth = 220;
  this.itemHeight = 20;
  this.itemBGColor = "#AAAAAA";
  this.itemHighLColor = "#888888";
  this.itemBorder = 0;
  this.itemBorderColor = "#000000";
  this.itemIndent = 0;
  this.itemSpacing = 0;
  //this.itemAlign = "left";

  this.fntSize = 10;
  this.fntBold = false;
  this.fntFamily = "Veranda,Arial,Helvetica";
  this.fntColor = "#000000";
  this.fntHighLColor = "#FFFFFF";

  this.closedMenuIcon = "images/menuClosed.gif";
  this.openMenuIcon = "images/menuOpen.gif";
  this.menuIconWidth = 11;
  this.menuIconHeight = 11;

  args = NavMenu.arguments;
  for( x = 0; x < args.length; x++ ){
    param = args[ x ].split( "=" );
    if( ! param[ 1 ] ){ continue; }
    this[ param[ 0 ] ] = (param[ 1 ] == "true") ? true :
	  ( (param[ 1 ] == "false") ? false : param[ 1 ] );
  }

  this.type = "NavMenu";
  this.objId = TYPE_NAVMENU;
  this.init = false;
  this.visible = false;
  this.maxItems = 0;
  this.activeIndex = 0;
  this.firstIndex = -1;
  this.menuList = new Array();

  this.addMenu = addMenu;
  this.showMenu = showNavMenu;
  this.hideMenu = hideMenu;
  this.actionOver = actionOver;
  this.actionOut = actionOut;
  this.actionClick = actionClick;

  this.xmid = window.xmenus.length;
  window.xmenus[ this.xmid ] = this;
}

function Menu(){
  var args, param, x;

  this.name = "Menu";

  this.top = 10;
  this.left = 10;

  this.fntSize = 10;
  this.fntBold = false;
  this.fntFamily = "Veranda,Arial,Helvetica";
  this.fntColor = "#000000";
  this.fntHighLColor = "#FFFFFF";

  this.itemWidth = 180;
  this.itemHeight = 20;
  this.itemBGColor = "#DDDDDD";
  this.itemHighLColor = "#777777";
  this.itemBorder = 0;
  this.itemBorderColor = "#000000";
  this.itemIndent = 0;
  this.itemSpacing = 0;
  
  this.hideTimeout = 50;

  args = Menu.arguments;
  for( x = 0; x < args.length; x++ ){
    param = args[ x ].split( "=" );
    if( ! param[ 1 ] ){ continue; }
    this[ param[ 0 ] ] = (param[ 1 ] == "true") ? true :
	  ( (param[ 1 ] == "false") ? false : param[ 1 ] );
  }

  this.type = "Menu";
  this.objId = TYPE_MENU;
  this.menuList = new Array();
  this.timerID = "";
  this.showTimerID = "";
  this.active = false;
  this.visible = false;
  this.init = false;
  this.subInit = false;
  this.hasParent = false;

  this.addItem = addItem;
  this.showMenu = showMenu;
  this.hideMenu = hideMenu;
  this.closeMenu = closeMenu;
  this.menuTimeout = menuTimeout;
  this.actionOver = actionOver;
  this.actionOut = actionOut;
  this.actionClick = actionClick;

  this.xmid = window.xmenus.length;
  window.xmenus[ this.xmid ] = this;
}

function setRelativeBase(){
  var width = (window.innerWidth) ? window.innerWidth : ( (document.body) ? document.body.clientWidth + 20 : 0 );

  RELATIVE_BASE = width - RELATIVE_DELTA;
  RELATIVE_BASE = (RELATIVE_BASE < RELATIVE_MIN) ? RELATIVE_MIN : RELATIVE_BASE;
}

function addMenu( menu, title, action ){
  var height, len = this.menuList.length;

  if( this.init ){ return; }
  this.menuList[ len ] = new Object();

  this.menuList[ len ].title = title;
  this.menuList[ len ].action = action;
  this.menuList[ len ].menu = menu;
  if( menu == null ){ return; }
  if( this.firstIndex < 0 ){ this.firstIndex = len; }
  menu.hasParent = true;
  menu.hideOnMouseOut = false;
  if( this.maxItems < menu.menuList.length ){
    this.maxItems = menu.menuList.length;
  }
}

function addItem( title, action ){
  var len = this.menuList.length;
  
  if( this.init ){ return; }
  this.menuList[ len ] = new Object();
  this.menuList[ len ].title = title;
  this.menuList[ len ].action = action;
}

function writeMenus(){
  var menu, menuID, firstItem, contentPad, fntProps, tempA, tempB, top, left, x, z, subContent, content = "";
  
  for( menuID in window.xmenus ){
    menu = window.xmenus[ menuID ];
    if( menu.hasParent ){ continue; }
    if( menu.init ){ continue; }
	content = "";
	// this.objId = TYPE_NAVMENU
    if( menu.objId == TYPE_NAVMENU ){

	  firstItem = menu.menuList[ menu.firstIndex ].menu;
	  if( menu.itemWidth < firstItem.itemWidth ){
	    menu.itemWidth = firstItem.itemWidth;
	  }
	  top = Number( menu.top ) + (( Number( menu.activeIndex ) + 1 ) * Number( menu.itemHeight ) );
	  left = Number( menu.left ) + ( Number( menu.itemWidth ) - 
	    Number( firstItem.itemWidth ) );

	  for( x = 0; x < menu.maxItems; x++ ){
	    content += getDIV( menu.name + "_c_F_" + x, left, top, 
		  Number(firstItem.itemWidth) + (Number(firstItem.itemBorder) * 2), 
		  Number(firstItem.itemHeight) + (Number(firstItem.itemBorder) * 2),
		  1, menu.xmid, x, CHILD, firstItem.itemBorderColor,
		  getDIV( menu.name + "_c_B_" + x, 
		  firstItem.itemBorder, firstItem.itemBorder, 
		  firstItem.itemWidth, 
		  firstItem.itemHeight,
		  1, menu.xmid, x, CHILD, firstItem.itemHighLColor, "&nbsp;", "inherit", false ) +
		  getDIV( menu.name + "_c_A_" + x, 
		  firstItem.itemBorder, firstItem.itemBorder, 
		  firstItem.itemWidth, 
		  firstItem.itemHeight,
		  2, menu.xmid, x, CHILD, firstItem.itemBGColor, "&nbsp;", "inherit", false ), 
		  ((LYRS) ? "hide" : "hidden"), true );
	    top += firstItem.itemHeight;
      }
    }

	contentPad = "<table width='" + menu.itemWidth + "' height='" + menu.itemHeight;
	contentPad += "'><tr><td valign='center'>";
	if( menu.itemIndent ){
      contentPad += "<img height='1' align='left' width='" + menu.itemIndent;
	  contentPad += "' border='0' src='" + SPACER + "'>";
	}
	fntProps += "font-family:" + menu.fntFamily;
    fntProps += "; font-size:" + menu.fntSize;
	boldOpen = (menu.fntBold) ? "<b>" : "";
    boldClosed = (menu.fntBold) ? "</b>" : "";

	subContent = "";
	top = 0;
    for( x = 0; x < menu.menuList.length; x++ ){
	  
      subContent += getDIV( menu.name + "_F_" + x, ((menu.objId == TYPE_NAVMENU) ? menu.left : 0 ), top, 
		  Number(menu.itemWidth) + (Number(menu.itemBorder) * 2), 
		  Number(menu.itemHeight) + (Number(menu.itemBorder) * 2),
		  1, menu.xmid, x, PARENT, menu.itemBorderColor,
	      getDIV( menu.name + "_B_" + x, menu.itemBorder, menu.itemBorder, 
		  menu.itemWidth, menu.itemHeight,
		  1, menu.xmid, x, PARENT, menu.itemHighLColor,
		  contentPad + "<a href='#' style='text-decoration:none;cursor:hand;'><span style='" + fntProps + "; color:" + menu.fntHighLColor + ";'>" + boldOpen +
		  menu.menuList[ x ].title + boldClosed + "</span></a></td></tr></table>", "inherit", false ) +
	      getDIV( menu.name + "_A_" + x, menu.itemBorder, menu.itemBorder,
		  menu.itemWidth, menu.itemHeight,
		  2, menu.xmid, x, PARENT, menu.itemBGColor,
		  contentPad + "<a href='#' style='text-decoration:none;cursor:hand;'><span style='" + fntProps + "; color:" + menu.fntColor + ";'>" + boldOpen +
		  menu.menuList[ x ].title + boldClosed + "</span></a></td></tr></table>", "inherit", false ), 
		  ((menu.objId == TYPE_NAVMENU) ? ((LYRS) ? "hide" : "hidden" ) : "inherit" ), true );
      top += Number( menu.itemHeight ) + 
              Number( menu.itemBorder ) + Number( menu.itemSpacing );
    }
	top = Number( menu.top );
	
	if( menu.objId == TYPE_NAVMENU ){
	  content += subContent;
	} else {
	  content += getDIV( menu.name + "_M_", menu.left, top, 
		  Number(menu.itemWidth) + (Number(menu.itemBorder) * 2), 
		  ( Number(menu.itemHeight) + (Number(menu.itemBorder) * 2) ) * menu.menuList.length,
		  1, menu.xmid, -1, MASTER, "transparent", subContent, 
		  ((LYRS) ? "hide" : "hidden" ), false );
	}
	
    menu.init = true;
    document.write( content );
  }
}

function initializeMenus(){
  var menu;
  
  for( menuID in window.xmenus ){
    menu = window.xmenus[ menuID ];
	
    if( menu.objId == TYPE_NAVMENU ){ continue; }
	
	menu.masterdiv = findElem( menu.name + "_M_" );
  }
  MENUS_INITIALIZED = true;
}

function getDIV( divName, left, top, width, height,
    zindex, menuID, index, child, color, content, visibility, action ){
    
  divtxt = "<div id='" + divName + "' style='position:absolute; ";
  //divtxt += "cursor:url(" + CURSOR + "); left:" + left + "px; top:" + top;
  divtxt += "left:" + left + "px; top:" + top;
  divtxt += "px; width:" + width + "px; height:" + height + "px; ";
  divtxt += "background-color: " + color;
  divtxt += "; visibility:" + visibility + " ; ";
  divtxt += "z-index:" + zindex + ";' ";
  if( action ){
    divtxt += "onMouseOver='actionOver(" + menuID + "," + index;
    divtxt += "," + child + ")' onMouseOut='actionOut(" + menuID + "," + index;
    divtxt += "," + child + ")' onClick='actionClick(" + menuID + "," + index;
    divtxt += "," + child + ")'";
  }
  divtxt += ">" + content + "</div>";

  return divtxt;
}

function menuTimeout(){

  if( this.active ){ return; }
  this.active = false;
  clearInterval( this.timerID );
  this.timerID = "";
  this.hideMenu();
}

function actionOver( menuID, index, child ){
  var color, fntColor, divA, divB, span, menu;
  
  menu = window.xmenus[ menuID ];
  if( ! menu.visible ){ return; }
  if( menu.showTimerID ){
    clearInterval( menu.showTimerID );
    menu.showTimerID = "";
  }
  if( menu.timerID ){
    menu.active = true;
  }
  if( child ){
    divA = findElem( menu.name + "_c_A_" + index ); 
	divB = findElem( menu.name + "_c_B_" + index );
  } else {
    if( menu.objId == TYPE_NAVMENU && index == menu.activeIndex ){ return; }
    divA = findElem( menu.name + "_A_" + index );
	divB = findElem( menu.name + "_B_" + index );
  }
  	
  if( LYRS ){

  } else {
	divA.style.visibility = "hidden";
	divB.style.visibility = "inherit";
  }
}

function actionOut( menuID, index, child ){
  var div, menu;
  
  menu = window.xmenus[ menuID ];
  if( ! menu.visible ){ return; }
  if( menu.timerID ){
    menu.active = false;
  } else if( menu.objId == TYPE_MENU ){
    menu.timerID = setInterval( "window.xmenus[" + menu.xmid + "].menuTimeout()", Number( menu.hideTimeout ) );
  }
  if( child ){
    div = findElem( menu.name + "_c_A_" + index );  
  } else {
    if( menu.objId == TYPE_NAVMENU && index == menu.activeIndex ){ return; }
    div = findElem( menu.name + "_A_" + index );
  }
  	
  if( LYRS ){

  } else {
    div.style.visibility = "inherit";
  }
}

function actionClick( menuID, index, child ){
  var menu;
  
  menu = window.xmenus[ menuID ];
  if( ! menu.visible ){ return; }
  if( menu.timerID ){
    clearInterval( menu.timerID );
	menu.timerID = "";
	menu.active = false;
  }
  if( child ){
    eval( menu.menuList[ menu.activeIndex ].menu.menuList[ index ].action );
  } else {
    eval( menu.menuList[ index ].action );
  }
  if( menu.objId == TYPE_MENU ){
    menu.hideMenu();
  } else if( menu.objId == TYPE_NAVMENU && menu.expandOnClick && menu.activeIndex != index ){
    menu.showMenu( index );
  }
}

function showNavMenu( index ){
  var x, z, n, div, level, contentPad, fntProps, boldOpen, boldClosed, top = Number( this.top ), delta = 0;
    
  this.activeIndex = index;
  
  for( x = 0; x < this.menuList.length; x++ ){
    boldOpen = (this.fntBold) ? "<b>" : "";
    boldClosed = (this.fntBold) ? "</b>" : "";
	
	div = findElem( this.name + "_F_" + x );
	if( LYRS ){
	
	} else {
	  div.style.top = top + delta;
	  div.style.visibility = "visible";
	}
    for( n = 0; n < 2; n++ ){
      level = (n) ? "B" : "A";
	  div = findElem( this.name + "_" + level + "_" + x );
	  contentPad = "<table width='" + this.itemWidth + "' height='" + this.itemHeight;
	  contentPad += "'><td valign='center'><img align='left' ";
	  contentPad += "width='" + this.menuIconWidth + "' height='" + this.menuIconHeight;
	  fntProps = "font-family:" + this.fntFamily;
      fntProps += "; font-size:" + this.fntSize;
	  if( x == index ){
	    fntProps += "; color:" + this.fntHighLColor;
	    contentPad += "' src='" + this.openMenuIcon + "' border='0'>";
	  } else {
	  	if( n ){
	      fntProps += "; color:" + this.fntHighLColor;
		} else {
		  fntProps += "; color:" + this.fntColor;
		}
	    contentPad += "' src='" + this.closedMenuIcon + "' border='0'>";
	  }
	  if( this.itemIndent ){
	    contentPad += "<img height='1' align='left' width='" + this.itemIndent;
	    contentPad += "' border='0' src='" + SPACER + "'>";
	  } 
	  if( LYRS ){

      } else {
	    div.innerHTML = contentPad + "<a href='#' style='text-decoration:none;cursor:hand;'><span style='" + fntProps + "'>" + boldOpen +
		  this.menuList[ x ].title + boldClosed + "</span></a></td></tr></table>";
        if( x == index ){
	      div.style.backgroundColor = this.itemHighLColor;
        } else {
		  if( n ){
		    div.style.backgroundColor = this.itemHighLColor;
		  } else {
            div.style.backgroundColor = this.itemBGColor;
		  }
        }
		div.style.visibility = "inherit";
      }
	}
	delta += Number( this.itemHeight ) + Number( this.itemBorder ) + Number( this.itemSpacing );
	if( x == index ){
	  contentPad = "<table width='" + this.menuList[ this.firstIndex ].menu.itemWidth;
	  contentPad += "' height='" + this.menuList[ this.firstIndex ].menu.itemHeight;
	  contentPad += "'><tr><td valign='center'>";
	  if( this.menuList[ this.firstIndex ].menu.itemIndent ){
	    contentPad += "<img height='1' width='" + this.menuList[ this.firstIndex ].menu.itemIndent;
	    contentPad += "' border='0' src='" + SPACER + "'>";
	  }
	  boldOpen = (this.menuList[ this.firstIndex ].menu.fntBold) ? "<b>" : "";
      boldClosed = (this.menuList[ this.firstIndex ].menu.fntBold) ? "</b>" : "";
	  for( z = 0; z < this.menuList[ x ].menu.menuList.length; z++ ){
	    div = findElem( this.name + "_c_F_" + z );
	    if( LYRS ){
	
	    } else {
	      div.style.top = top + delta;
	      div.style.visibility = "visible";
	    }
	    for( n = 0; n < 2; n++ ){
		  fntProps = "font-family:" + this.menuList[ this.firstIndex ].menu.fntFamily;
          fntProps += "; font-size:" + this.menuList[ this.firstIndex ].menu.fntSize;
          level = (n) ? "B" : "A";
	      div = findElem( this.name + "_c_" + level + "_" + z );
		  if( n ){
		    fntProps += "; color:" + this.menuList[ this.firstIndex ].menu.fntHighLColor;
		  } else {
		    fntProps += "; color:" + this.menuList[ this.firstIndex ].menu.fntColor;
		  }
	      if( LYRS ){

          } else {
            div.innerHTML = contentPad + "<a href='#' style='text-decoration:none;cursor:hand;'><span style='" + fntProps + "'>" + boldOpen +
		      this.menuList[ x ].menu.menuList[ z ].title + boldClosed + "</span></a></td></tr></table>";
			if( n ){
			  div.style.backgroundColor = this.menuList[ this.firstIndex ].menu.itemHighLColor;
		    } else {
			  div.style.backgroundColor = this.menuList[ this.firstIndex ].menu.itemBGColor;
		    }
			div.style.visibility = "inherit";
          }
		}
	    delta += Number( this.menuList[ this.firstIndex ].menu.itemHeight ) + 
		  Number( this.menuList[ this.firstIndex ].menu.itemBorder ) + 
		  Number( this.menuList[ this.firstIndex ].menu.itemSpacing );
	  }
	  for( z = this.menuList[ x ].menu.menuList.length; z < this.maxItems; z++ ){
	    for( n = 0; n < 2; n++ ){
          level = (n) ? "B" : "A";
	      div = findElem( this.name + "_c_" + level + "_" + z );
	      if( LYRS ){
		  
          } else {
            div.style.visibility = "hidden";
          }
		}
	  }
	}
  }
  this.visible = true;
}  
 
function findElem( elem ){

  if( IE ){
    return document.all[ elem ];
  } else if( LYRS ){
    return document.layers[ elem ];
  }
  return document.getElementById( elem );
}

function showMenu(){
  
  if( ! MENUS_INITIALIZED ){
    initializeMenus();
  }
  if( window.xcurrentMenu != this.xmid && window.xmenus[ window.xcurrentMenu ] ){
    window.xmenus[ window.xcurrentMenu ].hideMenu();
  }
  if( this.timerID ){ clearInterval( this.timerID ); }
  if( this.showTimerID ){ clearInterval( this.showTimerID ); }
  if( RELATIVEX ){
    setRelativeBase();
  }
  
  if( LYRS ){

  } else {
    this.masterdiv.style.left = Number( this.left ) + RELATIVE_BASE;
    this.masterdiv.style.visibility = "visible";
  }
  this.visible = true;
  this.subInit = true;
  window.xcurrentMenu = this.xmid;
}

function closeMenu(){
  if( this.showTimerID ){ clearInterval( this.showTimerID ); }
  this.showTimerID = setInterval( "window.xmenus[" + this.xmid + "].menuTimeout()", Number( this.hideTimeout ) );
}

function hideMenu(){
  
  if( this.type == "NavMenu" ){ return; }

  if( LYRS ){
	  
  } else {
    this.masterdiv.style.visibility = "hidden";
  }
  this.visible = false;
  //window.xcurrentMenu = "";
}