var fotoact=0;
var totalfotos;
/*
function iniciar() {

	for(trans=0, tiempo=25;trans<=100; trans+=2,tiempo+=25) {
	
		setTimeout("transparenta('foto1', "+trans+")", tiempo);
	
	}

	fotoact=1;
	setTimeout("fotosig()", tiempo+=12000);
}

function fotosig() {

	if(totalfotos==fotoact) {
	
		for(trans=0, tiempo=25; trans<=100; trans+=5, tiempo+=25) {
		
			setTimeout("transparenta('foto1', "+trans+")", tiempo);
		
		}
	
		for(trans=100, tiempo=25; trans>=0; trans-=5, tiempo+=25) {
		
			setTimeout("transparenta('foto"+fotoact+"', "+trans+")", tiempo);
		
		}
		fotoact=1;
	} else {
	
		for(trans=0, tiempo=25; trans<=100; trans+=5, tiempo+=25) {
		
			setTimeout("transparenta('foto"+(fotoact+1)+"', "+trans+")", tiempo);
		
		}
	
		for(trans=100, tiempo=25; trans>=0; trans-=5, tiempo+=25) {
		
			setTimeout("transparenta('foto"+fotoact+"', "+trans+")", tiempo);
		
		}
	
		fotoact++;
	}

	setTimeout("fotosig()", tiempo+=12000);

}

*/
$(document).ready(function(){

	var tab = $('#navigation li a');
	tab.mouseenter(function(){
		$(this).stop().animate({
			paddingLeft:40,
			width:235
		}, 200);
	});

	tab.mouseout(function(){
		$(this).stop().animate({
			paddingLeft:20,
			width:200
		}, 200);
	});
});
$(document).ready(function(){
 
    $("#fonditos").simpleSlide({duration:10500,transition:900});
 
});



$(document).ready(function(){

	var tab = $('#languages a');
	tab.mouseenter(function(){
		$(this).stop().animate({
			paddingTop:15,
			opacity:1
		}, 450);
	});

	tab.mouseout(function(){
		$(this).stop().animate({
			paddingTop:5,
			opacity:0.35
		}, 225);
	});
});






$(document).ready(function(){

	var tab = $('.absolutamente');
	tab.mouseenter(function(){
		$(this).stop().animate({
			opacity:1
		}, 600);
	});

	tab.mouseout(function(){
		$(this).stop().animate({
			opacity:0.65
		}, 500);
	});
});



jQuery.fn.simpleSlide = function(a){
 
    a               = a || {};
    a.duration      = a.duration || 4000;
    a.transition    = a.transition || 1000;
    a.stopAt        = a.stopAt || false;
 
    var c   = $(this);
 
    $(c).css("position","relative");
 
    $("img",$(c))
        .css({
            'position'  : 'absolute',
            'top'       : '0px',
            'left'      : '0px',
            'z-index'   : '8'
            })
        .find(":first")
            .addClass("slide-active")
            .css('z-index','10');
 
    var cnt         = 0;
 
    var interval    = setInterval(function(){
 
            if(!isNaN(a.stopAt)){
                cnt++;
                if(cnt==a.stopAt){
                    clearTimeout(interval);
                }
            }
 
            var $active = $("img.slide-active",$(c));
 
            if($active.length == 0) $active = $("img:last",$(c));
 
            var $next   = $active.next().length ? $active.next() : $("img:first",$(c));
 
            $active
                .addClass("slide-last-active")
                .css('z-index','9');
 
            $next
                .css({opacity: 0.0})
                .addClass("slide-active")
                .css('z-index','10')
                .animate({opacity: 1.0}, a.transition, function(){
                    $active
                        .removeClass('slide-active slide-last-active')
                        .css('z-index','8');
                });
        }, a.duration);
 
}

var menuacut=0;

function aver(cual) {
	if(menuacut==0) {
		menuacut=1; if(cual!=1) { setTimeout("aver("+cual+")", 500); } else {txtinicio();}
	} else {
		if(cual==3) {
		
			if(navigator.appName=="Microsoft Internet Explorer") {
		
				if(cual!=menuacut) {
					displaya('contenido'+menuacut, 'none');
					mover(1, 'gallery', 290);
					transparenta('txt'+menuacut, 0);
					estirar(0, 'txt'+menuacut, 0);
					
					menuacut=cual;
					t=25;
					for(trans=0, t+=25; trans<=100; trans+=2,t+=25) {
						setTimeout("transparenta('gallery', "+trans+")", t);
					}
				}
		
			} else {
				if(cual!=menuacut) {
	
				;
					mover(1, 'gallery', 290);
					setTimeout("document.getElementById('txt"+menuacut+"').style.overflow='hidden'",0);
					for(trans=100, tiempo=25; trans>=0; trans-=5,tiempo+=25) {
						setTimeout("transparenta('txt"+menuacut+"', "+trans+")", tiempo);
					}
					for(alto=620, tiempo=25; alto>=0; alto-=20, tiempo+=25) {
						setTimeout("estirar(0, 'txt"+menuacut+"', "+alto+")", tiempo);
					}
	
					ti=tiempo;
					for(trans=100,tiempo+=25; trans>=0; trans-=5, tiempo+=50) {
						setTimeout("transparenta('contenido"+menuacut+"', "+trans+")", tiempo);
					}
					setTimeout("displaya('contenido"+menuacut+"', 'none')", tiempo);
		
					for(trans=0,ti+=25; trans<=100; trans+=5, ti+=50) {
						setTimeout("transparenta('gallery', "+trans+")", ti);
					}
	
					menuacut=cual;
					t=ti;
	
				}
			}
		
		} else if(menuacut==3) {
			if(navigator.appName=="Microsoft Internet Explorer") {
		
				if(cual!=menuacut) {
					displaya('contenido'+cual, 'block');
					transparenta('gallery', 0);
					mover(1, 'gallery', 15000);
					
					menuacut=cual;
					t=25;
					for(trans=0, t+=25; trans<=100; trans+=2,t+=25) {
						setTimeout("transparenta('txt"+cual+"', "+trans+")", t);
					}
					for(alto=0, tiempo=100; alto<=620; alto+=10, tiempo+=25) {
					
						setTimeout("estirar(0, 'txt"+cual+"', "+alto+")", tiempo);
					
					}
					setTimeout("document.getElementById('txt"+cual+"').style.overflow='auto'",tiempo);
				}
		
			} else {
				if(cual!=menuacut) {
	
				
					for(trans=100, tiempo=25; trans>=0; trans-=5,tiempo+=25) {
						setTimeout("transparenta('gallery', "+trans+")", tiempo);
					}
					setTimeout("displaya('contenido"+cual+"', 'block')", tiempo);
					setTimeout("mover(1, 'gallery', 15000)", tiempo);
		
	
					menuacut=cual;
					ti=tiempo;
	
					for(trans=0,ti+=25; trans<=100; trans+=5, ti+=50) {
						setTimeout("transparenta('contenido"+cual+"', "+trans+")", ti);
					}
	
					menuacut=cual;
					t=ti;
	
					for(trans=0, ti+=25; trans<=100; trans+=2,ti+=25) {
						setTimeout("transparenta('txt"+cual+"', "+trans+")", ti);
					}
					for(alto=0, t+=100; alto<=620; alto+=10, t+=25) {
					
						setTimeout("estirar(0, 'txt"+cual+"', "+alto+")", t);
					
					}
					setTimeout("document.getElementById('txt"+cual+"').style.overflow='auto'",t);
				}
			}
		
		} else {
		
			if(navigator.appName=="Microsoft Internet Explorer") {
		
				if(cual!=menuacut) {
					displaya('contenido'+menuacut, 'none');
					displaya('contenido'+cual, 'block');
					transparenta('txt'+menuacut, 0);
					estirar(0, 'txt'+menuacut, 0);
					
					menuacut=cual;
					t=25;
					for(trans=0, t+=25; trans<=100; trans+=2,t+=25) {
						setTimeout("transparenta('txt"+cual+"', "+trans+")", t);
					}
					for(alto=0, tiempo=100; alto<=620; alto+=10, tiempo+=25) {
					
						setTimeout("estirar(0, 'txt"+cual+"', "+alto+")", tiempo);
					
					}
					setTimeout("document.getElementById('txt"+cual+"').style.overflow='auto'",tiempo);
				}
		
			} else {
				if(cual!=menuacut) {
				//	alert("cual "+cual+" , activo "+menuacut+".");
					displaya('contenido'+cual, 'block');
				
					setTimeout("document.getElementById('txt"+menuacut+"').style.overflow='hidden'", 0);
					for(trans=100, tiempo=25; trans>=0; trans-=5,tiempo+=25) {
						setTimeout("transparenta('txt"+menuacut+"', "+trans+")", tiempo);
					}
					for(alto=620, tiempo=25; alto>=0; alto-=20, tiempo+=25) {
						setTimeout("estirar(0, 'txt"+menuacut+"', "+alto+")", tiempo);
					}
	
					ti=tiempo;
					for(trans=100,tiempo+=25; trans>=0; trans-=5, tiempo+=50) {
						setTimeout("transparenta('contenido"+menuacut+"', "+trans+")", tiempo);
					}
					setTimeout("displaya('contenido"+menuacut+"', 'none')", tiempo);
		
					if(cual==1) { img=""; } else { img=cual; }
		
					for(trans=0,ti+=25; trans<=100; trans+=5, ti+=50) {
						setTimeout("transparenta('contenido"+cual+"', "+trans+")", ti);
					}
	
					menuacut=cual;
					t=ti;
	
					for(trans=0, ti+=25; trans<=100; trans+=2,ti+=25) {
						setTimeout("transparenta('txt"+cual+"', "+trans+")", ti);
					}
					for(alto=0, t+=100; alto<=620; alto+=10, t+=25) {
					
						setTimeout("estirar(0, 'txt"+cual+"', "+alto+")", t);
					
					}
					setTimeout("document.getElementById('txt"+cual+"').style.overflow='auto'", t);
				}
			}
		}
	}
}


function txtinicio() {

	displaya('contenido1', 'block');
	for(trans=0, tiempo=25; trans<=100; trans+=10,tiempo+=25) {
		setTimeout("transparenta('contenido1', "+trans+")", tiempo);
	}
	for(trans=0, tiemp=tiempo+25; trans<=100; trans+=10,tiempo+=25) {
		setTimeout("transparenta('txt1', "+trans+")", tiempo);
	}


	for(alto=0, tiemp=tiempo+25; alto<=620; alto+=10, tiempo+=25) {
	
		setTimeout("estirar(0, 'txt1', "+alto+")", tiempo);
	
	}
}

function menuinicio() {
	$('#menu').show(1500);
}


function sacaCargando() {

	for(trans=95, tiempo=25;trans>=0; trans-=5,tiempo+=25) {
	
		setTimeout("transparenta('cargando', "+trans+")",tiempo);
	
	}
	
	setTimeout("displaya('cargando', 'none')", tiempo);
}

function compEmTel(valor) {

	if(valor=="Email") { valor2="Telefono"; } else { valor2="Email"; }

	document.getElementById("o"+valor2).style.color = "#535353";
	document.getElementById("cmp"+valor2).disabled = "disabled";
	document.getElementById("cmp"+valor2).value = "";
	document.getElementById("o"+valor).style.color = "white";
	document.getElementById("cmp"+valor).removeAttribute("disabled");
	document.getElementById("cmp"+valor).focus();
	document.getElementById("cmp"+valor).select();

}

function enviarContacto() {

	var nombre = document.getElementById("cmpnombre");
	var email = document.getElementById("cmpEmail");
	var telefono = document.getElementById("cmpTelefono");
	var consulta = document.getElementById("cmpconsulta");


	if(nombre.value.length>2 && consulta.value.length>12) {
	
			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email.value)) {
				var emailComprobado=1;
			} else {
				var emailComprobado=0;
			}
			
			if(emailComprobado==1 && email.value.length>4 && telefono.value.length>8 && !isNaN(telefono.value)) {
				document.getElementById("cajaContacto").innerHTML="<img src='img/cargando3.gif' border=0 style='vertical-align: middle; margin-right : 10px'> Enviando...";
				setTimeout("cargarContenidoPOST('contacto.php', 'nombre|Email|Telefono|consulta', 'Contacto')", 2000);
			} else if(telefono.value.length<=8 || isNaN(telefono.value)) {
				alert('Por favor, introduza un número de teléfono válido.');
				telefono.focus();
				telefono.select();
			} else {
				alert('Por favor, introduza unha dirección de email válida.');
				email.focus();
				email.select();
			}

	
	} else if(nombre.value.length<=2) {
		alert("Por favor, introduza o seu nome para dirixirnos a vostede.");
		nombre.focus();
		nombre.select();
	} else if(consulta.value.length<=12) {
		alert("Por favor, introduza unha consulta. Debe conter alomenos 12 caracteres.");
		consulta.focus();
		consulta.select();
	}
}



function enviarContacto2() {

	var nombre = document.getElementById("cmpnombre2");
	var asunto = document.getElementById("cmpasunto2");
	var consulta = document.getElementById("cmpconsulta2");


	if(nombre.value.length>2 && asunto.value.length>3 && consulta.value.length>12) {
	
		document.getElementById("cajaContacto2").innerHTML="<img src='img/cargando2.gif' border=0 style='vertical-align: middle; margin-right : 10px'> Enviando...";
		setTimeout("cargarContenidoPOST('contacto2.php', 'nombre2|asunto2|consulta2', 'Contacto2')", 2000);
			
	
	} else if(nombre.value.length<=2) {
		alert("Por favor, introduzca su nombre para dirigirnos a usted.");
		nombre.focus();
		nombre.select();
	} else if(asunto.value.length<=3) {
		alert("Por favor, introduzca un asunto. Debe contener al menos 3 caracteres.");
		asunto.focus();
		asunto.select();
	} else if(consulta.value.length<=12) {
		alert("Por favor, introduzca una consulta. Debe contener al menos 12 caracteres.");
		consulta.focus();
		consulta.select();
	}
}

function muestracont() {

	cargarContenido('cnt.php', 'capaContacto');

}
function muestracont2() {

	cargarContenido('cnt2.php', 'capaContacto2');

}



function sigueme(e) {
	var x = (document.layers || !document.all)? e.pageX : event.x+document.body.scrollLeft;
	var y = (document.layers || !document.all)? e.pageY : event.y+document.body.scrollTop;
	var x2 = x + 15;
	var y2 = y + 15;
	
	document.getElementById('siguelo').style.left=''+x2+'px';
	document.getElementById('siguelo').style.top=''+y2+'px';
	
	return true
}

function sigueme2(e) {
	var x = (document.layers || !document.all)? e.pageX : event.x+document.body.scrollLeft;
	var y = (document.layers || !document.all)? e.pageY : event.y+document.body.scrollTop;
	var x2 = x + 25;
	var y2 = y - 85;
	
	document.getElementById('siguelo').style.left=''+x2+'px';
	document.getElementById('siguelo').style.top=''+y2+'px';
	
	return true
}


function muestrame(texto) {

	document.onmousemove = sigueme;
	
	document.getElementById('siguelo').innerHTML=texto;
	
	document.getElementById('siguelo').style.display='block';
	if (document.layers) document.captureEvents(Event.MOUSEMOVE);
}


function muestrame2(texto) {

	document.onmousemove = sigueme2;
	
	document.getElementById('siguelo').innerHTML=texto;
	
	document.getElementById('siguelo').style.display='block';
	if (document.layers) document.captureEvents(Event.MOUSEMOVE);
}


function quitame() {
	document.getElementById('siguelo').style.display='none';
}


function entrar() {

	var pass = document.getElementById("cmppassword");
	if(pass.value == "") { alert('Por favor, introduce una contraseña'); pass.focus(); }
	else {
		
		cargarContenidoPOST('admin/entrar.php', 'password', 'pass');
	
	}

}


function guardaMarquesina() {

	if(document.frmcons.mensaje.value=="") {
		alert("Escriba un texto para la marquesina");
		document.frmcons.mensaje.focus();
	} else {
		cargarContenidoPOST('admin/guardar.php', 'mensaje', 'botonguardar');
	}

}

function cambiarContrasena() {

	if(document.frmpass.passa.value=="" || document.frmpass.passn.value=="") {
		alert("Introduce la contraseña actual y la nueva contraseña para continuar");
		document.frmpass.passa.focus();
	} else {
		if(hex_md5(document.frmpass.passa.value)===document.frmpass.passc.value) {
			cargarContenidoPOST('admin/pass.php', 'passa|passn', 'botonpass');
		} else {
			alert("La contraseña actual no es correcta");
		}
	}

}
