/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  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 NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {	
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
        }
		this.showMenu();
    }
	
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
       // menu.style.left = this.offsetLeft + 153 + "px";
       // menu.style.top = this.offsetTop - 1 + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

function mouseOut(event) {
	var el;

	// If there is no active button, exit.

	if (currentMenu == null)
		return;

	// Find the element the mouse is moving to.
	
	if (browser.isIE) 
		el = window.event.toElement;
	else if (event.relatedTarget != null) 
		el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

	// If the element is not part of a menu, reset the active button.

	if (getContainerWith(el, "DIV", "subMenu") == null) {
		currentMenu.style.visibility = "hidden";
		currentMenu = null;
	}
}


function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName && hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  
  for (i = 0; i < list.length; i++) {
    if (list[i] == name)
      return true;
  }
  return false;
}

	
				function rotate(objName,num,ecllipse) {
     				var banTime= new Date();
     				var ss=banTime.getSeconds();
					var interval = ecllipse;
					var temp = 0;
					var index = 0;
					var obj;
					
					temp=(Math.floor(ss/interval)) % num;
					
  					//if ((ss>=0)&&(ss<=19)) {
					for(i=1;i<=num;i++) {
						if (MM_findObj(objName+i)!= null){
							obj = MM_findObj(objName+i);
							//alert("i="+i+" "+"temp="+temp);
        					if(i==temp+1) {
								eval("obj.style.display = 'block'");
							}
							else {
       							eval("obj.style.display = 'NONE'");
							}
						}
					}
					
					setTimeout("rotate(\""+objName+"\","+num+","+ecllipse+")",interval * 1000);
				}
		


function initialize() {
				initializeMenu("submenu1", "globalmenu1");
				initializeMenu("submenu2", "globalmenu2");
				initializeMenu("submenu3", "globalmenu3");
				initializeMenu("submenu4", "globalmenu4");
				initializeMenu("submenu5", "globalmenu5");
				initializeMenu("submenu6", "globalmenu6");

			}



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