var altoAmpliado = 0;
var altoTotal = 389;
var URL = "http://www.elcoto.com/"
var ventanaMusica = "";
var previo = "";
var fotos = "";
var cambio = "";
var alt = "";
var carpetaCabecera = "";
var numFoto = 0;
var interTime = 2000;
var puedeAmpliar = true;
var letra = "";


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if (navigator.appName.indexOf("Netscape") != -1) {var isNN = true;}
else{var isNN = false;}

if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1) {var isIE = true;}
else{var isIE = false;}

function pngFix(imagen){
	if ((version >= 5.5) && (document.body.filters)) 
	{
	  var img = imagen;
	  var imgName = img.src.toUpperCase()
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
	}
}

if(typeof(document.getElementsByClassName) != 'function') {
  	document.getElementsByClassName = function (cn) {
		var rx = new RegExp("\\b" + cn + "\\b"), allT = document.getElementsByTagName("*"), allCN = [], i = 0, a;
			while (a = allT[i++]) {
			  if (a.className && a.className.indexOf(cn) + 1) {
				if(a.className===cn){ allCN[allCN.length] = a; continue;   }
				rx.test(a.className) ? (allCN[allCN.length] = a) : 0;
			  }
			}
		return allCN;
	}
}



function setContenido(objeto,texto) {
	document.getElementById(objeto).innerHTML = texto
}
	
		
function seeMe(obj){
	obj.style.visibility="visible";
	pngFix(obj);

}


function appear(content, value) {
    var property = content.filters ? 'filter' : 'opacity';
    if (typeof value == 'undefined'){
		if(content.style[property]== 'undefined' || content.style[property]== ''){
			value = 0;
		}else{
			valor = parseInt(content.style[property]);  
			if (isNaN(valor)) {  
			   //no es entero 0  
				value = parseInt(content.style[property].slice(14,content.style[property].length-1));
			}else{  
			   //es un valor entero  
				value = content.style[property]*100;
			}  
		}
	}
    if (value == 100) {
        content.style[property] = 1;
    } else {
        content.style[property] = content.filters ? 'alpha(opacity=' + value + ')' : value/100;
        setTimeout(function () {appear(content, value + 20)}, 50);
    }
}

function disappear(content, value) {
    var property = content.filters ? 'filter' : 'opacity';
    if (typeof value == 'undefined'){
		if(content.style[property]== 'undefined' || content.style[property]== ''){
			value = 100;
		}else{
			valor = parseInt(content.style[property]);  
			if (isNaN(valor)) {  
			   //no es entero 0  
				value = parseInt(content.style[property].slice(14,content.style[property].length-1));
			}else{  
			   //es un valor entero  
				value = content.style[property]*100;
			}  
		}
	}
    content.style[property] = content.filters ? 'alpha(opacity=' + value + ')' : value/100;
    if (value > 0) {
	    if (content.direccion == 1) {
		    setTimeout(function () {disappear(content, value - 20)}, 50);
		}
    }
}



function clickSec(destino){
	if(letra!=17){
		document.location = destino;
	}else{
		window.open(destino)
		letra = "";
	}
}


function overSec(num){
	var obj = document.getElementById("li"+num);
	obj.style.background = "url("+URL+"img/fondoBotonVino.gif)"
	obj = document.getElementById("sp"+num);
	obj.style.background = "#e5e5e5"
}

function outSec(num){
	var obj = document.getElementById("li"+num);
	obj.style.background = "#fafafa"
	obj = document.getElementById("sp"+num);
	obj.style.background = "#fafafa"
}

function overSecB(num,letra){
	if(CONSTANTES['idioma']!="ES"){idioma = "en"}else{idioma = "es"}
	var obj = document.getElementById("imgMB"+num);
	var archivoImg = "";
	numObjeto = obj.id.slice(5,6)
	archivoImg = letra+numObjeto+"b.jpg";
	obj.src = URL+"img/menuB/"+idioma+"/"+archivoImg;
}

function outSecB(num,letra){
	if(CONSTANTES['idioma']!="ES"){idioma = "en"}else{idioma = "es"}
	var obj = document.getElementById("imgMB"+num);
	var archivoImg = "";
	numObjeto = obj.id.slice(5,6)
	archivoImg = letra+numObjeto+".jpg";
	obj.src = URL+"img/menuB/"+idioma+"/"+archivoImg;
}

function overFcb(){
	var obj = document.getElementById("fcbImg");
	obj.src = URL+"img/btFbkB.jpg";
}

function outFcb(){
	var obj = document.getElementById("fcbImg");
	obj.src = URL+"img/btFbk.jpg";
}

function sobreIdioma(enlace){
	var obj = document.getElementById("langExtra");
	obj.posicion = 1;
	setTimeout(function () {actuaIdioma(enlace)}, 50)
}

function outIdioma(){
	var obj = document.getElementById("langExtra");
	obj.posicion = 0;
	setTimeout(function () {actuaIdioma()}, 50)
}

function overPdf(num){
	if(num!=null){
		var obj = document.getElementById("pdfImage"+num);
		var imagen = "pdf2.png"
	}else{
		var obj = document.getElementById("pdfImage");
		var imagen = "pdf2.jpg"
	}
	obj.src = URL+'img/'+imagen;
//	pngFix(obj)
}

function outPdf(num){
	if(num!=null){
		var obj = document.getElementById("pdfImage"+num);
		var imagen = "pdf.png"
	}else{
		var obj = document.getElementById("pdfImage");
		var imagen = "pdf1.jpg"
	}
	obj.src = URL+'img/'+imagen;
//	pngFix(obj)
}


function overDwn(num){
	$("#downImage"+num).stop(true);
	$("#downImage"+num).animate({ opacity:1 }, {duration: 600,easing: 'easeOutQuart'});
	$("#liDown"+num+" a").css("color","#3d3d3d")

}

function outDwn(num){
	$("#downImage"+num).stop(true);
	$("#downImage"+num).animate({ opacity:0.6 }, {duration: 600,easing: 'easeOutQuart'});
	$("#liDown"+num+" a").css("color","#8b8b8b")
}

function overBtnVina(nombre,area,localizacion){
	if(document.getElementById('helpMapa')!=null){
		$("#helpMapa").stop(true);
		$("#helpMapa").css("opacity",0);
		elemento=document.getElementById('helpMapa');
		elemento.parentNode.removeChild(elemento);
	}

	var sobre = document.createElement('div');
	sobre.id = "helpMapa";
	textoHtml = '<div id="nombreFinca">'+nombre+'</div>';
	textoHtml += '<div id="textoFinca"><span>'+localizacion+"</span> / "+area+'</div>';
	textoHtml += '<div id="clickFinca">'+CONSTANTES["CLICK"]+'</div>';
	sobre.innerHTML = textoHtml;
	var miMapa = document.getElementById('mapa');
	miMapa.appendChild(sobre);
	$("#helpMapa").css("opacity",0);
	$("#helpMapa").stop(true);
	$("#helpMapa").animate({ opacity:1 }, {duration: 600,easing: 'easeOutQuart'});
}

function outBtnVina(){
	$("#helpMapa").stop(true);
	$("#helpMapa").animate({ opacity:0 }, {duration: 600,easing: 'easeOutQuart', complete: function(){
		elemento=document.getElementById('helpMapa');
		elemento.parentNode.removeChild(elemento);
	}});
}


function actuaIdioma(enlace){
	var objeto = document.getElementById("langExtra");
	var pulsado = objeto.posicion;
	if(pulsado == 1){
		if(objeto.innerHTML==''){
/*			localizacionJS = location.pathname;
			trozos = localizacionJS.split("/")
			nuevaLocation = "";
			for(i=0;i<trozos.length-1;i++){
				nuevaLocation += trozos[i]+"/";
			}*/
			if(CONSTANTES['idioma']=="ES"){idioma = "en";idiomaMay = "EN"}else{idioma = "es";idiomaMay = "ES"}
			enlacePost = enlace + idioma;
//			objeto.innerHTML += '<a href="'+enlace+'" onmouseover="sobreIdioma()" onmouseout="outIdioma()" onfocus="sobreIdioma()"  onblur="outIdioma()">['+idiomaMay+']</a>';
			objeto.innerHTML = '<a href="'+enlacePost+'" onmouseover="sobreIdioma('+"'"+enlace+"'"+')" onmouseout="outIdioma()" onfocus="sobreIdioma()"  onblur="outIdioma()">['+idiomaMay+']</a>';
		}
//		appear(objeto,0)
	}else{
		objeto.innerHTML = "";
	}
}

function rollOver(obj,objSubM){
	if(CONSTANTES['idioma']=="ES"){idioma = "es"}else{idioma = "en"}
	var objeto = document.getElementById(obj);
	var archivoImg = "";
	numObjeto = objeto.id.slice(4,5)
	archivoImg = "b"+numObjeto+"b.jpg";
	objeto.src = URL+"img/menu/"+idioma+"/"+archivoImg;
	objeto.estado = 1;
	valorID = objeto.id
	eval("setTimeout(function () {actuaSubM('"+valorID+"',"+numObjeto+")}, 50)");  // Haciendolo con el eval evitamos que coja el valor de la variable cuando ejecute el timeout ya que puede haber cambiado
	if(objSubM!=null){
		var objetoSubMenu = document.getElementById(objSubM);
		objetoSubMenu.style.backgroundImage = "url("+URL+"img/bgSubM2.jpg" + ")";
	}
}

function rollOut(obj,objSubM){
	if(CONSTANTES['idioma']=="ES"){idioma = "es"}else{idioma = "en"}
	var objeto = document.getElementById(obj);
	var archivoImg = "";
	numObjeto = objeto.id.slice(4,5)
	if(numObjeto!=seccion){
		archivoImg = "b"+numObjeto+".jpg";
		objeto.src = URL+"img/menu/"+idioma+"/"+archivoImg;
	}
	objeto.estado = 2;
	valorID = objeto.id
	eval("setTimeout(function () {actuaSubM('"+valorID+"',"+numObjeto+")}, 50)");  // Haciendolo con el eval evitamos que coja el valor de la variable cuando ejecute el timeout ya que puede haber cambiado
	if(objSubM!=null){
		var objetoSubMenu = document.getElementById(objSubM);
		numObjeto2 = objetoSubMenu.id.slice(objetoSubMenu.id.length-1,objetoSubMenu.id.length)
		numObjeto = objetoSubMenu.id.slice(objetoSubMenu.id.length-3,objetoSubMenu.id.length-2)
//		alert(numObjeto+"  "+numObjeto2)
		if(numObjeto!=seccion || numObjeto2!=subSeccion){
			objetoSubMenu.style.backgroundImage = "url("+URL+"img/bgSubM.jpg" + ")";
		}
	}



}

function actuaSubM(obj,numObjeto){
	var objeto = document.getElementById(obj);
	objetoMenu = document.getElementById("subML"+numObjeto)
	if(objeto.estado == 1){
		if(objetoMenu.posicion==0){
			$("#subML"+numObjeto).stop(true);
			$("#subML"+numObjeto).animate({ height: objetoMenu.altoMax }, {duration: 200,easing: 'easeOutQuart'});
			objetoMenu.posicion=1
		}
	}else{
		if(objetoMenu.posicion==1){
			$("#subML"+numObjeto).stop(true);
			$("#subML"+numObjeto).animate({ height: 0 }, {duration: 200,easing: 'easeOutQuart'});
			objetoMenu.posicion=0
		}
	}
}



function InitFade(capa){
	var content = document.getElementById(capa);
	appear(content)
}

function inicioAppear(num){
	var content = document.getElementById("capaFoto"+num);
	if(content!=null){
		preHeight = content.offsetHeight
		preWidth = content.offsetWidth
//		content.style.height="1px"
//		content.style.width="1px"
//		creceFoto(content,preWidth,preHeight) 
		appear(content);
		nuevoNum = num+1;
		if(nuevoNum<=9){
			setTimeout(function () {inicioAppear(nuevoNum)}, 50-num*3);
		}
	}
}


function creceFoto(capa,finW,finH){
	repetir = false;
	if(capa.style.width=="" || capa.style.width=="udefined"){capa.style.width = capa.offsetWidth+"px";}
	if(capa.style.height=="" || capa.style.height=="udefined"){capa.style.height = capa.offsetHeight+"px";}

	if(capa.style.width.slice(0,capa.style.width.length-2)<finW-3){
		distancia = Math.round((finW - parseInt(capa.style.width.slice(0,capa.style.width.length-2))) / 2)
		capa.style.width = (parseInt(capa.style.width.slice(0,capa.style.width.length-2))+distancia)+"px";
		repetir = true;
	}else{
		capa.style.width = finW+"px";
	}
	if(capa.style.height.slice(0,capa.style.height.length-2)<finH-3){
		distancia = Math.round((finH - parseInt(capa.style.height.slice(0,capa.style.height.length-2))) / 2)
		capa.style.height = (parseInt(capa.style.height.slice(0,capa.style.height.length-2))+distancia)+"px";
		repetir = true;
	}else{
		capa.style.height = finH+"px";
	}

	if(repetir==true){
		setTimeout(function () {creceFoto(capa,finW,finH)}, 50);
	}else{
	}
}


function valida_enviar(){
	document.getElementById("formError").innerHTML = "";
	if (document.commentForm.comment.value.length==0){
		alert(CONSTANTES['ERROR1'])
		document.commentForm.comment.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR1'];
	}else if(document.commentForm.nombre.value.length==0){
		alert(CONSTANTES['ERROR2'])
		document.commentForm.nombre.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR2'];
	}else if(document.commentForm.correo.value.length==0){
		alert(CONSTANTES['ERROR3'])
		document.commentForm.correo.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR3'];
	}else if(document.commentForm.acceptPol.checked==false){
		alert(CONSTANTES['PRIVERROR'])
		document.commentForm.acceptPol.focus()
		document.getElementById("formError").innerHTML = CONSTANTES["PRIVERROR"];
	}else{
		correo = document.commentForm.correo.value;
		if(correo.split("@").length!=2 || correo.split("@")[0]=="" || correo.split("@")[1]=="" || correo.split("@")[1].split(".").length!=2 || correo.split("@")[1].split(".")[0]=="" || correo.split("@")[1].split(".")[1]==""){
			alert(CONSTANTES['ERROR4'])
			document.commentForm.correo.focus()
			document.getElementById("formError").innerHTML = CONSTANTES['ERROR4'];
		}else{
			enviaComment();
		}
	}
}



function generaReqCom(){
	var oXMLHttpRequest; 
	if(window.XMLHttpRequest) { // no es IE 
		oXMLHttpRequest = new XMLHttpRequest(); 
	} else { // Es IE o no tiene el objeto 
		try { 
			oXMLHttpRequest = new ActiveXObject('Microsoft.XMLHTTP'); 
		} catch (e) { 
			alert('El navegador utilizado no está soportado'); 
		} 
	} 
	return oXMLHttpRequest;
}

function enviaComment(){ 
	var oXMLHttpRequest = generaReqCom();
	oXMLHttpRequest.onreadystatechange = function(){
		if(oXMLHttpRequest.readyState == 4 && oXMLHttpRequest.status == 200)
		{
			var respuesta = oXMLHttpRequest.responseXML;
			var elementos = respuesta.getElementsByTagName("valor"); 
			var resultado = elementos[0].getElementsByTagName("enviado")[0].firstChild.data;
			if(resultado=="true"){
				alert(CONSTANTES['ENVIADO'])
				document.getElementById("formError").innerHTML = CONSTANTES['ENVIADO'];
				document.commentForm.comment.value="";
				document.commentForm.nombre.value="";
				document.commentForm.correo.value="";
			}else{
				alert(CONSTANTES['ERROR_ENVIO'])
				document.getElementById("formError").innerHTML = CONSTANTES['ERROR_ENVIO'];
			}
			obj = document.commentForm;
			obj.submit.style.visibility="visible";
		}
	};
	obj = document.commentForm;
	obj.submit.style.visibility="hidden";
	document.getElementById("formError").innerHTML = "Enviando...";
//	alert(URL+'inc/enviaCorreo_js.php?nombre='+document.commentForm.nombre.value+'&correo='+document.commentForm.correo.value+'&comment='+document.commentForm.comment.value)
	oXMLHttpRequest.open( 'GET', URL+'inc/enviaCorreo_js.php?nombre='+escape(document.commentForm.nombre.value)+'&correo='+document.commentForm.correo.value+'&comment='+escape(document.commentForm.comment.value), true );
	oXMLHttpRequest.send( null);
} 

function compruebaEdad(tipo){
	var alerta = false; 
	var fecha=new Date();
	var annoActual=fecha.getFullYear();
	var diferencias = CONSTANTES['EDADES_ARRAY'].split(",");

	switch(tipo){
		case 1:   //ESPAÑOL
			if(document.getElementById("nacimiento_es").value==0){
				alerta=true;
				elError = "No se ha indicado la edad"
			}else{
				nacimiento = parseInt(document.getElementById("nacimiento_es").value);
				diferencia = diferencias[parseInt(document.getElementById("pais_es").value)];
				if(annoActual-nacimiento<diferencia){
					alerta=true;
					elError = "Aun no has cumplido la edad necesaria para acceder a este tipo de contenidos en tu pais";
				}
			}
			break;
		case 2:   //INGLES
			if(document.getElementById("year_birth").value==0){
				alerta=true;
				elError = "E - No se ha indicado la edad"
			}else{
				nacimiento = parseInt(document.getElementById("year_birth").value);
				diferencia = diferencias[parseInt(document.getElementById("country").value)];
				if(annoActual-nacimiento<diferencia){
					alerta=true;
					elError = "E - Aun no has cumplido la edad necesaria para acceder a este tipo de contenidos en tu pais";
				}
			}
			break;
	}

	formulario = document.forms["condiciones"];


	if(alerta == false){
		document.forms["condiciones"].submit();
	}else{
		document.getElementById("formError").innerHTML = elError;
		alert("ERROR: "+elError)
	}
}


function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth-17;
        heightViewport= window.innerHeight-17;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
} 


function initCabeceraDinamica(fot,camb,alts,carpeta,activar){

//	alert(activar)

	fotos = fot.split(",");
	cambios = camb.split(",");
	alt = alts.split(",");
	carpetaCabecera = carpeta;
//	alert(fotos)
//	alert(cambios)
//	alert(alts)

	var sobre = document.createElement('div');
	sobre.id = "sobreBlack";
	sobre.innerHTML = "<!-- -->";
	var sobre2 = document.createElement('div');
	sobre2.id = "sobreBlack2";
	sobre2.innerHTML = "<!-- -->";
	var cabecera = document.getElementById('cabeceraDinamicaIn');
	cabecera.appendChild(sobre);
	cabecera.appendChild(sobre2);
	var foto = document.getElementById('foto1');

	if(activar==true){
		tween(sobre,"height",213,3,"acabaBlack")
		foto.onload = null;
		tween(foto,"alpha",100,3,"acabaFoto")
	}else{
		sobre.style.height = "213px";
		var property = foto.filters ? 'filter' : 'opacity';
		foto.style[property] = foto.filters ? 'alpha(opacity=' + 100 + ')' : 100/100;
		acabaBlack(activar);
	}
}

function acabaBlack(activar){
	var sobre2 = document.getElementById('sobreBlack2');
	sobre2.innerHTML = "<div id='tituloCabecera'><img id='tituloCabeceraImg' src='' alt='Titulo'/></div>";
	if(activar!=false){
		var imagen = document.getElementById('tituloCabeceraImg');
		var property = imagen.filters ? "filter" : "opacity"
		imagen.style[property] = imagen.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
		imagen.onload = function (){
			pngFix(imagen);
			tween(imagen,"alpha",100,3,null)
		}
		if(CONSTANTES['idioma']=="ES"){cabImg = "texto.png";}else{cabImg = "textoB.png";}
		imagen.src = URL+"img/cabeceras/"+carpetaCabecera+"/"+cabImg;
		var menu = document.getElementById('menuBodega');
		if(menu!=null){
			tween(menu,"alpha",100,3,null)
		}
	}else{
		var menu = document.getElementById('menuBodega');
		if(menu!=null){
			var property = menu.filters ? "filter" : "opacity"
			menu.style[property] = menu.filters ? "alpha(opacity=" + 100 + ")" : 100/100;
		}
		var imagen = document.getElementById('tituloCabeceraImg');
		imagen.onload = function (){
			pngFix(imagen);
		}
		if(CONSTANTES['idioma']=="ES"){cabImg = "texto.png";}else{cabImg = "textoB.png";}
		imagen.src = URL+"img/cabeceras/"+carpetaCabecera+"/"+cabImg;
		acabaFoto();

	}
}

function acabaFoto(){
	setTimeout(function () {
		var capa = document.getElementById('foto2');
		var property = capa.filters ? "filter" : "opacity"
		capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
		capa.onload = function (){
			tween(capa,"alpha",100,3,"acabaFoto2")
		}
		capa.src = URL+"img/cabeceras/"+carpetaCabecera+"/"+fotos[numFoto];
		numFoto++;
		if(numFoto>=fotos.length){numFoto=0;}
		if(interTime<10000){
			interTime = interTime+2000;
		}
	}, interTime);
			
}

function acabaFoto2(){
	var capa = document.getElementById('foto1');
	capa.onload = function (){
		var obj = document.getElementById('foto2');
		tween(obj,"alpha",0,5,"acabaFoto")	
	}
	capa.src = URL+"img/cabeceras/"+carpetaCabecera+"/"+fotos[numFoto];
}


function tween(capa,propiedad,destino,velocidad,funcion,objeto){
	if(eval("capa.idTO_" + propiedad)!=null){ 
		clearTimeout(eval("capa.idTO_" + propiedad))
	}
	doTween(capa,propiedad,destino,velocidad,funcion,objeto)
}


function doTween(capa,propiedad,destino,velocidad,funcion,objeto){
	repetir = false;
	switch (propiedad){
		case "top":
			if(capa.style.top=="" || capa.style.top=="udefined"){capa.style.top = capa.offsetTop+"px";}
			distancia = destino - parseInt(capa.style.top.slice(0,capa.style.top.length-2))
			if(distancia>1){
				distancia = distancia / velocidad ;
				capa.style.top = Math.ceil(parseInt(capa.style.top.slice(0,capa.style.top.length-2))+distancia)+"px";
				repetir = true;
			}else if(distancia<-1){
				distancia = distancia / velocidad ;
				capa.style.top = Math.floor(parseInt(capa.style.top.slice(0,capa.style.top.length-2))+distancia)+"px";
				repetir = true;
			}else{
				capa.style.top = destino+"px";
			}
			break;
		case "left":
			if(capa.style.left=="" || capa.style.left=="udefined"){capa.style.left = capa.offsetLeft+"px";}
			distancia = destino - parseInt(capa.style.left.slice(0,capa.style.left.length-2))
			if(distancia>1){
				distancia = distancia / velocidad ;
				capa.style.left = Math.ceil(parseInt(capa.style.left.slice(0,capa.style.left.length-2))+distancia)+"px";
				repetir = true;
			}else if(distancia<-1){
				distancia = distancia / velocidad ;
				capa.style.left = Math.floor(parseInt(capa.style.left.slice(0,capa.style.left.length-2))+distancia)+"px";
				repetir = true;
			}else{
				capa.style.left = destino+"px";
			}
			break;
		case "width":
			if(capa.style.width=="" || capa.style.width=="udefined"){capa.style.width = capa.offsetWidth+"px";}
			distancia = destino - parseInt(capa.style.width.slice(0,capa.style.width.length-2))
			if(distancia>1){
				distancia = distancia / velocidad ;
				capa.style.width = Math.ceil(parseInt(capa.style.width.slice(0,capa.style.width.length-2))+distancia)+"px";
				repetir = true;
			}else if(distancia<-1){
				distancia = distancia / velocidad ;
				capa.style.width = Math.floor(parseInt(capa.style.width.slice(0,capa.style.width.length-2))+distancia)+"px";
				repetir = true;
			}else{
				capa.style.width = destino+"px";
			}
			break;
		case "height":
			if(capa.style.height=="" || capa.style.height=="udefined"){capa.style.height = capa.offsetHeight+"px";}
			distancia = destino - parseInt(capa.style.height.slice(0,capa.style.height.length-2))
			if(distancia>1){
				distancia = distancia / velocidad ;
				capa.style.height = Math.ceil(parseInt(capa.style.height.slice(0,capa.style.height.length-2))+distancia)+"px";
				repetir = true;
			}else if(distancia<-1){
				distancia = distancia / velocidad ;
				capa.style.height = Math.floor(parseInt(capa.style.height.slice(0,capa.style.height.length-2))+distancia)+"px";
				repetir = true;
			}else{
				capa.style.height = destino+"px";
			}
			break;
		case "alpha":
			var property = capa.filters ? 'filter' : 'opacity';
			if(capa.style[property]== 'undefined' || capa.style[property]== ''){
				if(destino==0){value=100}else{value=0}
			}else{
				valor = parseInt(capa.style[property]);  
				if (isNaN(valor)) {  
				   //no es entero 0  
					value = parseInt(capa.style[property].slice(14,capa.style[property].length-1));
				}else{  
				   //es un valor entero  
					value = capa.style[property]*100;
				}  
			}
			distancia = destino - value;
			if(distancia>1){
				distancia = distancia / velocidad ;
				nuevoValor = Math.ceil(value + distancia);
				capa.style[property] = capa.filters ? 'alpha(opacity=' + nuevoValor + ')' : nuevoValor/100;
				repetir = true;
			}else if (distancia<-1){
				distancia = distancia / velocidad ;
				nuevoValor = Math.floor(value + distancia);
				capa.style[property] = capa.filters ? 'alpha(opacity=' + nuevoValor + ')' : nuevoValor/100;
				repetir = true;
			}else{
				capa.style[property] = capa.filters ? 'alpha(opacity=' + destino + ')' : destino/100;

			}
			break;
	}


	if(repetir==true){
		eval("capa.idTO_" + propiedad + " = setTimeout(function () {doTween(capa,propiedad,destino,velocidad,funcion,objeto)}, 50);");
//		idTimer = eval("capa.idTO_" + propiedad);
//		document.getElementById("trazador").innerHTML = document.getElementById("trazador").innerHTML+"<br/> Auto";
	}else{
//		eval("capa.idTO_" + propiedad +"=null");
		if(objeto==null){
			eval(funcion+"()")
		}else{
			eval(funcion+"('"+objeto+"')")
		}
	}
}


function cookieAdulto(){
	var oXMLHttpRequest; 
	if(window.XMLHttpRequest) { // no es IE 
		oXMLHttpRequest = new XMLHttpRequest(); 
	} else { // Es IE o no tiene el objeto 
		try { 
			oXMLHttpRequest = new ActiveXObject('Microsoft.XMLHTTP'); 
		} catch (e) { 
			alert('El navegador utilizado no está soportado'); 
		} 
	} 
	oXMLHttpRequest.open( 'GET', URL+'inc/cookieAdulto.php', true );
	oXMLHttpRequest.send( null );


}


function initMenu(){
	nombres = new Array("","BODEGA","VINEDO","VINOS","CLUB","PRENSA")
	archivosPhp = new Array("","bodega.php","vinedo.php","vinos.php","grupo.php","prensa.php")
	container = "cabeceraDer";
	contWidth = document.getElementById(container).offsetWidth;
	if(CONSTANTES['idioma']=="ES"){idioma = "es";}else{idioma = "en";}
	for(numSubM=1;numSubM<=5;numSubM++){
		objeto = document.getElementById("l"+numSubM)
		iniTop = objeto.offsetTop;
		iniLeft = objeto.offsetLeft;
		iniHeight = objeto.offsetHeight;
		iniRight = objeto.offsetLeft + objeto.offsetWidth;
		texto = '<div id="subML'+numSubM+'" class="subMenu">'  
		texto += '	<ul>'  
		i = 1;
		while(CONSTANTES['MENU_'+nombres[numSubM]+'_'+i]!=null){
			if(numSubM==5){extra = "/1"}else{extra = ""}
			enlace = URL+archivosPhp[numSubM]+'/'+CONSTANTES['MENU_'+nombres[numSubM]+'_'+i+'_LINK']+extra+"/"+idioma;
			texto += '	<li class="liMenuDin" id="lisubM_'+numSubM+'_'+i+'" onmouseover="rollOver('+"'"+'imgM'+numSubM+"'"+','+"'"+'lisubM_'+numSubM+'_'+i+"'"+')"  onmouseout="rollOut('+"'"+'imgM'+numSubM+"'"+','+"'"+'lisubM_'+numSubM+'_'+i+"'"+')" onclick="clickSubMenu('+"'"+enlace+"'"+');return false;">'
			texto += '		<a id="asubM_'+numSubM+'_'+i+'" href="'+enlace+'">'
//				alert(texto)
			var elArray = new Array();
			elArray["tagA"] = 'asubM_'+numSubM+'_'+i; 
			elArray["objStr"] = "subML"+numSubM; 
			elArray["iniLeft"] = iniLeft; 
			elArray["iniRight"] = iniRight; 
			elArray["texto"] = CONSTANTES['MENU_'+nombres[numSubM]+'_'+i] 
			elArray["fuente"] = 'Arial Bold Condensed'
			elArray["fontSize"] = 18
			elArray["textoCol"] = "ffffff"
			elArray["alto"] = 30
			elArray["alineamientoV"] = true
			generaImg(elArray);
			texto += '		</a>'
			texto += '	</li>'  
			i++;
		}
		texto += '	</ul>'  
		texto += '</div>'  
		objeto.innerHTML +=	texto;
		objeto = document.getElementById("subML"+numSubM)
		objeto.posicion=0;
		objeto.style.position = "absolute"
		objeto.style.top = iniTop+iniHeight+"px";
		objeto.style.zIndex = 49;
		objeto.style.overflow = "hidden";
		objeto.altoMax = objeto.offsetHeight;
		objeto.style.height = "0px";
	}

	var objetoSubMenu = document.getElementById("lisubM_"+seccion+"_"+subSeccion);
	objetoSubMenu.style.backgroundImage = "url("+URL+"img/bgSubM2.jpg" + ")";
	
	$(".liMenuDin").css("visibility","hidden")

}


function clickSubMenu(destino){
	if(letra!=17){
		document.location = destino;
	}else{
		window.open(destino)
		letra = "";
	}
}


function abajo(e) {
  var keyCode=0 ;

  if (isIE){
    keyCode=event.keyCode
  }else{
    keyCode=e.which;
  }
  letra = keyCode;
}

function arriba(e) {
  letra = "";
}

document.onkeydown = abajo;
document.onkeyup = arriba;

function alineaSubMenu(objStr,iniLeft,iniRight,objImg){
		objImg.style.height = "15px"
		objImg.style.marginTop = "8px"

		objeto = document.getElementById(objStr)
		objetoFinX = parseInt(iniLeft) + parseInt(objeto.offsetWidth)
		if(objetoFinX < contWidth){
			objeto.style.left = iniLeft+"px";
		}else{
//			alert("alineo")
			objeto.style.left = "0px";
			objeto.style.left = (iniRight-objeto.offsetWidth)+"px";
		}
		miId = objImg.parentNode.parentNode.id;
		$("#"+miId).css("visibility","visible")

}


function detenerPropagacion(){
	var e=window.event||arguments.callee.caller.arguments[0];
	e.cancelBubble = true;
	e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	if (e.preventDefault) e.preventDefault();
}


function generaImg(variables){



	var oXMLHttpRequest = generaReqCom();
	oXMLHttpRequest.onreadystatechange = function(){
		if(oXMLHttpRequest.readyState == 4 && oXMLHttpRequest.status == 200)
		{
			var respuesta = oXMLHttpRequest.responseXML;
			var elementos = respuesta.getElementsByTagName("valor"); 
			var resultado = elementos[0].getElementsByTagName("imgTag")[0].firstChild.data;
			var tag = elementos[0].getElementsByTagName("aTag")[0].firstChild.data;
			var objStr = elementos[0].getElementsByTagName("objStr")[0].firstChild.data;
			aTag = document.getElementById(tag)
			aTag.innerHTML = resultado;
//			alineaSubMenu(objStr,iniLeft,iniRight)
//			alert("resultado "+resultado+" aTag "+tag)
		}
	};


	sender = URL+'inc/generaImgXML.php?texto='+escape(variables["texto"]);
	if(variables["tagA"]!=null){sender += "&tagA="+variables["tagA"];}
	if(variables["objStr"]!=null){sender += "&objStr="+variables["objStr"];}
	if(variables["iniLeft"]!=null){sender += "&iniLeft="+variables["iniLeft"];}
	if(variables["iniRight"]!=null){sender += "&iniRight="+variables["iniRight"];}
	if(variables["fuente"]!=null){sender += "&fuente="+variables["fuente"];}
	if(variables["ancho"]!=null){sender += "&ancho="+variables["ancho"];}
	if(variables["alto"]!=null){sender += "&alto="+variables["alto"];}
	if(variables["bgCol"]!=null){sender += "&bgCol="+variables["bgCol"];}
	if(variables["textoCol"]!=null){sender += "&textoCol="+variables["textoCol"];}
	if(variables["fontSize"]!=null){sender += "&fontSize="+variables["fontSize"];}
	if(variables["sombraCol"]!=null){sender += "&sombraCol="+variables["sombraCol"];}
	if(variables["angulo"]!=null){sender += "&angulo="+variables["angulo"];}
	if(variables["saltoLinea"]!=null){sender += "&saltoLinea="+variables["saltoLinea"];}
	if(variables["alineamiento"]!=null){sender += "&alineamiento="+variables["alineamiento"];}
	if(variables["alineamientoV"]!=null){sender += "&alineamientoV="+variables["alineamientoV"];}
	if(variables["x"]!=null){sender += "&x="+variables["x"];}
	if(variables["y"]!=null){sender += "&y="+variables["y"];}




//	alert("sender "+sender)
	oXMLHttpRequest.open( 'GET', sender, true);
	oXMLHttpRequest.send( null);



}


//ampliado viñas


function ampliaVina(img,frase,carpeta,imgs,frases,descarga) {
	if(puedeAmpliar==true){
	    if (!isIE || version >=7){
			puedeAmpliar = false;
			putAmpliado(img,frase,carpeta,imgs,frases,descarga)
		}else{
			window.open(URL+""+carpeta+"/"+img)
		}
	}
}

function putAmpliado(img,frase,carpeta,imgs,frases,descarga){
	dimensionesWindow =  getWindowData();
	altoWin = dimensionesWindow[1];
	anchoWin = dimensionesWindow[0];
	cantidad = imgs.split(",").length;

	
	objeto = document.createElement("div");
	objeto.id = "ampliadoBkg"
	document.body.appendChild(objeto);
	$("#ampliadoBkg").css("height", "100%");
	$("#ampliadoBkg").css("width", "100%");

	$("#ampliadoBkg").css("position", "fixed");
	$("#ampliadoBkg").css("top", "0px");
	$("#ampliadoBkg").css("left", "0px");
	$("#ampliadoBkg").css("opacity", 0);
	$("#ampliadoBkg").animate({ opacity: 0.8 }, {duration: 600,easing: 'easeOutQuart'});

	
	objeto = document.createElement("div");
	objeto.id = "ampliadoVina"
	document.body.appendChild(objeto);
	$("#ampliadoVina").css("height", "40px");
	$("#ampliadoVina").css("width", "40px");
	$("#ampliadoVina").css("position", "fixed");
	$("#ampliadoVina").css("top", altoWin/2-15+"px");
	$("#ampliadoVina").css("left", anchoWin/2-15+"px");
//	$("#ampliado").css("opacity", 0.50);
	var ampliado= document.getElementById("ampliadoVina");

	objeto = new Image();
	objeto.id = "ampliadoImg"
	objeto.style.visibility = "hidden"
	objeto.onload = function(){
		ampliado.appendChild(objeto);
		anchoFinal = $("#ampliadoImg").width();
		altoFinal = $("#ampliadoImg").height();

		if(altoFinal>altoWin-50){
			proporcion = anchoFinal / altoFinal;
			altoFinal = altoWin - 50;
			anchoFinal = proporcion*altoFinal;
		}
		if(anchoFinal>anchoWin-50){
			proporcion = altoFinal / anchoFinal;
			anchoFinal = anchoWin - 50;
			altoFinal = proporcion*anchoFinal;
		}

		$("#ampliadoImg").css("height", "10px");
		$("#ampliadoImg").css("width", "10px");
		$("#ampliadoImg").css("visibility", "");
		$("#ampliadoImg").css("opacity", 0);


//		$("#ampliadoImg").css("margin", "5px");

		leftFinal = anchoWin/2 - anchoFinal/2
		topFinal = altoWin/2 - altoFinal/2
//		$("#ampliadoImg").animate({ height: altoFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart'});

		$("#ampliadoVina").hover( 
				//over
			function () {
				$("#ampliadoBar").stop(true);
				$("#ampliadoBar").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
				if(puedeOver = true){
					$("#ampliadoTexto").stop(true);
					$("#ampliadoTexto").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
				}
			},
			//out
			function () {
				$("#ampliadoBar").stop(true);
				$("#ampliadoBar").animate({ opacity: 0 }, {duration: 600,easing: 'easeOutQuart'});
				$("#ampliadoTexto").stop(true);
				$("#ampliadoTexto").animate({ opacity: 0 }, {duration: 600,easing: 'easeOutQuart'});
			}
		);
		
		
		
		$("#ampliadoVina").animate({top: topFinal, height: altoFinal}, {duration: 600,easing: 'easeInQuart',complete: function() {
			$("#ampliadoVina").animate({ left: leftFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart',complete: function() {
//				$("#ampliadoImg").css("top", "25px");
				$("#ampliadoImg").css("top", "0px");
				$("#ampliadoImg").css("left", "0px");
				$("#ampliadoImg").css("height", altoFinal+"px");
				$("#ampliadoImg").css("width", anchoFinal+"px");
				$("#ampliadoVina").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
				$("#ampliadoImg").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart',complete: function() {

					objeto = document.createElement("div");
					objeto.id = "ampliadoBar"
					ampliado.appendChild(objeto);
//					$("#ampliadoBar").css("opacity", 0);
					var ampliadoBar= document.getElementById("ampliadoBar");

					objeto = document.createElement("div");
					objeto.id = "ampliadoBarIn"
					ampliadoBar.appendChild(objeto);
					var ampliadoBarIn= document.getElementById("ampliadoBarIn");


	if(cantidad>1){
					objeto = document.createElement("div");
					objeto.id = "ampliadoLeft"
					objeto.innerHTML = '<a href="" onclick="cambiaAmpliado(1,'+"'"+imgs+"','"+carpeta+"','"+frases+"'"+','+descarga+');return false"><img id="ampliadoLeftBkg" src="'+URL+'/img/izqAmpliado.png" onload="arrancaIconosAmpliado(this)"/></a>'
					ampliadoBarIn.appendChild(objeto);
					$("#ampliadoLeftBkg").css("opacity", 0);
					objeto = document.createElement("div");
					objeto.id = "ampliadoRight"
					objeto.innerHTML = '<a href="" onclick="cambiaAmpliado(2,'+"'"+imgs+"','"+carpeta+"','"+frases+"'"+','+descarga+');return false"><img id="ampliadoRightBkg" src="'+URL+'/img/derAmpliado.png" onload="arrancaIconosAmpliado(this)"/></a>'
					objeto.imagen = img;
					ampliadoBarIn.appendChild(objeto);
					$("#ampliadoRightBkg").css("opacity", 0);
	}
					objeto = document.createElement("div");
					objeto.id = "ampliadoClose"
					objeto.innerHTML = '<a href="" onclick="cierraAmpliado();return false"><img id="ampliadoCloseBkg" src="'+URL+'/img/closeAmpliado.png"  onload="arrancaIconosAmpliado(this)"/></a>'
					ampliadoBarIn.appendChild(objeto);
					$("#ampliadoCloseBkg").css("opacity", 0);


	if(descarga==true){
					objeto = document.createElement("div");
					objeto.id = "ampliadoDownLoad"
					objeto.innerHTML = '<a href="" onclick="descargaAmpliado();return false"><img id="ampliadoDownLoadBkg" src="'+URL+'/img/downAmpliado.png"  onload="arrancaIconosAmpliado(this)"/></a>'
					ampliadoBarIn.appendChild(objeto);
					$("#ampliadoDownLoadBkg").css("opacity", 0);
	}


//					var cierre= document.getElementById("ampliadoClose");
//					cierre.onclick = cierraAmpliado();


					objeto = document.createElement("div");
					objeto.id = "ampliadoTexto"
					document.body.appendChild(objeto);
					objeto = document.getElementById("ampliadoTexto");
					objeto.innerHTML = frase;
					$("#ampliadoTexto").css("position", "fixed");
					suTop = $("#ampliadoVina").css("top");
					suHeight = $("#ampliadoVina").css("height");
					suTop = parseInt(suTop.substring(0,suTop.length-2))
					suHeight = parseInt(suHeight.substring(0,suHeight.length-2))



					$("#ampliadoTexto").css("opacity", 0);
					$("#ampliadoTexto").css("width", anchoFinal-37+"px");
					$("#ampliadoTexto").css("left", $("#ampliadoVina").css("left"));

					miTop = suTop + suHeight;
					miHeight = $("#ampliadoTexto").height();
					miWidth = $("#ampliadoTexto").css("width");
					miWidth = parseInt(miWidth.substring(0,miWidth.length-2))

//					alert("mitop antes "+miLeft+" miHeight "+miHeight+"  sltowin "+altoWin)
					if(miTop+miHeight>altoWin-20){
						miTop = altoWin - 40 - miHeight;
						$("#ampliadoTexto").css("padding-bottom", "20px");
						$("#ampliadoTexto").css("background", "#262626");
						$("#ampliadoTexto").css("width", miWidth+3+"px");
						$("#ampliadoTexto").css("border-width", "1px");
						$("#ampliadoTexto").css("border-color", "#ffffff");
						$("#ampliadoTexto").css("border-style", "solid");

					}
//					alert("mitop despues "+miTop+" miHeight "+miHeight+"  sltowin "+altoWin)
					
					$("#ampliadoTexto").css("top", miTop+"px");
					$("#ampliadoTexto").stop(true);
					$("#ampliadoTexto").animate({opacity:1}, {duration: 400,easing: 'easeInQuint'});


				
				}});
			}});
		}});
	}
	objeto.src = URL+"/"+carpeta+"/"+img;
	if(descarga==true){
		objeto.alt = frase;
	}
}

function arrancaIconosAmpliado(obj){
	pngFix(obj);
	$("#"+obj.id).stop(true);
	$("#"+obj.id).animate({opacity:1}, {duration: 400,easing: 'easeInQuint'});
}

function cambiaAmpliado(sentido,imgs,carpeta,frases,descarga){
	puedeOver = false
	objeto = document.getElementById('ampliadoRight');
	img = objeto.imagen;
	imagenes = imgs.split(",");
	lasFrases = frases.split("X|X");
	for(i=0;i<imagenes.length;i++){
		if(img == imagenes[i]){
			posicion = i;
			break;
		}
	}

	if(sentido==1){posicion --;}else{posicion ++;}
	if(posicion<0){posicion = imagenes.length-1}
	if(posicion>imagenes.length-1){posicion = 0}
	imgCarga = imagenes[posicion];
	objeto.imagen = imgCarga;
	$("#ampliadoTexto").stop(true);
	$("#ampliadoTexto").animate({opacity:0}, {duration: 400, easing: 'easeInQuint', complete: function() {
//			this.html(lasFrases[posicion]);
			objetoTexto = document.getElementById('ampliadoTexto');
			objetoTexto.innerHTML = "";
	}});
	$("#ampliadoImg").animate({opacity:0}, {duration: 400,easing: 'easeInQuint', complete: function() {
		elemento=document.getElementById('ampliadoImg');
		elemento.parentNode.removeChild(elemento);

		objeto = new Image();
		objeto.id = "ampliadoImg"
		objeto.style.visibility = "hidden"
		objeto.onload = function(){
			var ampliado= document.getElementById("ampliadoVina");
			ampliado.appendChild(objeto);
			anchoFinal = $("#ampliadoImg").width();
			altoFinal = $("#ampliadoImg").height();
			var ampliadoImg= document.getElementById("ampliadoImg");
//			ampliadoImg.onmouseover = apareceBar();
//			ampliadoImg.onmouseout = desapareceBar();

			if(altoFinal>altoWin-50){
				proporcion = anchoFinal / altoFinal;
				altoFinal = altoWin - 50;
				anchoFinal = proporcion*altoFinal;
			}
			if(anchoFinal>anchoWin-50){
				proporcion = altoFinal / anchoFinal;
				anchoFinal = anchoWin - 50;
				altoFinal = proporcion*anchoFinal;
			}

			$("#ampliadoImg").css("height", "10px");
			$("#ampliadoImg").css("width", "10px");
			$("#ampliadoImg").css("visibility", "");
			$("#ampliadoImg").css("opacity", 0);
			leftFinal = anchoWin/2 - anchoFinal/2
			topFinal = altoWin/2 - altoFinal/2
	//		$("#ampliadoImg").animate({ height: altoFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart'});
			$("#ampliadoVina").animate({top: topFinal, height: altoFinal}, {duration: 600,easing: 'easeInQuart',complete: function() {
				$("#ampliadoVina").animate({ left: leftFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart',complete: function() {
					$("#ampliadoImg").css("top", "0px");
					$("#ampliadoImg").css("left", "0px");
					$("#ampliadoImg").css("height", altoFinal+"px");
					$("#ampliadoImg").css("width", anchoFinal+"px");
					$("#ampliadoVina").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
					$("#ampliadoImg").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart',complete: function() {
					
					
					
						objetoTexto = document.getElementById('ampliadoTexto');
						objetoTexto.innerHTML = lasFrases[posicion];
						suTop = $("#ampliadoVina").css("top");
						suHeight = $("#ampliadoVina").css("height");
						suTop = parseInt(suTop.substring(0,suTop.length-2))
						suHeight = parseInt(suHeight.substring(0,suHeight.length-2))

						
						$("#ampliadoTexto").css("opacity", 0);
						$("#ampliadoTexto").css("width", anchoFinal-37+"px");
						$("#ampliadoTexto").css("left", $("#ampliadoVina").css("left"));

						miTop = suTop + suHeight;
						miHeight = $("#ampliadoTexto").height();
						miWidth = $("#ampliadoTexto").css("width");
						miWidth = parseInt(miWidth.substring(0,miWidth.length-2))

	//					alert("mitop antes "+miLeft+" miHeight "+miHeight+"  sltowin "+altoWin)
						if(miTop+miHeight>altoWin-20){
							miTop = altoWin - 40 - miHeight;
							$("#ampliadoTexto").css("padding-bottom", "20px");
							$("#ampliadoTexto").css("background", "#262626");
							$("#ampliadoTexto").css("width", miWidth+3+"px");
							$("#ampliadoTexto").css("border-width", "1px");
							$("#ampliadoTexto").css("border-color", "#ffffff");
							$("#ampliadoTexto").css("border-style", "solid");

						}else{
							$("#ampliadoTexto").css("background", "transparent");
							$("#ampliadoTexto").css("border-width", "0px");
						}


						$("#ampliadoTexto").css("top", miTop+"px");
						$("#ampliadoTexto").stop(true);
						$("#ampliadoTexto").animate({opacity:1}, {duration: 400,easing: 'easeInQuint',complete: function() {
							puedeOver = true;
						}});
					
					
					}});
				}});
			}});

		}
		objeto.src = URL+"/"+carpeta+"/"+imgCarga;
		if(descarga==true){
			objeto.alt = lasFrases[posicion];
		}

	}});

}

function cierraAmpliado(){
	dimensionesWindow =  getWindowData();
	altoWin = dimensionesWindow[1];
	anchoWin = dimensionesWindow[0];
	elemento=document.getElementById('ampliadoClose');
	elemento.parentNode.removeChild(elemento);
	if(cantidad>1){
		elemento=document.getElementById('ampliadoLeft');
		elemento.parentNode.removeChild(elemento);
		elemento=document.getElementById('ampliadoRight');
		elemento.parentNode.removeChild(elemento);
	}
	puedeAmpliar=true
	$("#ampliadoImg").css("position", "absolute");
	altoImg = $("#ampliadoVina").height();
	anchoImg = $("#ampliadoVina").width();

	$("#ampliadoTexto").animate({opacity:0}, {duration: 400,easing: 'easeInQuint'});
	$("#ampliadoImg").animate({top: altoImg/2-15, height: 30, left: anchoImg/2-15, width: 30, opacity:0}, {duration: 400,easing: 'easeInQuint',complete: function() {
		$("#ampliado").animate({top: altoWin/2-15, height: 30, left: anchoWin/2-15, width: 30, opacity:0.5}, {duration: 400,easing: 'easeInQuart',complete: function() {
		}});
			$("#ampliadoVina").animate({opacity:0}, {duration: 400,easing: 'easeInQuart',complete: function() {
				elemento=document.getElementById('ampliadoVina');
				elemento.parentNode.removeChild(elemento);
				$("#ampliadoBkg").animate({opacity:0}, {duration: 400,easing: 'easeOutQuart',complete: function() {
					elemento=document.getElementById('ampliadoBkg');
					elemento.parentNode.removeChild(elemento);
					elemento=document.getElementById('ampliadoTexto');
					elemento.parentNode.removeChild(elemento);
					puedeAmpliar=true
				}});
			}});
	}});
}

function descargaFichero(archivo,nombre){
	destino = URL+"inc/descargaFile.php?file="+archivo+"&fileNombre="+nombre;
//	alert(destino);
	document.location.href= destino
//	window.open(destino)
}

function descargaAmpliado(){
	objeto = document.getElementById('ampliadoImg');
	
	trozos = objeto.src.split("/");
	nuevaRuta = "";
	for(i=4;i<trozos.length;i++){
		if(i!=4){nuevaRuta += "/"}
		nuevaRuta += trozos[i];
	}

	trozosExt = nuevaRuta.split(".");
	extension = trozosExt[trozosExt.length-1];

	descargaFile = urlAmiga(objeto.alt)+"."+extension;
	
	destino = URL+"inc/descargaFile.php?file="+nuevaRuta;
//	alert(destino);
//	window.open(destino)
	document.location.href= destino
}


function urlAmiga(texto){
	texto = texto.toLowerCase()
	texto = str_replace("<br>","-",texto);
	texto = str_replace("<br/>","-",texto);
	texto = str_replace("\n","-",texto);
	texto = str_replace("\r","-",texto);
	texto = str_replace("á","a",texto);
	texto = str_replace("é","e",texto);
	texto = str_replace("í","i",texto);
	texto = str_replace("ó","o",texto);
	texto = str_replace("ú","u",texto);
	texto = str_replace("ü","u",texto);
	texto = str_replace("Á","A",texto);
	texto = str_replace("É","E",texto);
	texto = str_replace("Í","I",texto);
	texto = str_replace("Ó","O",texto);
	texto = str_replace("Ú","U",texto);
	texto = str_replace("Ü","u",texto);
	texto = str_replace("Ñ","N",texto);
	texto = str_replace("ñ","n",texto);
	texto = str_replace(",","-",texto);
	texto = str_replace(";","-",texto);
	texto = str_replace(":","-",texto);
	texto = str_replace("?","-",texto);
	texto = str_replace("¿","-",texto);
	texto = str_replace(" ","-",texto);
	texto = str_replace("_","-",texto);
	texto = str_replace(".","-",texto);
	texto = str_replace('"',"-",texto);
	texto = str_replace("'","-",texto);
	texto = str_replace(" ","-",texto);
	texto = str_replace("<span>","",texto);
	texto = str_replace("</span>","",texto);
	texto = str_replace("<strong>","",texto);
	texto = str_replace("</strong>","",texto);
	texto = str_replace("<li>","",texto);
	texto = str_replace("</li>","",texto);
	texto = str_replace("<ul>","",texto);
	texto = str_replace("</ul>","",texto);
	texto = str_replace("<p>","",texto);
	texto = str_replace("</p>","",texto);
	return texto;
}


function str_replace(busca, repla, orig)
{
	str 	= new String(orig);

	rExp	= busca;
	newS	= String(repla);

	do{
		str = new String(str.replace(rExp, newS));
		if(str.length!=orig.length){
			repetir=true
			orig = str;
		}else{
			repetir=false
		}
	}while(repetir==true);


	return str;
}

function overDwnNws(num){
	for(i=0;i<=2;i++){
		$("#downImage"+num+"_"+i).stop(true);
		$("#downImage"+num+"_"+i).animate({ opacity:1 }, {duration: 600,easing: 'easeOutQuart'});
	}
	$("#liDown"+num+" a").css("color","#3d3d3d")
	$("#liDown"+num+" a.rojo").css("color","#ff0000")

}

function outDwnNws(num){
	for(i=0;i<=2;i++){
		$("#downImage"+num+"_"+i).stop(true);
		$("#downImage"+num+"_"+i).animate({ opacity:0.6 }, {duration: 600,easing: 'easeOutQuart'});
	}
	$("#liDown"+num+" a").css("color","#8b8b8b")
}

function overImgNws(num,numImg){
	overDwnNws(num);
	destAncho = 160;
	destAlto = 160;
	enlace = $('#liDown'+num+' a').attr("href");

	if(document.getElementById('imgDinamica')!=null){
		outImgNws()
	}

	imagen = $("#downImage"+num+"_"+numImg).attr("src");
	var imgDinamica = document.createElement('img');
	imgDinamica.id = "imgDinamica";

	imagenObj = document.getElementById('downImage'+num+"_"+numImg)


	miTop = findAbsPosY(imagenObj) +1
	miLeft = findAbsPosX(imagenObj) +1


	miTopCent = findAbsPosY(imagenObj) + $("#downImage"+num+"_"+numImg).height() / 2 
	miLeftCent = findAbsPosX(imagenObj) + $("#downImage"+num+"_"+numImg).width() / 2 


	futuroTop = miTopCent - destAlto/2;
	futuroLeft = miLeftCent - destAncho/2;

	iniHeight = $("#downImage"+num+"_"+numImg).height();
	iniWidth = $("#downImage"+num+"_"+numImg).width();

	
	imgDinamica.onload = function(){
		$(this).stop(true);
		$(this).animate({ height: destAlto, width: destAncho, top: futuroTop, left: futuroLeft}, {duration: 600,easing: 'easeOutQuart', complete: function(){
//			alert("complete animation")
		}});
	}

	imgDinamica.onmouseover = function(){
		overDwnNws(num);
	}

	imgDinamica.onmouseout = function(){
		outImgNws()
		outDwnNws(num)
	}

	imgDinamica.onclick = function(){
		window.open(enlace)
	}

	imgDinamica.src = imagen;


	document.body.appendChild(imgDinamica);
	$("#imgDinamica").css("position","absolute")
	$("#imgDinamica").css("z-index","100000")
	$("#imgDinamica").css("top",miTop+"px")
	$("#imgDinamica").css("left",miLeft+"px")
	$("#imgDinamica").css("height",iniHeight+"px")
	$("#imgDinamica").css("width",iniWidth+"px")
	$("#imgDinamica").css("padding","5px")
	$("#imgDinamica").css("border-color","#dfdeb2")
	$("#imgDinamica").css("border-width","2px")
	$("#imgDinamica").css("border-style","solid")
	$("#imgDinamica").css("background","#f9f9ef")
	$("#imgDinamica").css("cursor","pointer")



}


function outImgNws(){
	elemento=document.getElementById('imgDinamica');
	elemento.parentNode.removeChild(elemento);
}


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

}

function findAbsPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function overCompartir(obj){
	obj.style.backgroundPosition = '0px -16px'
	var trozos = $(".fecebookBtn").attr("src").split("/");
	imagenActual = trozos[(trozos.length-1)].split(".")[0];
	imagenDestino = URL+"img/"+imagenActual+"2.jpg"
	$(".fecebookBtn").attr("src",imagenDestino)
}

function outCompartir(obj){
	obj.style.backgroundPosition = '0px -16px'
	var trozos = $(".fecebookBtn").attr("src").split("/");
	imagenActual = trozos[(trozos.length-1)].split(".")[0];
	imagenActual = imagenActual.slice(0,(imagenActual.length-1))
	imagenDestino = URL+"img/"+imagenActual+".jpg"
	$(".fecebookBtn").attr("src",imagenDestino)
}

/*  jugando con CANVAS
function cargaIframe(num){
	im = document.getElementById('downImage'+num);
	var canvas = document.createElement("canvas");
	if(canvas.getContext){ 
		canvas.width  = im.width  || im.offsetWidth; 
		canvas.height = im.height || im.offsetHeight; 
		canvas.getContext('2d').drawImage(im,0,0,71,28); 
		im.parentNode.replaceChild(canvas,im); 
	}




//	enlace = $('#liDown'+num+' a').attr("href");
//	alert(enlace)

	var testFrame = document.createElement("IFRAME");
	testFrame.id = "testFrame";
	testFrame.src = enlace;

	document.body.appendChild(testFrame);


	

	var myiframe = $("#testFrame");
	myiframe.load(function() {
		if (myiframe.get(0).contentDocument) {
			iframebody=$(myiframe.get(0).contentDocument.body);
		} else {
			iframebody=$(myiframe.get(0).contentWindow.document.body);
		}

		ancho = iframebody.width();
		alto = iframebody.height();

		proporcion = ancho/alto;
		alert("loaded   ancho "+ancho+"     alto "+alto+"   im  "+im)


		  var canvas = document.createElement("canvas");
		  if(canvas.getContext){ 
			alert("entro")
			canvas.width  = im.width  || im.offsetWidth; 
			canvas.height = im.height || im.offsetHeight; 
			canvas.getContext('2d').drawImage(myiframe,0,0,25,70); 
			im.parentNode.replaceChild(canvas,im); 
		//    canvasToGray(canvas,2);
		//    canvasToGray(canvas);
		  }



	});




}*/



