
// Copyright 2006-2007 javascript-array.com

var TimeOut         = 100;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;
var currentBtImage 	= null;
var menuOpened		= false;
var itemColorOver 	= "#A3C7E2";
var itemColorOut 	= "#cce1f0";

// Agregado por FONATUR: 08/03/2007
// Function para imagenes con roll-over
function imgchng(n, imgsrc){
	var image = document.getElementById("imgmenu"+n);
	image.src = imgsrc;
	/* SVS For debug
	var salida = document.getElementById("salida");
	salida.innerHTML += "restaura"+imgsrc+"<br>"*/
}

// Open Hidden Layer
// Modificado por FONATUR: 08/03/2007
function mopen(n)
{
    var l  = document.getElementById("lateral"+n);
    var mm = document.getElementById("mmenu"+n);
    if(l)
    {
		if(currentitem){
			currentitem.style.backgroundColor=itemColorOut;
		}
		
		// Para posicionar el submenu a la altura del padre
		if( l != currentLayer ){
			//if(l.offsetHeight && mm.offsetHeight && !l.style.marginTop){
			if(mm.offsetHeight){
				var hPadre = mm.offsetHeight;
				if(! l.style.marginTop){
					// Para Explorer
					l.style.marginTop = 0-hPadre;
					if(!l.style.marginTop){
						// Para Mozilla
						l.style.marginTop = 0-hPadre+"px"
					}					
				}
			}
		}
		
        mcancelclosetime();
        l.style.visibility='visible';
		mm.style.backgroundColor=itemColorOver;
		
		/*if( l != currentLayer){
			if(l.offsetWidth){
				var height = l.offsetHeight
				var width = l.offsetWidth
				//l.style.height = '0px';
				l.style.width = '0px';
				l.style.overflow = 'hidden';
				for(var i=0;i<width;i++){
					//setTimeout(function(){mlIncreaseHeight(l)},i*1);
					setTimeout(function(){mlIncreaseWidth(l)},i*1);
				}
				//setTimeout(function(){l.style.overflow='';l.style.height='auto'},(height-1)*1)//-1 for IE
				setTimeout(function(){l.style.overflow='';l.style.width='auto'},(width-1)*1)//-1 for IE
				
			}
		}*/

        if(currentLayer && (currentLayerNum != n)){
            currentLayer.style.visibility='hidden';		
		}
		
        currentLayer = l;
        currentitem = mm;
        currentLayerNum = n;			
    }
    else if(currentLayer)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentitem = null;
        currentLayer = null;
	}
}

function mopeniz(n)
{
    var l  = document.getElementById("lateral"+n);
    var mm = document.getElementById("mmenu"+n);
    if(l)
    {
		if(currentitem){
			currentitem.style.backgroundColor=itemColorOut;
		}
		
		// Para posicionar el submenu a la altura del padre
		if( l != currentLayer ){
			//if(l.offsetHeight && mm.offsetHeight && !l.style.marginTop){
			if(mm.offsetHeight){
				var hPadre = mm.offsetHeight;
				if(! l.style.marginTop){
					// Para Explorer
					l.style.marginTop = 0-hPadre;
					if(!l.style.marginTop){
						// Para Mozilla
						l.style.marginTop = 0-hPadre+"px"
					}					
				}
			}
		}
		
		l.style.marginLeft = -140+"px"
        mcancelclosetime();
        l.style.visibility='visible';
		mm.style.backgroundColor=itemColorOver;
		
		if( l != currentLayer){
			if(l.offsetWidth){
				var height = l.offsetHeight
				var width = l.offsetWidth
				//l.style.height = '0px';
				l.style.width = '0px';
				l.style.overflow = 'hidden';
				for(var i=0;i<width;i++){
					//setTimeout(function(){mlIncreaseHeight(l)},i*1);
					setTimeout(function(){mlIncreaseWidth(l)},i*1);
				}
				//setTimeout(function(){l.style.overflow='';l.style.height='auto'},(height-1)*1)//-1 for IE
				setTimeout(function(){l.style.overflow='';l.style.width='auto'},(width-1)*1)//-1 for IE
				
			}
		}

        if(currentLayer && (currentLayerNum != n)){
            currentLayer.style.visibility='hidden';		
		}
		
        currentLayer = l;
        currentitem = mm;
        currentLayerNum = n;			
    }
    else if(currentLayer)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentitem = null;
        currentLayer = null;
	}
}


// Turn On Close Timer
function mclosetime()
{
    closeTimer = window.setTimeout(mclose, TimeOut);
}

// Cancel Close Timer
function mcancelclosetime()
{
    if(closeTimer)
    {
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}

// Close Showed Layer
// Modificado por FONATUR: 08/03/2007
function mclose()
{				
    if(currentLayer && noClose!=1)
    { 
		//imgchng(currentLayerNum, currentBtImage)
		if(currentitem.className != "itemsel"){
			currentitem.style.backgroundColor=itemColorOut;
		}
		
		//currentitem.style.backgroundColor=itemColorOut;
		currentLayer.style.visibility='hidden';	
        currentLayerNum = 0;
        currentLayer = null;
        currentitem = null;
    }
    else
    {
        noClose = 0;
    }
    currentLayer = null;
    currentitem = null;
	
}

// Agregado por FONATUR: 08/03/2007
function mlIncreaseHeight(ob){
	var current = parseInt(ob.style.height);
	if(!isNaN(current)){
		var newh = current + 1;
		ob.style.height = newh+'px';
	}
}

// Agregado por FONATUR: 24/04/2007
function mlIncreaseWidth(ob){
	var current = parseInt(ob.style.width);
	if(!isNaN(current)){
		var neww = current + 1;
		ob.style.width = neww+'px';
	}
}

// Close Layer Then Click-out
document.onclick = mclose; 