// JavaScript Document
var menuList;
var infoPadList;
var absoluteDivs;
var oldMenuObj;

// Script for animating Menu Items
function AnimateMenu(caller, ind){
    this.name = caller.id;
	this.counter = 0;
	this.index_= ind;
	this.slideInterval = 100;
	this.t1;
	this.ANIMATING_OPEN = 1;
	this.ANIMATING_CLOSE = 2
	this.OPEN_COMPLETE = 3;
	this.CLOSE_COMPLETE = 4;
	this.submenuState = this.CLOSE_COMPLETE;

    this.mainContainer = caller.parentNode;

	this.menuViewClip = this.mainContainer.getElementsByTagName("DIV").item(1);

    AnimateMenu.prototype.open = function(){
            if (this.submenuState == this.ANIMATING_CLOSE)
            {
                clearInterval(this.t1);
                this.submenuState = this.CLOSE_COMPLETE;
            }
            if (this.submenuState == this.CLOSE_COMPLETE)
            {
                this.submenuState = this.ANIMATING_OPEN;
			    this.t1 = setInterval("openSubmenu("+ this.index_ +");", this.slideInterval);
            }
    }

    AnimateMenu.prototype.close = function(){
            if (this.submenuState == this.ANIMATING_OPEN)
            {
                clearInterval(this.t1);
                this.submenuState = this.OPEN_COMPLETE;
            }
            if (this.submenuState == this.OPEN_COMPLETE)
            {
                this.submenuState = this.ANIMATING_CLOSE;
			    this.t1 = setInterval("closeSubmenu("+ this.index_ +");", this.slideInterval);
            }
    }
}

function openSubmenu(indx){
	menuList[indx].menuViewClip.style.visibility = "visible";
	menuList[indx].submenuState = menuList[indx].OPEN_COMPLETE;
	clearInterval(menuList[indx].t1);
}

function closeSubmenu(indx){
	menuList[indx].menuViewClip.style.visibility = "hidden";
	menuList[indx].submenuState = menuList[indx].CLOSE_COMPLETE;
	clearInterval(menuList[indx].t1);
}

function initiate(callerObjId){
	if(oldMenuObj){
		if(oldMenuObj.submenuState != oldMenuObj.CLOSE_COMPLETE){
			oldMenuObj.close();
		}
	}
    for(var i = 0; i < menuList.length; ++i){
        if(menuList[i].name == callerObjId){
           oldMenuObj = menuList[i];
           menuList[i].open();
           break;
        }
    }
}
function closeThis(callerObjId){
    for(var i = 0; i < menuList.length; ++i){
        if(menuList[i].name == callerObjId){
			menuList[i].close();
            break;
        }
    }
}

//Functions Used by above script 
//Ignoring for child elementsd on mouseover
function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
