/* crea una ventana con la url que se le pasa */
var contador = 0;
var ventanas = [];
function crearVentanaPreview(url,titulo){ 
	/*contador ++;
	ventanas.push(window.open(url,'titulo '+contador,"width=200, height=200, scrollbar=yes,resizable=yes"));
	mostrarTodasVentanas();
	*/
	openInNewTab(url)
	
}
function openInNewTab(URL) {
	var temporalForm = document.createElement('form');
	with (temporalForm) {
		setAttribute('method', 'GET');
		setAttribute('action', URL);
		setAttribute('target', '_blank');
	}

	var paramsString = URL.substring(URL.indexOf('?') + 1, URL.length);
	var paramsArray = paramsString.split('&');

	for (var i = 0; i < paramsArray.length; ++i) {
		var elementIndex = paramsArray[i].indexOf('=');
		var elementName = paramsArray[i].substring(0, elementIndex);
		var elementValue = paramsArray[i].substring(elementIndex + 1, paramsArray[i].length);

		var temporalElement = document.createElement('input');
		with(temporalElement) {
			setAttribute('type', 'hidden');
			setAttribute('name', elementName);
			setAttribute('value', elementValue);
		}
		temporalForm.appendChild(temporalElement);
	}
	document.body.appendChild(temporalForm);
	temporalForm.submit();
	document.body.removeChild(temporalForm);
}


function mostrarTodasVentanas(){
	for(var i=0;i<nuevaVentana.length;i++)
		nuevaVentana[i].focus();
}

/* cambia el background color en el hover o en el out */
function changeItemMenu(o){
	if(!o.activo)
		if(!o.hover){
			o.hover = true;
			o.style.backgroundColor = "black";
			o.style.color = "white";
		}else{
			o.hover = false;
			o.style.backgroundColor = "transparent";
			o.style.color = "#1d1d1e";
		}
}

function cambiarBackgroundItem(o,y){
	if(!o.activo){
		var ultimo = -18 + y;  
		if(!o.over){
			o.over = true;
			o.style.backgroundPosition = "0px " + ultimo +"px";
		}else{
			o.over = false;
			o.style.backgroundPosition = "0px " +y+"px";
		}
	}
}
function verEmpresaSlogan(o){
	activaMenu(o);
	/* oculta el auto */
	document.getElementById("imagenFate").style.visibility = "hidden";
	/* activa el slogan */
	document.getElementById("empresaFate").style.visibility = "visible";
}
function activaMenu(o){
	o.activo = true;
	o.style.backgroundColor = "black";
	o.style.color = "white";
}
function desactivaMenu(o){
	o.hover = false;
	o.activo = false;
	o.style.backgroundColor = "transparent";
	o.style.color = "black";
}
function resetarFate(){
	var o = document.getElementById("empresaItemFate");
	desactivaMenu(o);
	/* desactivar mensaje */
	document.getElementById("empresaFate").style.visibility = "hidden";
	/* activa camion 4*4 */
	document.getElementById("imagenFate").style.visibility = "visible";
}

/* cambiar menu */
function cambiarMenu(pagina){
	window.location = pagina;
}
/* cambia imagen del audio a color y background color a naranaja */
function cambiarAudiOver(o,opcion){
	if(!entraSlide)
		if(opcion){
			//o.style.backgroundColor = "#fb9d00";
			document.getElementById("imagenAudi").src = imagenAudi.src;
		}else{
			//o.style.backgroundColor = "white";
			document.getElementById("imagenAudi").src = imagenAudiPreview.src;
		}
}

/* cambia imagen del audio a color y background color a naranaja */
function cambiarFateOver(o,opcion){
	if(!entraSlide)
		if(opcion){
			//o.style.backgroundColor = "#d5d5d5";
			document.getElementById("imagenFate").src = imagenFate.src;
		}else{
			//o.style.backgroundColor = "white";
			document.getElementById("imagenFate").src = imagenFatePreview.src;
		}
}
/* carga el preview de las imagenes */
var imagenAudiPreview = document.createElement("IMG");
var imagenAudi = document.createElement("IMG");
imagenAudi.src = "img/audi.png";
imagenAudiPreview.src = "img/audiclara.png";

var imagenFatePreview = document.createElement("IMG");
var imagenFate = document.createElement("IMG");
imagenFate.src = "img/4x4Inicio.png";
imagenFatePreview.src = "img/fateclara.png";

/* carga los sub items del menu marcas continental */
var itemBarum = document.createElement("IMG");
var itemContinental = document.createElement("IMG");
var itemGeneral = document.createElement("IMG");
var itemBarumWhite = document.createElement("IMG");
var itemContinentalWhite = document.createElement("IMG");
var itemGeneralWhite = document.createElement("IMG");

itemBarum.src = "img/portadaBarumn.png";
itemContinental.src = "img/portadaContinegro.png";
itemGeneral.src = "img/portadaGeneral.png";
itemBarumWhite.src = "img/portadaBarumnblanco.png";
itemContinentalWhite.src = "img/portadaConti.png";
itemGeneralWhite.src = "img/portadaGeneralblanco.png";

function changeImageSubMenu(o,tipo){
	if(!tipo){
		/* barum*/
		if(!o.hover){
			o.hover = true;
			o.src = itemBarumWhite.src
		}else{
			o.hover = false;
			o.src = itemBarum.src
		}
	}else if(tipo==1){
		/* continental */
		if(!o.hover){
			o.hover = true;
			o.src = itemContinentalWhite.src
		}else{
			o.hover = false;
			o.src = itemContinental.src
		}
	}else if(tipo==2){
		/* general */
		if(!o.hover){
			o.hover = true;
			o.src = itemGeneralWhite.src
		}else{
			o.hover = false;
			o.src = itemGeneral.src
		}
	}
}
/* si hay click no activa el hover change */
var changeOverActive = false;
var entraSlide = false;
var noDocument = true;
var contador = 11;
var unidad = 512 / 10;
/* realiza animacion de entrada y salida */
function inicializarSlide(eC,continental){
	if(!changeOverActive){
		entraSlide = eC;
		changeOverActive = true;
		if(continental && (noDocument|| !eC)){
			slideDivContinental();
			switchBackground();
			switchZindex(true);
		}else if(!continental && (noDocument|| !eC)){
			switchZindex(false);
			switchBackground(true);
			slideDivFate();
		}
	}
}
/* hace switch entre zIndex */
function switchZindex(continental){
		var c = document.getElementById("contenedorContinental");
		var f = document.getElementById("contenedorFate");
	if(continental){
		c.style.zIndex = 2;
		f.style.zIndex = 1;
	}else{
		c.style.zIndex = 1;
		f.style.zIndex = 2;
	}
}
function switchBackground(fate){
	if(!fate){
		var o = document.getElementById("contenedorContinental");
		var color = "#fb9d00";
	}
	else{
		var o = document.getElementById("contenedorFate");
		//var color = "#d5d5d5";
		var color = "#bcbcc5";
	}
	if(noDocument){
		o.style.backgroundColor = color;
	}else{
		/* vuelve desde continental oculta productos */
		slideVisibleContinental();
		offMenuContinental();
		/* oculta la empresa */
		ocultarEmpresa();
		o.style.backgroundColor = "white";
	}
}
function slideDivContinental(){	
	var continental = document.getElementById("contenedorContinental");
	if(contador){
		//var fate = document.getElementById("contenedorFate");
		contador --;
		var cantidad = parseInt(unidad * (10-contador));
		if(entraSlide)
			cantidad = -512 + (cantidad ) + "px";
		else
			cantidad =  (cantidad * -1) + "px";
		continental.style.left = cantidad;
		setTimeout(slideDivContinental,10);		
	}else{
		contador = 11;
		if(entraSlide){
			continental.style.cursor = "default";
			noDocument = false;
		}else{
			continental.style.cursor = "pointer";
			noDocument = true;
		}
		changeOverActive = false;
	}
}
function slideDivFate(){	
	var fate = document.getElementById("contenedorFate");
	if(contador){
		//var fate = document.getElementById("contenedorFate");
		contador --;
		var cantidad = parseInt(unidad * (10-contador));
		if(entraSlide)
			cantidad = 512 - (cantidad ) + "px";
		else
			cantidad =  cantidad  + "px";
		fate.style.left = cantidad;
		setTimeout(slideDivFate,10);		
	}else{
		contador = 11;
		if(entraSlide){
			fate.style.cursor = "default";
			noDocument = false;
		}else{
			fate.style.cursor = "pointer";
			noDocument = true;
		}
		changeOverActive = false;
	}
}

/* realiza animacion de entrada y salida */

function switchBackgroundFate(){
	var o = document.getElementById("contenedorFate");
	if(noDocument){
		o.style.backgroundColor = "#1d1d1e";
	}else{
		o.style.backgroundColor = "white";
	}
}
function slideDivContinental(){	
	var continental = document.getElementById("contenedorContinental");
	if(contador){
		//var fate = document.getElementById("contenedorFate");
		contador --;
		var cantidad = parseInt(unidad * (10-contador));
		if(entraSlide)
			cantidad = -512 + (cantidad ) + "px";
		else
			cantidad =  (cantidad * -1) + "px";
		continental.style.left = cantidad;
		setTimeout(slideDivContinental,30);		
	}else{
		contador = 11;
		if(entraSlide){
			continental.style.cursor = "default";
			noDocument = false;
		}else{
			continental.style.cursor = "pointer";
			noDocument = true;
		}
		changeOverActive = false;
	}
}
function onProducto(o,empresa){
	if(!o.activo){
		o.activo = true;
		offMenuContinental();
		if(!empresa){
			/* oculta emrpesa siempre */
			ocultarEmpresa();
			slideHiddenContinental();
			document.getElementById("subProductosMenu").style.display = "inline";
		}else{
			ocultarAudi();
			/* muestra empresa */
			verEmpresa();
			/* oculta menu sub continental */
			var subMenu = document.getElementById("subMenuContinental");
			subMenu.style.visibility = "hidden";
		}
		o.style.backgroundColor = "black";
	}
}
function offMenuContinental(){
	var pC = document.getElementById("productoContinental");
	pC.activo = false;
	pC.style.backgroundColor = "transparent";
	pC.style.color = "black";
	pC.hover = false;
	document.getElementById("subProductosMenu").style.display = "none";
	var e = document.getElementById("empresaMenu");
	e.activo = false;
	e.style.backgroundColor = "transparent";
	e.style.color = "black";
	e.hover = false;
}
/* desaparece auto continental */
function slideHiddenContinental(){	
	var continental = document.getElementById("imagenAudi");
	continental.style.visibility = "hidden";
	// muestra el menu 
	var subMenu = document.getElementById("subMenuContinental");
	subMenu.style.visibility = "visible";
}
/* oculta auto */
function ocultarAudi(){
	var continental = document.getElementById("imagenAudi");
	continental.style.visibility = "hidden";
	// muestra el menu 
}
/* oculta emrpesa */
function ocultarEmpresa(){
	document.getElementById("empresaContinental").style.visibility = "hidden";
}
/* ver emrpesa */
function verEmpresa(){
	document.getElementById("empresaContinental").style.visibility = "visible";
}
function slideVisibleContinental(){
	var continental = document.getElementById("imagenAudi");
	continental.style.visibility = "visible";
	// oculta el menu 
	var subMenu = document.getElementById("subMenuContinental");
	subMenu.style.visibility = "hidden";
}


