//-----------------------------------------------

var firefox  = !document.layers && !document.all;
var bFirefox3=false;
if (firefox) {
	if(navigator.userAgent.match("rv:1\.9")) 
		bFirefox3 = true;
	else
		if (navigator.oscpu) bFirefox3 = true;
}

//-----------------------------------------------

var tiempoFade = 600;
var tiempoFadeGrande = 1500;

//-----------------------------------------------


function Aparece (id) {
    var currentOpac = 100; 
	var millisec = tiempoFade;
    if(document.getElementById(id).style.opacity < 100) { 
   	    currentOpac = document.getElementById(id).style.opacity * 100; 
    } 
	if (currentOpac == 0) {
		currentOpac = 1;
		opacity(id, currentOpac, 100, millisec);
	}
}

function ApareceDIV (id) {
    var currentOpac = 100; 
	var millisec = tiempoFadeGrande;
    if(document.getElementById(id).style.opacity < 100) { 
   	    currentOpac = document.getElementById(id).style.opacity * 100; 
    } 
	if (currentOpac == 0) {
		currentOpac = 1;
		opacity(id, currentOpac, 100, millisec);
	}
}

function Desaparece (id, evento) {
	//esto se hace asi porque sino, cuando el raton pasa sobre un elemento interior al DIV (ie. <A> ó <UL>) lanza un evento mouseOver y no funciona bien
	var bDesaparecer=false;
	if (firefox) {
		if (evento.target.tagName == "DIV") {
			bDesaparecer=true;
		}
	}
	else {
		if (event.srcElement.tagName == "DIV") {
			bDesaparecer=true;
		}
	}
	if (bDesaparecer) {
    	var currentOpac = 100; 
		var millisec = tiempoFade;
    	if(document.getElementById(id).style.opacity < 100) { 
			currentOpac = document.getElementById(id).style.opacity * 100; 
	    }
		if (currentOpac > 0) {
			opacity(id, currentOpac, 0, millisec);
		}
	}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
	if (opacity==0) {
		if (id=='wrapper-contenido2') {
			document.getElementById(id).style.display="none";
		}
	}
}

function DesapareceDIV (id) {
   	var currentOpac = 100; 
	var millisec = tiempoFadeGrande;
   	if(document.getElementById(id).style.opacity < 100) { 
		currentOpac = document.getElementById(id).style.opacity * 100; 
    }
	if (currentOpac > 0) {
		opacity(id, currentOpac, 0, millisec);
	}
}

// --------------------------------------------------------------------------------------------------

function Despliega (id) {
	if (pliegaInicio) clearTimeout(pliegaInicio);
	var object = document.getElementById(id).style; 
    var currentTop = parseInt(object.top);
	var millisec = 500;
	desplegar(id, currentTop, 94, millisec);
}

function Pliega (id, evento) {
	//esto se hace asi porque sino, cuando el raton pasa sobre un elemento interior al DIV (ie. <A> ó <UL>) 
	//lanza un evento mouseOver y no funciona bien
	var bDesaparecer=false;
	if (firefox) {
		if (evento.target.tagName == "DIV") {
			if (bFirefox3) { 
				//firefox 3
				if (evento.target.id != "submenu" && evento.relatedTarget.id != "submenu") {
					bDesaparecer=true;
				}
			}
			else {
				//chrome y otros
				if (evento.target.id != "submenu" && evento.toElement.id != "submenu") {
					bDesaparecer=true;
				}
			}
		}
	}
	else {
		if (event.srcElement.tagName == "DIV") {
			if (event.srcElement.id != "submenu" && event.toElement.id != "submenu") {
				bDesaparecer=true;
			}
		}
	}
	if (bDesaparecer) {
		PliegaDIV(id);
	}
}

function PliegaDIV (id) {
	var object = document.getElementById(id).style; 
    var currentTop = parseInt(object.top);
	var millisec = 500;
	desplegar(id, currentTop, 148, millisec);
}

function desplegar(id, topStart, topEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0;
	var i;

    //determine la direccion de movimiento, si start y end son iguales no ocurre nada
    if(topStart > topEnd) { 
        for(i = topStart; i >= topEnd; i--) { 
            setTimeout("changeTop(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
			if (bFirefox3 && timer > 40) timer=40;
        } 
    } else if(topStart < topEnd) { 
        for(i = topStart; i <= topEnd; i++) { 
            setTimeout("changeTop(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function changeTop(x, id) { 
    var object = document.getElementById(id).style; 
	if (bFirefox3) 
	    object.top = x+"px";
	else
	    object.posTop = x;
}
