
// ---------- Define variables ----------
var pulldownDisplaySec = 2;
var pulldownKeepAliveSec = 1;
var activePulldown = "none";
var activeTopLink = "none";

// ---------- Function to display pull-down sub nav ----------
function showPulldown(mouseOverTarget,calledFrom){
 // Run the mousePull function
 mousePull(calledFrom);
 // Define variabes
 var navItemParent, navItemParentPos, browserAdjust, activePulldownt;
 activePulldown = mouseOverTarget;
 browserAdjust = 0;
 // Set parent node of hidden nav
 navItemParent = document.getElementById('pullDown_' + activePulldown).parentNode;
 // Get absolute position of hidden nav parent
 navItemParentPos = getPos(navItemParent)
 // set the position of the hidden nav to absolute
 document.getElementById('pullDown_' + activePulldown).style.position = "absolute";
 // set vertical position of hidden nav using fixed distance
 document.getElementById('pullDown_' + activePulldown).style.top = "105px";
 // set horizontal position of hidden nav based on parent element adjusting for browser variations
 // not required if strict doc type declared
 //if (browser.isIE)
 //  {browserAdjust = 6;}
 //else
 //  {browserAdjust = 0;}
 document.getElementById('pullDown_' + activePulldown).style.left = navItemParentPos.x - browserAdjust - 8 + "px";
 // display the selected pulldown
 document.getElementById('pullDown_' + activePulldown).style.display = "block";
}

function mousePull(calledFrom){
 checkHidePulldown();
 activeTopLink = calledFrom;
 activeTopLink.className = "pullDownOnState";
}

function checkHidePulldown(){
 if(activePulldown != "none"){
  clearTimeout(topTimerId );
  hidePulldown();
 }
}

function hidePulldown(){
 mouseOff();
 document.getElementById('pullDown_' + activePulldown).style.display = "none";
 activePulldown = "none";
}

function mouseOff(){
 activeTopLink.className = "mouseOutItem";
 activeTopLink = "none";
}

function mouseOn(calledFrom){
 checkHidePulldown();
 activeTopLink = calledFrom;
 activeTopLink.className = "mouseOverItem";
}

function startTimer(){
 if(activePulldown != "none"){
  topTimerId = setTimeout('hidePulldown()', pulldownDisplaySec*1000);
 }
}

function keepAliveTop(){
 if(activePulldown != "none"){
  clearTimeout(topTimerId );
  topTimerId = setTimeout('hidePulldown()', pulldownKeepAliveSec*1000);
 }
}

 // ---------- String function to return left part of string ----------
 function Left(str, n){
   if (n <= 0)
     return "";
   else if (n > String(str).length)
     return str;
   else
     return String(str).substring(0,n);
 }

 // ---------- String function to return position of element ----------
 function getPos(inputElement) {
   var coords =  new Object();
   coords.x = 0;
   coords.y = 0;
   try {
     targetElement = inputElement;
     if(targetElement.x && targetElement.y) {
       coords.x = targetElement.x;
       coords.y = targetElement.y;
     } else {
       if(targetElement.offsetParent) {
         coords.x += targetElement.offsetLeft;
         coords.y += targetElement.offsetTop;
         while(targetElement = targetElement.offsetParent) {
           coords.x += targetElement.offsetLeft;
           coords.y += targetElement.offsetTop;
         }
       } else {
         //alert(\"Could not find any reference for coordinate positioning.\");
       }
     }
       return coords;
   } catch(error) {
     //alert(error.msg);
     return coords;
   }
 }

 // ---------- Function to determine browser ----------
 function Browser() {
   // Define variables
   var ua, s, i;
   this.isIE = false;  // Internet Explorer
   this.isOP = false;  // Opera
   this.isNS = false;  // Netscape
   this.version = null;
   ua = navigator.userAgent;
   // Test for Opera
   s = "Opera";
   if ((i = ua.indexOf(s)) >= 0) {
     this.isOP = true;
     this.version = parseFloat(ua.substr(i + s.length));
     return;}
   // Test for Netscape 6
   s = "Netscape6/";
   if ((i = ua.indexOf(s)) >= 0) {
     this.isNS = true;
     this.version = parseFloat(ua.substr(i + s.length));
     return;}
   // Treat any other "Gecko" browser as Netscape 6.1.
   s = "Gecko";
   if ((i = ua.indexOf(s)) >= 0) {
     this.isNS = true;
     this.version = 6.1;
     return;}
   // Test for IE
   s = "MSIE";
   if ((i = ua.indexOf(s))) {
     this.isIE = true;
     this.version = parseFloat(ua.substr(i + s.length));
     return;}
 }
 var browser = new Browser();
