function OpcMenu (){
	this.TIMER_SLIDE = null;
	this.OBJ_SLIDE;
	this.OBJ_VIEW;
	this.PIX_SLIDE = 10; //this is the amount of slide/DELAY_SLIDE
	this.NEW_PIX_VAL;
	this.DELAY_SLIDE = 30; //this is the time between each call to slide
	this.DIV_HEIGHT = 22; //value irrelevant
	this.SUB_MENU_NUM =0;
	this.RE_INIT_OBJ = null;
	this.bMenu = document.getElementById("curMenu");
	this.MainDiv;
	this.SubDiv;
	this.abierto=0;
}

var menu = new Array (4) 
menu[0] = new OpcMenu();
menu[1] = new OpcMenu();
menu[2] = new OpcMenu();
menu[3] = new OpcMenu();

//DD added code
document.write('<div id="tempcontainer" class="mainDiv" style="visibility: hidden; position: absolute"></div>')

function Init(objDiv,num)
{

    var opcMenu = menu[num];
    if (opcMenu.TIMER_SLIDE == null)
    {
        opcMenu.SUB_MENU_NUM = 0;
        opcMenu.MainDiv = objDiv.parentNode;
        opcMenu.SubDiv =  opcMenu.MainDiv.getElementsByTagName("DIV").item(0);
   
        //opcMenu.SubDiv.onclick = SetSlide;

        opcMenu.OBJ_SLIDE = opcMenu.MainDiv.getElementsByTagName("DIV").item(1)
        opcMenu.OBJ_VIEW = opcMenu.OBJ_SLIDE.getElementsByTagName("DIV").item(0);

	document.getElementById("tempcontainer").innerHTML=opcMenu.MainDiv.getElementsByTagName("DIV").item(2).innerHTML //DD added code
	opcMenu.DIV_HEIGHT=document.getElementById("tempcontainer").offsetHeight //DD added code
        
        for (i=0;i<opcMenu.OBJ_VIEW.childNodes.length;i++)
        {
            if (opcMenu.OBJ_VIEW.childNodes.item(i).tagName == "SPAN")
            {
                opcMenu.SUB_MENU_NUM ++;
                opcMenu.OBJ_VIEW.childNodes.item(i).onmouseover= ChangeStyle;
                opcMenu.OBJ_VIEW.childNodes.item(i).onmouseout= ChangeStyle;
            }
        }   
        
              opcMenu.NEW_PIX_VAL = parseInt(opcMenu.MainDiv.getAttribute("state")); 
    }
	menu[num]=opcMenu;
}

function SetSlide(num)
{    
	CloseOthers(num);
     var opcMenu = menu[num];
     opcMenu.abierto=1; 
     
     if (opcMenu.TIMER_SLIDE) clearInterval(opcMenu.TIMER_SLIDE) //DD added code
      if (opcMenu.TIMER_SLIDE == null && this.parentNode == opcMenu.MainDiv){
            opcMenu.TIMER_SLIDE = setInterval('RunSlide('+num+')', opcMenu.DELAY_SLIDE);
       }
      else
      {
          opcMenu.RE_INIT_OBJ = this;
          setTimeout('ReInit('+num+')', 200);
      }
      menu[num]=opcMenu;
      
}


function ReInit(num)
{

    var opcMenu = menu[num];
    opcMenu.TIMER_SLIDE = setInterval('RunSlide('+num+')', opcMenu.DELAY_SLIDE);
    opcMenu.RE_INIT_OBJ = null;
    menu[num]=opcMenu;
}

function RunSlide(num)
{
    var opcMenu = menu[num];
    if (opcMenu.OBJ_VIEW.getAttribute("state") == 0)
    {
	opcMenu.NEW_PIX_VAL += opcMenu.PIX_SLIDE;
        opcMenu.OBJ_SLIDE.style.height = opcMenu.NEW_PIX_VAL;

        if (opcMenu.NEW_PIX_VAL >= opcMenu.DIV_HEIGHT) //DD modified code
        {
            clearInterval(opcMenu.TIMER_SLIDE);
            opcMenu.TIMER_SLIDE = null;
            opcMenu.OBJ_VIEW.style.display = 'inline';
            opcMenu.OBJ_VIEW.setAttribute("state","1")
            opcMenu.MainDiv.setAttribute("state",opcMenu.NEW_PIX_VAL);
        }
    } else
    {
    	opcMenu.abierto=0;
        opcMenu.OBJ_VIEW.style.display = 'none';
        opcMenu.NEW_PIX_VAL -= opcMenu.PIX_SLIDE;
        if(opcMenu.NEW_PIX_VAL > 0)opcMenu.OBJ_SLIDE.style.height = opcMenu.NEW_PIX_VAL;
        if (opcMenu.NEW_PIX_VAL <= 0)
        {
            opcMenu.NEW_PIX_VAL = 0;
            opcMenu.OBJ_SLIDE.style.height = opcMenu.NEW_PIX_VAL
            clearInterval(opcMenu.TIMER_SLIDE);
            opcMenu.TIMER_SLIDE = null;
            opcMenu.OBJ_VIEW.setAttribute("state","0")
            opcMenu.MainDiv.setAttribute("state",opcMenu.NEW_PIX_VAL);
        }
    }
    menu[num]=opcMenu;
}

function ChangeStyle()
{
    if (this.className == this.getAttribute("classOut"))
        this.className = this.getAttribute("classOver");
    else
        this.className = this.getAttribute("classOut");
}
function CloseOthers(num){
	for(i=0;i<4;i++){
		var other=i;
		if(other!=num){
			if((other==1 && num==2) || (other==1 && num==3)){
				//los menus internos no cierran el superior.
			}else if((other==2 && num==1) || (other==3 && num==1)){
				//y al cerrar el superior no se cierran los inf(mermorizacion)
			}
			else{
				//alert('otros' + other + 'mio' + num);
				var opcMenu = menu[other];
				//si estado es 1 es que esta abierto.
				if (opcMenu.abierto==1){
					
					var capa = document.getElementById('capa'+other);
					Init(capa,other);	
					CloseParticular(other);
					opcMenu.abierto=0;
					menu[other]=opcMenu;
					
				}
				
			}
		}
	}
}
function CloseParticular(num)
{
	    
     var opcMenu = menu[num];
     if (opcMenu.TIMER_SLIDE) clearInterval(opcMenu.TIMER_SLIDE) //DD added code
      if (opcMenu.TIMER_SLIDE == null && this.parentNode == opcMenu.MainDiv){
            opcMenu.TIMER_SLIDE = setInterval('RunSlide('+num+')', opcMenu.DELAY_SLIDE);
       }
      else
      {
          opcMenu.RE_INIT_OBJ = this;
          setTimeout('ReInit('+num+')', 200);
      }
      menu[num]=opcMenu;
}

