function despliegaModuloCabecera(idWrapperModulo) {
	
	if(idWrapperModulo == 'pos-1') {
		$j("#pos1").animate({
			opacity: 0.0
		}, 500 );
	}
	
	if(idWrapperModulo == 'pos1') {
		$j("#pos-1").animate({
			opacity: 0.0
		}, 500 );
	}
	
	$j("#" + idWrapperModulo).animate({
		opacity: 1.0
	}, 500 );
	
	$j("#wrapperCabecera").animate({
		top: "-20px"
	}, 1000 );
	$j("#pos2").animate({
		borderTopColor: "red"
	}, 1000 );
	$j("#pos0").animate({
		borderTopColor: "red"
	}, 1000 );
}

function despliegaBuscadorCabecera() {
	$j("#wrapperCabecera").animate({
		top: "0px"
	}, 1000 );
	$j("#pos2").animate({
		borderTopColor: "red"
	}, 1000 );
	$j("#pos0").animate({
		borderTopColor: "red"
	}, 1000 );
}

function repliegaBuscadorCabecera() {
	if(document.getElementById('wrapperCabecera').style.top == '-20px')	 {
		$j("#wrapperCabecera").animate({
			top: "-65px"
		}, 1000 );
		$j("#pos2").animate({
			borderTopColor: "black"
		}, 1000 );
		$j("#pos0").animate({
			borderTopColor: "black"
		}, 1000 );
	}
}

var punteroSobreTitularProds = false;

function disparaDespliegueMenuProds(event) {
	punteroSobreTitularProds = true;
	setTimeout(function(){return despliegaMenuProds(event)},200) 
}

function paraDespliegueMenuProds(event) {
	punteroSobreTitularProds = false;
}

function despliegaMenuProds(event) {
    
	if (punteroSobreTitularProds == false) {
		repliegaMenuProds();
		return;
	}
	
	// Para ocultar el menu de productos hemos puesto debajo de #pos4 otro div invisible y un poco mas ancho y detectamos los eventos de entrada del puntero en este div.
	// Las sigientes tres lineas sirven para parar la propagacion de este evento mouseover a este div detector cuando el usuario pasa el puntero sobre los enlaces del menu.
	// De lo contrario, el menu de productos se ocultaria en cuanto el usuario pasase el puntero por encima de cualquiera de los enlaces de los productos.
	$j("#pos4").mouseover(function(event){
	  event.stopPropagation();
	}); 
	
	var alturaPag = getDocHeight();
	
	$j("#pos4").animate({
		height: alturaPag - 350 + 155 + "px",
		opacity: 1.0,
		paddingTop: "350px",
		lineHeight: "25px"
	}, 1000 );
	
	$j("#wrapperPos4").animate({
		height: alturaPag + "px"
	}, 1000 );
	
	$j("#elemProductos").animate({
		color: "black"
	}, 1000 );
}

function repliegaMenuProds() {
	$j("#pos4").animate({
		height: "0px",
		opacity: 0.0,
		paddingTop: "0px",
		lineHeight: "1px"
	}, 1000 );
	
	$j("#wrapperPos4").animate({
		height: "0px"
	}, 1000 );
	
	$j("#elemProductos").animate({
		color: "red"
	}, 1000 );
}

function ensanchaMenuProds(anchoAdicional) {
	$j("#pos4").stop();
	$j("#pos4").animate({
		paddingRight: anchoAdicional + "px"
	}, 200 );
}

function estrechaMenuProds() {
	$j("#pos4").stop();
	$j("#pos4").animate({
		paddingRight: "0px"
	}, 200 );
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function muestraPantallaProducto(idPantalla, enlace) {
//	alert(findPosX(document.getElementById(idPantalla)) );
		
	if(findPosX(document.getElementById(idPantalla)) == findPosX(document.getElementById('wrapperCabecera')))	
		return;
	
	var margen = findPosX(document.getElementById(idPantalla)) -  findPosX(document.getElementById('wrapperPantallasProducto'));
	if(margen > 0)
		margen = margen * (-1);
	
		
	$j("#wrapperPantallasProducto").animate({
		marginLeft: margen + "px"
	}, 1000 );
	
	$j(".enlacesSupProdAct").each(function() {
		$j(this).removeClass('enlacesSupProdAct');
	});
	
	enlace.className = 'enlacesSupProdAct';
	enlace.setAttribute("class", 'enlacesSupProdAct'); //For Most Browsers
	enlace.setAttribute("className", 'enlacesSupProdAct'); //For IE; harmless to other browsers.

/*	$j("#wrapperEnlaces1Prod a").each(function() {
		$j(this).css("color", "#FFF");
	});
	
	$j("#wrapperEnlaces2Prod a").each(function() {
		$j(this).css("color", "#666666");
	});
	
	enlace.style.color = "#F00";
*/
}

function colocaMenuProds() {
	var ancho = document.body.clientWidth;
	var margen = -30;
	if(ancho > 980) {
		margen = (ancho - 980) / 2;
		margen = margen + 100 - 130;
	}
	var p = document.getElementById('wrapperGlobalMenuProds');
	p.style.marginLeft = margen + 'px';
	p.style.display = 'block';
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
				if(!obj.offsetParent)
					break;
				  obj = obj.offsetParent;
				}
				else if(obj.x)
					curleft += obj.x;
	return curleft;
}
