var altoAmpliado = 0;
var altoTotal = 466;
var URL = "http://www.thermobel.es/"
var ventanaMusica = "";
var previo = "";
var fotos = "";
var cambio = "";
var alt = "";
var carpetaCabecera = "";
var numFoto = 0;
var interTime = 10000;
var timerId = "";
var puedeActuar = false;
var sentidoSlide = 0;
var slideAuto = false;
var idCambio = "";
var preAmpliado = "";
var preAmpliadoImg = "";
var preAmpliadoTrans = "";
var ampliadoTexto = false;
var fotoSelected = 0;
var preCapaCargando="";
var altoScroll=0;
var recorridoScroll = 0;
var interScrollId = "";

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

function setContenido(objeto,texto) {
	document.getElementById(objeto).innerHTML = texto
}


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
	}
}


function seeMe(obj){
	obj.style.visibility="visible";
	pngFix(obj);

}
		

function amplia(img,carpeta,ID) {
	resto = altoTotal-altoAmpliado
	if(resto>5){
		altoAmpliado = altoAmpliado + resto/2
	}else{
		altoAmpliado = altoTotal
	}
	var capa= document.getElementById("ampliado");
	capa.style.height = altoAmpliado+"px";
	capa.style.top = '94px';
	if(altoAmpliado>=altoTotal){
//		contenido = '<img src="http://www.inspirate.es/clientes/otazu/img/fotoBig/'+img+'" class="imgAmpliada"/>';
		valor = '<div id="imgAmpliada">';
		valor+= '	<div style='+'"'+'background:url(http://www.inspirate.es/clientes/otazu/'+carpeta+img+")"+';width:971px;height:444px;"'+' id="imgAmpliadaIn">';
		valor+= '		<div id="cerrarAmpliado" onclick="cierra('+ID+')">'
		valor+= '			<div id="cerrarAmpliadoInBkg" onclick="cierra('+ID+')">'
		valor+= '			</div>'
		valor+= '			<div id="cerrarAmpliadoIn" onclick="cierra('+ID+')">'
		valor+= '				'+CONSTANTES['CERRAR_TXT'];
		valor+= '			</div>'
		valor+= '			<div id="cerrarAmpliadoInSobre" onclick="cierra('+ID+')">'
		valor+= '			</div>'
		valor+= '			<div id="cerrarAmpliadoIn2" onclick="cierra('+ID+')">'
		valor+= '				<img src="'+URL+'img/cerrar.jpg"/>'
		valor+= '			</div>'
		valor+= '		</div>'
		valor+= '	</div>'
		valor+= '</div>'
		setContenido("ampliado",valor)
        var content = document.getElementById("imgAmpliada");
        appear(content);
		if(ID!=null){
			obj = document.getElementById("menuGestor");
			previo = obj.innerHTML;
			obj.innerHTML = '<a href="" onclick="edit('+"'"+'galeria'+"'"+','+ID+');return false;" id="editBtn"><img src="'+URL+'img/iconos/entrar.jpg" title="Editar registro"/></a> ' + obj.innerHTML
		}
	}else{
		setTimeout(function () {amplia(img,carpeta,ID)}, 50)
	}
}

function cierra(ID){
	setContenido("ampliado","")
	var capa= document.getElementById("ampliado");
	resto = 0 - altoAmpliado;
	if(resto<-2){
		altoAmpliado = altoAmpliado + resto/2
	}else{
		altoAmpliado = 0
		capa.style.top = '-30px';
	}
	capa.style.height = altoAmpliado+"px";
	if(altoAmpliado>0){
		setTimeout(function () {cierra(ID)}, 50)
	}else{
		if(ID!=null){
			obj = document.getElementById("menuGestor");
			obj.innerHTML = previo;
		}
	}
}


function initAudio(){
	ventanaMusica = window.open(URL+"musica.php", "ventanaMusica", "left=00,top=00,width=220,height=40,location=no,menubar=no,scrollbars=no,status=no");
	valor = '<a href="" onClick="paraAudio();return false;">MÚSICA[ ON ]</a>';
	setContenido("musica",valor)
}


function paraAudio(){
	ventanaMusica.close()
	valor = '<a href="" onClick="initAudio();return false;">MÚSICA[ OFF ]</a>';
	setContenido("musica",valor)
}


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 overPrim(num){
	var obj = document.getElementById("liContent"+num);
	obj.style.background = "#398e31";
	obj = document.getElementById("ap"+num);
	obj.style.color = "#ffffff"
}

function outPrim(num){
	var obj = document.getElementById("liContent"+num);
	obj.style.background = "transparent";
	obj = document.getElementById("ap"+num);
	obj.style.color = "#323232"
}


function clickPrim(destino){
	document.location = destino;
}


function overSec(num){
	var obj = document.getElementById("li"+num);
	obj.style.background = "#c3c4bf url("+URL+"img/marcadorOn.jpg) no-repeat top left";
	obj = document.getElementById("a"+num);
	obj.style.color = "#38382c"
}

function outSec(num){
	var obj = document.getElementById("li"+num);
	obj.style.background = "#36382b"
	obj = document.getElementById("a"+num);
	obj.style.color = "#ffffff"
}


function clickSec(destino){
	document.location = destino;
}


function overTer(num){
	var obj = document.getElementById("at"+num);
//	obj.style.fontWeight = "600"
	obj.style.color = "#000000"
	var marca = document.getElementById("marcadort"+num);
	marca.style.background = 'url('+URL+'img/marcadorOn.jpg)'
}

function outTer(num){
	var obj = document.getElementById("at"+num);
//	obj.style.fontWeight = "400"
	obj.style.color = "#4e4e4e"
	var marca = document.getElementById("marcadort"+num);
	marca.style.background = 'url('+URL+'img/marcadorOff.jpg)'
}

function overPdf(){
	var obj = document.getElementById("pdfLink");
	obj.style.color = "#000000"
	var obj = document.getElementById("pdfImage");
	obj.src = URL+'img/pdf2.jpg'
}

function outPdf(){
	var obj = document.getElementById("pdfLink");
	obj.style.color = "#484848"
	var obj = document.getElementById("pdfImage");
	obj.src = URL+'img/pdf.jpg'
}


function overLang(num){
	var obj = document.getElementById("lb"+num);
	if(num==1){num2=2}else{num2=1}
	obj.style.color = "#503228"
	obj.style.textDecoration = "underline";
	var content = document.getElementById("sobre"+num2);
	content.direccion = 1;
	disappear(content)
}

function outLang(num){
	var obj = document.getElementById("lb"+num);
	if(num==1){num2=2}else{num2=1}
	obj.style.color = "#2b2b2b"
	obj.style.textDecoration = "none";
	var content = document.getElementById("sobre"+num2);
	content.direccion = 0;
	appear(content)
}

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

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

function actuaIdioma(){
	var objeto = document.getElementById("langExtra");
	var pulsado = objeto.posicion;
	if(pulsado == 1){
		if(objeto.innerHTML==''){
			localizacion = location.pathname;
			trozos = localizacion.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"}
			enlace = nuevaLocation + idioma;
			objeto.innerHTML = '<a href="'+enlace+'" onmouseover="sobreIdioma()" onmouseout="outIdioma()" onfocus="sobreIdioma()"  onblur="outIdioma()">['+idiomaMay+']</a>';
		}
//		appear(objeto,0)
	}else{
		objeto.innerHTML = "";
	}
}

function InitFade(capa){
	switch (capa)
	{
	case "noticias":
		capa = "interior";
		var content = document.getElementById(capa);
		appear(content)
		break;
	case "vinos":
		capa = "img_vinos_cont";
		var content = document.getElementById(capa);
		appear(content)
		break;
	case "galeria":
		capa = "fotografias";
		for(i=0;i<=9;i++){
			var content = document.getElementById("capaFoto"+i);
			if(content!=null){
				var property = content.filters ? 'filter' : 'opacity';
				content.style[property] = content.filters ? 'alpha(opacity=' + 0 + ')' : 0/100;
			}else{
				break;
			}
		}
		var content = document.getElementById(capa);
		var property = content.filters ? 'filter' : 'opacity';
		content.style[property] = content.filters ? 'alpha(opacity=' + 100 + ')' : 100/100;
		inicioAppear(0);
		break;
	}
}

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(){
	visita = document.getElementById("telefono");
	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(visita!=null && (document.commentForm.telefono.value.length!=9)){
		alert(CONSTANTES['ERROR5'])
		document.commentForm.telefono.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR5'];
	}else if(visita==null && document.commentForm.correo.value.length==0){
		alert(CONSTANTES['ERROR3'])
		document.commentForm.correo.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR3'];
	}else if(visita!=null && document.commentForm.correo2.value.length==0){
		alert(CONSTANTES['ERROR3'])
		document.commentForm.correo2.focus()
		document.getElementById("formError").innerHTML = CONSTANTES['ERROR3'];
	}else{
		if(visita==null){
			correo = document.commentForm.correo.value;
		}else{
			correo = document.commentForm.correo2.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{
			if(visita==null){
				enviaComment(false);
			}else{
				enviaComment(true);
			}
		}
	}
}


function enviaComment(visita){ 
	var oXMLHttpRequest = generaReqHome();
	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="";
				if(visita==false){
					document.commentForm.correo.value="";
				}else{
					document.commentForm.correo2.value="";
					document.commentForm.telefono.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...";
	if(visita==false){
		oXMLHttpRequest.open( 'GET', URL+'inc/enviaCorreo_js.php?nombre='+document.commentForm.nombre.value+'&correo='+document.commentForm.correo.value+'&comment='+document.commentForm.comment.value, true );
	}else{
		oXMLHttpRequest.open( 'GET', URL+'inc/enviaCorreo_js.php?nombre='+document.commentForm.nombre.value+'&correo='+document.commentForm.correo2.value+'&comment='+document.commentForm.comment.value+'&telefono='+document.commentForm.telefono.value, true );
	}
	oXMLHttpRequest.send( null);
} 


function generaReqHome(){
	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 cambiaInterior(sentido,cambiando){
	if(puedeActuar==true){

		var capa = document.getElementById("fotoAmpliada");
		if(capa!=null){
			var capa = document.getElementById("fotoAmpliada");
			prefoto = capa.src;
			var capa = document.getElementById("foto1");
			capa.src = prefoto;
			var capa = document.getElementById("fotoAmpliada");
			var property = capa.filters ? "filter" : "opacity";
			capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
		}




		puedeActuar = false;
		sentidoSlide = sentido;
		idCambio = cambiando;
		var capa = document.getElementById('foto0');
		if(sentidoSlide=="0"){
			numFoto++;
			if(numFoto>=fotos.length){numFoto=0;}
			numFotoAcargar = numFoto+1;
			if(numFotoAcargar>=fotos.length){numFotoAcargar=0;}
			capa.style.left = "1928px";
		}else{
			numFoto--;
			if(numFoto<0){numFoto=fotos.length-1;}
			numFotoAcargar = numFoto;
			capa.style.left = "-964px";
		}

		var preL = document.getElementById('prelad2');
		preL.style.visibility = "";


		capa.onload = function (){
			capa.style.visibility = "";
			animaSlide(sentidoSlide)
			var preL = document.getElementById('prelad2');
			preL.style.visibility = "hidden";
//			tween(capa,"alpha",100,3,"acabaFoto2")
		}
		capa.onerror = function (){
			capa.style.visibility = "";
			animaSlide(sentidoSlide)
			var preL = document.getElementById('prelad2');
			preL.style.visibility = "hidden";

		}
		capa.style.visibility = "hidden";
		capa.src = "";
		capa.src = URL+"lib/"+carpetaCabecera+"/"+fotos[numFotoAcargar];
	}
}


function animaSlide(sentido){
	switch(sentido){
		case "0":
			destX0=964; destA0=50;
			destX1=-964; destA1=0;
			destX2=0; destA2=100;
			break;
		case "1":
			destX0=0; destA0=100;
			destX1=964; destA1=50;
			destX2=1928; destA2=0;
			break;
	}
	var foto = document.getElementById('foto0');
	tween(foto,"alpha",destA0,3,null)
	tween(foto,"left",destX0,3,null)	
	var foto = document.getElementById('foto1');
	tween(foto,"alpha",destA1,3,null)
	tween(foto,"left",destX1,3,null)	
	var foto = document.getElementById('foto2');
	tween(foto,"alpha",destA2,3,null)
	tween(foto,"left",destX2,3,"acabaAnimacion")	
	puedeActuar = false;

	var flecha = document.getElementById('btnLeft');
	flecha.src =  URL+"img/btnLeft2.png";
	pngFix(flecha);
	flecha = document.getElementById('btnRight');
	flecha.src =  URL+"img/btnRight2.png";
	pngFix(flecha);
	oferta = document.getElementById('ofertaImg');
	if(oferta!=null && seccionOf!=true){
		var property = oferta.filters ? "filter" : "opacity";
		oferta.style[property] = oferta.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
	}

	clearTimeout(timerId);

}

function acabaAnimacion(){

	preFoto = numFoto-1;
	if(preFoto<0){preFoto=fotos.length-1;}


	nextFoto = numFoto+1;
	if(nextFoto>=fotos.length){nextFoto=0;}


	var foto = document.getElementById('foto0');
	foto.id = "temp0";
	var foto = document.getElementById('foto1');
	foto.id = "temp1";
	var foto = document.getElementById('foto2');
	foto.id = "temp2";

	if(sentidoSlide=="0"){
		var foto = document.getElementById('temp0');
		foto.id = "foto2";
		var foto = document.getElementById('temp1');
		foto.id = "foto0";
		var foto = document.getElementById('temp2');
		foto.id = "foto1";
	}else{
		var foto = document.getElementById('temp0');
		foto.id = "foto1";
		var foto = document.getElementById('temp1');
		foto.id = "foto2";
		var foto = document.getElementById('temp2');
		foto.id = "foto0";
	}
	
	if(idCambio!=null){
		document.location.href = URL+idCambio;
	}else{
		puedeActuar = true;
		var flecha = document.getElementById('btnLeft');
		flecha.src =  URL+"img/btnLeft.png";
		pngFix(flecha);
		flecha = document.getElementById('btnRight');
		flecha.src =  URL+"img/btnRight.png";
		pngFix(flecha);
	}

	if(slideAuto==true){
		timerId = setTimeout(function () {
			cambiaInterior("0")
			interTime = interTime+1000;
		}, interTime);
	}
}

function initScroll(){
	var objTexto = document.getElementById('ssTbCenterCenterTxtIn');
	altoScroll = objTexto.offsetHeight;
	recorridoScroll = altoScroll - 260 +10;
}

function overScroll(dir,aceleracion){
	var obj = document.getElementById("ssTbCenterCenterTxtIn");
	obj.posicion = 1;
	obj.direccion = dir;
	obj.aceleracion = aceleracion;
	setTimeout(function () {actuaScroll()}, 50)
}


function outScroll(dir,aceleracion){
	var obj = document.getElementById("ssTbCenterCenterTxtIn");
	obj.posicion = 0;
	obj.direccion = dir;
	obj.aceleracion = aceleracion;
	setTimeout(function () {actuaScroll()}, 50)
}

function actuaScroll(){
	var obj = document.getElementById("ssTbCenterCenterTxtIn");
	pulsado = obj.posicion;
	if(pulsado == 1){
		if(recorridoScroll>0){
			mueveScroll(obj.direccion,obj.aceleracion)
		}
	}else{
		paraScroll()
	}
}



function mueveScroll(dir,aceleracion){
	// 0 arriba  1 abajo


	var capa = document.getElementById('ssTbCenterCenterTxtIn');
	if(capa.style.top=="" || capa.style.top=="udefined"){capa.style.top = capa.offsetTop+"px";}
	posY = parseInt(capa.style.top.slice(0,capa.style.top.length-2))
	if(aceleracion==true){
		if(dir==0){
			velocidad = (recorridoScroll+posY)/10;
		}else{
			velocidad = (-posY)/10;
		}
	}else{
		velocidad = 1;
	}	

	if(dir==0){
		if(posY-velocidad>-recorridoScroll){
			capa.style.top = (posY-velocidad)+"px";
			clearTimeout(interScrollId)
			interScrollId = setTimeout(function () {mueveScroll(dir,aceleracion)},50)
		}else{
			capa.style.top = recorridoScroll+"px";
		}
	}else if(dir==1){
		if(posY+velocidad<0){
			capa.style.top = (posY+velocidad)+"px";
			clearTimeout(interScrollId)
			interScrollId = setTimeout(function () {mueveScroll(dir,aceleracion)},50)
		}else{
			capa.style.top = "0px";
		}
	}
}

function paraScroll(){
	clearTimeout(interScrollId)
}

function initSlideShow(fot,carpeta,cambiaSec,home){

	var capa= document.getElementById("imgCatMini"+0);
	if(capa!=null){
		var property = capa.filters ? "filter" : "opacity";
		capa.style[property] = capa.filters ? "alpha(opacity=" + 50 + ")" : 50/100;
		capa.style.borderColor = "#c54f4f";
	}

	fotos = fot.split(",");
	carpetaCabecera = carpeta;

	slideAuto = home;

	if(cambiaSec!=false){
		var foto = document.getElementById('foto1');
		if(foto!=null){
			foto.onload = null;
			tween(foto,"alpha",100,3,"slideActivado")
		}
		var foto = document.getElementById('foto2');
		if(foto!=null){
			foto.style.left = "964px";
			foto.onload = null;
			foto.onload = function(){
				tween(foto,"alpha",50,3,null)
			};
			foto.src = URL+"lib/"+carpetaCabecera+"/"+fotos[numFoto+1];
		}
	}else{
		var foto = document.getElementById('foto1');
		if(foto!=null){
		var property = foto.filters ? "filter" : "opacity";
		foto.style[property] = foto.filters ? "alpha(opacity=" + 100 + ")" : 100/100;
		}
		var foto = document.getElementById('foto2');
		if(foto!=null){
			var property = foto.filters ? "filter" : "opacity";
			foto.style[property] = foto.filters ? "alpha(opacity=" + 50 + ")" : 50/100;
		}
		slideActivado();
	}

	var preL = document.getElementById('prelad2');
	preL.style.visibility = "hidden";
	if(foto!=null){
		if(slideAuto==true){
			timerId = setTimeout(function () {
				cambiaInterior("0")
				interTime = interTime+2000;
			}, interTime);
		}
	}
}

function slideActivado(){
	puedeActuar = true;
}

function cambiaFoto(fotoAmpliada,numero){
	if(ampliadoTexto!=true){

		var capa= document.getElementById("imgCatMini"+fotoSelected);
		capa.style.borderColor = "#fffeff";
		var property = capa.filters ? "filter" : "opacity";
		capa.style[property] = capa.filters ? "alpha(opacity=" + 100 + ")" : 100/100;

		var capa= document.getElementById("imgCatMini"+numero);
		var property = capa.filters ? "filter" : "opacity";
		capa.style[property] = capa.filters ? "alpha(opacity=" + 50 + ")" : 50/100;
		capa.style.borderColor = "#c54f4f";
		preCapaCargando = capa.innerHTML;
		capa.innerHTML +='<div id="cargandoCat"></div>';

		fotoSelected = numero;
		var capa= document.getElementById("ssImg");
		valor = '	<img id="fotoAmpliada" src="" alt="Imagen Ampliada"/>';
		if(preAmpliadoImg==""){
			preAmpliadoImg = capa.innerHTML;
			capa.innerHTML += valor;
			var capa = document.getElementById("fotoAmpliada");
			var property = capa.filters ? "filter" : "opacity";
			capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
			capa.onload = function(){
				tween(capa,"alpha",100,3);
				var capa2= document.getElementById("imgCatMini"+fotoSelected);
				capa2.innerHTML = preCapaCargando;
			}
			capa.src = 	URL+"lib/catalogo/big/"+fotoAmpliada;	
		}else{
			var capa = document.getElementById("fotoAmpliada");
			prefoto = capa.src;
			var capa = document.getElementById("foto1");
			capa.src = prefoto;
			var capa = document.getElementById("fotoAmpliada");
			capa.src = URL+"lib/catalogo/big/"+fotoAmpliada;
			var property = capa.filters ? "filter" : "opacity";
			capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
			capa.onload = function(){
				tween(capa,"alpha",100,3);
				var capa2= document.getElementById("imgCatMini"+fotoSelected);
				capa2.innerHTML = preCapaCargando;
			}
			capa.src = 	URL+"lib/catalogo/big/"+fotoAmpliada;	
		}
	}
}


function generaAmpliado(textoAmpliado){
	if(ampliadoTexto!=true){
		var capa= document.getElementById("ssImg");
		valor = '	<div id="catalogoAmpliadoJs">';
		valor += '		<div id="catalogoAmpliadoIn">';
		valor += '			'+textoAmpliado;
		valor += '		</div>';
		valor += '		<a id="cerrarAmpliado" href="" title="Cerrar" onclick="cierraAmpliado();return false"><img src="'+URL+'img/cerrarAmp.jpg" alt="Cerrar"/></a>';
		valor += '	</div>';
		valor += '		<div id="catalogoAmpliadoBkg"></div>';
		preAmpliado = capa.innerHTML;
		capa.innerHTML += valor;
		var capa = document.getElementById("catalogoAmpliadoJs");
		var property = capa.filters ? "filter" : "opacity";
		capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
		var capa = document.getElementById("catalogoAmpliadoBkg");
		var property = capa.filters ? "filter" : "opacity";
		capa.style[property] = capa.filters ? "alpha(opacity=" + 0 + ")" : 0/100;
		var capa= document.getElementById("ssImg");
		var capa = document.getElementById("catalogoAmpliadoJs");
		tween(capa,"alpha",100,3)
		var capa = document.getElementById("catalogoAmpliadoBkg");
		tween(capa,"alpha",90,3)
		ampliadoTexto = true;
	}

}

function cierraAmpliado(){
	var capa = document.getElementById("catalogoAmpliadoJs");
	tween(capa,"alpha",0,3,"acabaCierreAmpliado")
	var capa = document.getElementById("catalogoAmpliadoBkg");
	tween(capa,"alpha",0,3)
}


function acabaCierreAmpliado(){
	var capa= document.getElementById("ssImg");
	capa.innerHTML = preAmpliado;
	ampliadoTexto = false;
}


function tween(capa,propiedad,destino,velocidad,funcion,objeto,repeat){
	repetir = false;
	eval("idTimer = capa.idTO_" + propiedad);
//	alert(idTimer)
	if(idTimer!=null && repeat!=true){ clearTimeout(idTimer)}

	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]== ''){
				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;
				}  
			}
			nuevoValor = value + Math.round((destino - value) / velocidad);
			capa.style[property] = capa.filters ? 'alpha(opacity=' + nuevoValor + ')' : nuevoValor/100;
			if ((destino>value && nuevoValor>=destino-3) || (destino<value && nuevoValor<=destino+3)) {
				capa.style[property] = capa.filters ? 'alpha(opacity=' + destino + ')' : destino/100;
			}else{
				repetir = true;
			}
			break;
	}


	if(repetir==true){
		eval("capa.idTO_" + propiedad + " = setTimeout(function () {tween(capa,propiedad,destino,velocidad,funcion,true)}, 50);");
	}else{
		if(objeto==null){
			eval(funcion+"()")
		}else{
			eval(funcion+"('"+objeto+"')")
		}
	}
}



//ampliado dinamico
var puedeAmpliar=true
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 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 ampliaImgTodo(img,carpeta,imgs,descarga) {
	if(puedeAmpliar==true){
	    if (!isIE || version >=7){
			puedeAmpliar = false;
			putAmpliado(img,carpeta,imgs,descarga)
		}else{
			window.open(URL+carpeta+"/"+img)
		}
	}
}

function putAmpliado(img,carpeta,imgs,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 = "ampliadoFull"
	document.body.appendChild(objeto);
	$("#ampliadoFull").css("height", "40px");
	$("#ampliadoFull").css("width", "40px");
	$("#ampliadoFull").css("position", "fixed");
	$("#ampliadoFull").css("top", altoWin/2-15+"px");
	$("#ampliadoFull").css("left", anchoWin/2-15+"px");
	$("#ampliadoFull").corners("8px transparent");

//	$("#ampliado").css("opacity", 0.50);
//	alert("ele post corn")
	var ampliado= document.getElementById("ampliadoFull");

	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'});

		$("#ampliadoFull").hover( 
				//over
			function () {
				$("#ampliadoBar").stop(true);
				$("#ampliadoBar").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
			},
			//out
			function () {
				$("#ampliadoBar").stop(true);
				$("#ampliadoBar").animate({ opacity: 0 }, {duration: 600,easing: 'easeOutQuart'});
			}
		);
		
		
		
		$("#ampliadoFull").animate({top: topFinal, height: altoFinal}, {duration: 600,easing: 'easeInQuart',complete: function() {
			$("#ampliadoFull").animate({ left: leftFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart',complete: function() {
//				$("#ampliadoImg").css("top", "25px");
				$("#ampliadoImg").css("top", "20px");
				$("#ampliadoImg").css("left", "20px");
				$("#ampliadoImg").css("height", altoFinal-40+"px");
				$("#ampliadoImg").css("width", anchoFinal-40+"px");
				$("#ampliadoFull").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+"'"+');return false"><img id="ampliadoLeftBkg" src="'+URL+'/img/izqAmpliado.png?nocache='+getNocache()+'" onload="arrancaIconosAmpliado(this)"/></a>'
					ampliadoBarIn.appendChild(objeto);
					$("#ampliadoLeftBkg").css("opacity", 0);
	}

					objeto = document.createElement("div");
					objeto.id = "ampliadoClose"
					objeto.innerHTML = '<a href="" onclick="cierraAmpliado2();return false"><img id="ampliadoCloseBkg" src="'+URL+'/img/closeAmpliado.png?nocache='+getNocache()+'"  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);
	}



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

	objeto.src = URL+carpeta+"/"+img;
}


function getNocache(){
	nocache = "_nocache"+Math.floor(Math.random()*1111111111111) 
	return nocache;
}

function descargaAmpliado(){
	objeto = document.getElementById('ampliadoImg');
//	alert(objeto.src);
	
	trozos = objeto.src.split("/");
	nuevaRuta = "";
	for(i=4;i<trozos.length;i++){
		if(i!=4){nuevaRuta += "/"}
		nuevaRuta += trozos[i];
	}
	destino = URL+"inc/descargaFile.php?file="+nuevaRuta;
//	alert(destino);
//	window.open(destino)
	document.location.href= destino
}

function descargaFichero(archivo,nombre){
	destino = URL+"inc/descargaFile.php?file="+archivo+"&fileNombre="+nombre;
//	pageTracker._trackPageview('#/descarga_archivo/'+nombre);

//	alert(destino);
	document.location.href= destino
//	window.open(destino)
}


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

function cambiaAmpliado(sentido,imgs,carpeta){
	objeto = document.getElementById('ampliadoRight');
	img = objeto.imagen;
	imagenes = imgs.split(",");
	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;
	$("#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("ampliadoFull");
			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'});
			$("#ampliadoFull").animate({top: topFinal, height: altoFinal}, {duration: 600,easing: 'easeInQuart',complete: function() {
				$("#ampliadoFull").animate({ left: leftFinal, width: anchoFinal}, {duration: 600,easing: 'easeOutQuart',complete: function() {
					$("#ampliadoImg").css("top", "20px");
					$("#ampliadoImg").css("left", "20px");
					$("#ampliadoImg").css("height", altoFinal-40+"px");
					$("#ampliadoImg").css("width", anchoFinal-40+"px");
					$("#ampliadoFull").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart'});
					$("#ampliadoImg").animate({ opacity: 1 }, {duration: 600,easing: 'easeOutQuart',complete: function() {
					}});
				}});
			}});

		}
		objeto.src = URL+carpeta+"/"+imgCarga;
	}});

}

function cierraAmpliado2(){
	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 = $("#ampliadoFull").height();
	anchoImg = $("#ampliadoFull").width();

	$("#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() {
		}});
			$("#ampliadoFull").animate({opacity:0}, {duration: 400,easing: 'easeInQuart',complete: function() {
				elemento=document.getElementById('ampliadoFull');
				elemento.parentNode.removeChild(elemento);
				$("#ampliadoBkg").animate({opacity:0}, {duration: 400,easing: 'easeOutQuart',complete: function() {
					elemento=document.getElementById('ampliadoBkg');
					elemento.parentNode.removeChild(elemento);
					puedeAmpliar=true
				}});
			}});
	}});
}
