﻿var curMenu = new Array();
curMenu[0] = 0;
curMenu[1] = 0;
var menutimeout = 0;

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do{
      curleft += obj.offsetLeft;
      if(getStyle(obj, "border-left-style") != "none"){
        curleft += parseInt(getStyle(obj, "border-left-width").replace("px", ""));
      }
      curtop += obj.offsetTop;
      if(getStyle(obj, "border-top-style") != "none"){
        curtop += parseInt(getStyle(obj, "border-top-width").replace("px", ""));
      }
    }while (obj = obj.offsetParent) 
  }
  return [curleft,curtop];
}


function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function resize(){
  var divs = document.getElementsByTagName("div");
  for(i=0; i<divs.length; i++){
    if(divs[i].className == "MENUOBJECT"){
      var tablelink = document.getElementById(divs[i].id.replace("Menu", ""));
      var position = findPos(tablelink);
      //-1 to overlap top border
      divs[i].style.top = (position[1] + tablelink.offsetHeight - 1) + "px";
      
      
      if(getStyle(tablelink, "float") == "right"){
        divs[i].style.left = (position[0] + tablelink.offsetWidth - 302) + "px";
      }else{
        divs[i].style.left = position[0]  + "px";
      }
    }
  }
}

function toggleSection(obj){
  if(obj.className.search("SHOWON") > -1){
    obj.className = obj.className.replace("SHOWON", "SHOWOFF");
    obj.src = "/images/min.gif";
    var section = document.getElementById(obj.id.replace("BUTTON", "SECTION"));
    section.className = section.className.replace("SHOWOFF", "SHOWON");
  }else{
    obj.className = obj.className.replace("SHOWOFF", "SHOWON");
    obj.src = "/images/plus.gif";
    var section = document.getElementById(obj.id.replace("BUTTON", "SECTION"));
    section.className = section.className.replace("SHOWON", "SHOWOFF");
  }
}

function start(){
  var imgs = document.getElementsByTagName("img");
  for(i=0; i<imgs.length; i++){
    if(imgs[i].className == "IMGSECTIONSHOWON" || imgs[i].className == "IMGSECTIONSHOWOFF"){
      imgs[i].onclick = function() {
        toggleSection(this);
      }
    }
  }
  var divs = document.getElementsByTagName("div");
  //var footerdiv = document.getElementById("FOOTER");
  for(i=0; i<divs.length; i++){
    //if(divs[i].id != ""){
      //footerdiv.innerHTML += divs[i].id + "<br>";
    //}
    if(divs[i].className == "MENUSECTIONCLASSHOVEROFF"){
      divs[i].onmouseover=function() {
        this.className=this.className.replace("HOVEROFF", "HOVERON");
      }
      divs[i].onmouseout=function() {
        this.className=this.className.replace("HOVERON", "HOVEROFF");
      }
    }
    if(divs[i].className == "HIGHLIGHTLINKHOVEROFF"){
      divs[i].onmouseover=function() {
        this.className=this.className.replace("HOVEROFF", "HOVERON");
      }
      divs[i].onmouseout=function() {
        this.className=this.className.replace("HOVERON", "HOVEROFF");
      }
    }
    if(divs[i].className == "MENUBUTTONHOVEROFF"){
      divs[i].onmouseover=function() {
        if(curMenu[0] == this && menutimeout != 0){
          clearTimeout(menutimeout);
          menutimeout = 0;
        }
        this.className=this.className.replace("HOVEROFF", "HOVERON");
      }
      divs[i].onmouseout=function() {
        this.className=this.className.replace("HOVERON", "HOVEROFF");
        if(curMenu[0] == this && menutimeout == 0){
          menutimeout = setTimeout("menuOff()", 1000);
        }
      }
      divs[i].onclick = function() {
        showMenu(this.id);
      }
    }
    if(divs[i].className == "MENUOBJECT"){
      var tablelink = document.getElementById(divs[i].id.replace("Menu", ""));
      var position = findPos(tablelink);
      //-1 to overlap top border
      divs[i].style.top = (position[1] + tablelink.offsetHeight - 1) + "px";
      
      
      if(getStyle(tablelink, "float") == "right"){
        divs[i].style.left = (position[0] + tablelink.offsetWidth - 302) + "px";
      }else{
        divs[i].style.left = position[0]  + "px";
      }

      
      divs[i].onmouseover=function() {
        if(menutimeout != 0){
          clearTimeout(menutimeout);
          menutimeout = 0;
        }
      }
      divs[i].onmouseout=function() {
        if(menutimeout == 0){
          menutimeout = setTimeout("menuOff()", 1000);
        }
      }
    }
  }
}

function menuOff(){
  curMenu[0].className=curMenu[0].className.replace("HOVFIX", "HOVEROFF");
  curMenu[1].style.display = "none";
  curMenu[0] = 0;
  curMenu[1] = 0;
  if(menutimeout != 0){
    clearTimeout(menutimeout);
  }
  menutimeout = 0;
}

function showMenu(idname){
  if(curMenu[0] != 0){
    menuOff();
  }
  var menulink = document.getElementById(idname);
  menulink.className = "MENUBUTTONHOVFIX"
  var menu = document.getElementById(idname + "Menu");
  menu.style.display="block";
  curMenu[0] = menulink;
  curMenu[1] = menu;
}


