//Menu functions

var menu          = "";
var submenu       = "";
var delay         = 0;
var myTimerID;
var y_axis_offset = 0; 
var x_axis_offset = 0; 

browserName = navigator.appName;          
browserVer = parseInt(navigator.appVersion);
var userBrowser   = navigator.userAgent; 
userBrowser       = userBrowser.toLowerCase();
isExplorer         = userBrowser.indexOf("msie") > -1;
isNetscape        = userBrowser.indexOf("netscape") > -1; 
isFirefrox        = userBrowser.indexOf("firefox") > -1; 
isSafari          = userBrowser.indexOf("safari") > -1; 
isMac             = userBrowser.indexOf("mac") > -1; 


function showMenu (x, y, imgname){
  var x,y;
  y -= y_axis_offset;
  x -= x_axis_offset;
  if(myTimerID)
    clearTimeout(myTimerID);

  if(document.layers) {
    eval("x = document.dm_"+menu+".left +" + x);
    eval("y = document.dm_"+menu+".top +" + y + "+ dm_"+imgname+"Y");
  } else {
    x = moveXbySlicePos (x, imgname);
    y = moveYbySlicePos (y, imgname);
  }

  if(document.all) {  
    eval("dm_"+imgname+".style.left ="+x);
    eval("dm_"+imgname+".style.top =" + y);
    eval("dm_"+imgname+".style.visibility = 'visible'");
  } else if(document.layers) { 
    eval("document.dm_"+imgname+".left ="+x);
    eval("document.dm_"+imgname+".top ="+y);    
    eval("document.dm_"+imgname+".visibility = 'show'");
  } else if(document.getElementById) {
    document.getElementById('dm_'+imgname).style.visibility = 'visible';
    document.getElementById('dm_'+imgname).style.left = x;
    document.getElementById('dm_'+imgname).style.top = y;

  }
}

function FIND(item) {
  if( window.mmIsOpera ) return(document.getElementById(item));
  if(document.all) return(document.all[item]);
  if(document.getElementById) return(document.getElementById(item));
  return(false);
}

function moveXbySlicePos (x, imgname) { 
  var img = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
  if(!document.layers) {
    var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
    var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
    var par = img;
    var lastOffset = 0;
    while(par){
      if(par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
      if((par.offsetLeft != lastOffset) && par.offsetLeft) x += parseInt(par.offsetLeft);
      if(par.offsetLeft != 0) lastOffset = par.offsetLeft;
      par = macIE45 ? par.parentElement : par.offsetParent;
    }
  } else if(img.x) {
     x += img.x;
  }
  return x;
}

function getExplorerVersion() {
  var ieVers = parseFloat(navigator.appVersion);
  if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
  var tempVers = navigator.appVersion;
  var i = tempVers.indexOf( 'MSIE ' );
  if(i >= 0) {
    tempVers = tempVers.substring( i+5 );
    ieVers = parseFloat( tempVers ); 
  }
  return ieVers;
}


function moveYbySlicePos (y, imgname) {
  var img = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
  if(!document.layers) {
    var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
    var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
    var par = img;
    var lastOffset = 0;
    while(par){
      if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
      if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
      if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
      par = macIE45 ? par.parentElement : par.offsetParent;
    }    
  } else if(img.y >= 0) y += img.y;
  return y;
}

//Hide the menus
function hideMenu(){
 if(isMac && isFirefrox){ 
  var myVar ="";
  myVar += "document.getElementById('dm_about_us').style.visibility = 'hidden';";
  myVar += "document.getElementById('dm_products').style.visibility = 'hidden'";
  myTimerID=setTimeout(myVar,delay);
 }
 else{
  document.getElementById('dm_about_us').style.visibility = 'hidden';
  document.getElementById('dm_products').style.visibility = 'hidden';
  startTimeout();
 }
}

//Hide the menu after a delay
function startTimeout(){
  myTimerID=setTimeout('hideMenu();',delay);
}



//Change home buttons
var bt = "";//Rename the button

if(primaryActiveState == "home"){
 bt = "h_";
 }

//Navigation active states
function active_bt(){

  if(primaryActiveState == 'home'){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_off.gif';
   document.getElementById('products').src = root+'images/bt_products_off.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_off.gif';
   document.getElementById('links').src = root+'images/bt_links_off.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
  else if(primaryActiveState == 'about_us'){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_on.gif';
   document.getElementById('products').src = root+'images/bt_products_off.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_off.gif';
   document.getElementById('links').src = root+'images/bt_links_off.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
  else if(primaryActiveState == 'products'){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_off.gif';
   document.getElementById('products').src = root+'images/bt_products_on.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_off.gif';
   document.getElementById('links').src = root+'images/bt_links_off.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
  else if(primaryActiveState == 'news'){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_off.gif';
   document.getElementById('products').src = root+'images/bt_products_off.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_on.gif';
   document.getElementById('links').src = root+'images/bt_links_off.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
  else if(primaryActiveState == 'links'){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_off.gif';
   document.getElementById('products').src = root+'images/bt_products_off.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_off.gif';
   document.getElementById('links').src = root+'images/bt_links_on.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
  else if(primaryActiveState == 'contact_us'){
  document.getElementById('about_us').src = root+'images'+bt+'/bt_about_us_off.gif';
  document.getElementById('products').src = root+'images/bt_products_off.gif';
  document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
  document.getElementById('news').src = root+'images/bt_news_off.gif';
  document.getElementById('links').src = root+'images/bt_links_off.gif';
  document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_on.gif';
  }
  else if(primaryActiveState == ' '){
   document.getElementById('about_us').src = root+'images/'+bt+'bt_about_us_off.gif';
   document.getElementById('products').src = root+'images/bt_products_off.gif';
   document.getElementById('solutions').src = root+'images/bt_solutions_off.gif';
   document.getElementById('news').src = root+'images/bt_news_off.gif';
   document.getElementById('links').src = root+'images/bt_links_off.gif';
   document.getElementById('contact_us').src = root+'images/'+bt+'bt_contact_us_off.gif';
  }
 }

