﻿/*** FUNCIONES***/

	// POSICIONES (footer)
	$(window).resize(function() {
		posiciones();
	}); 

	//BOTONES CUADRO OFERTAS
	function ofDer(of,id,cc,hh) {
		$("#oferta_list").fadeOut(1000, function () {
			$("#oferta_list").load("caofact.php?oferta="+of+"&idioma="+id+"&a=s&c="+cc+"&h="+hh, function() {
				$("#oferta_list").fadeIn(1000);
			});
		});
	}
	function ofIzq(of,id,cc,hh) {
		$("#oferta_list").fadeOut(1000, function () {
			$("#oferta_list").load("caofact.php?oferta="+of+"&idioma="+id+"&a=a&c="+cc+"&h="+hh, function() {
				$("#oferta_list").fadeIn(1000);
			});
		});
	}

	//POSICIONAR FOOTER ABAJO
	function posiciones() {
		alto = $(window).height();
		if (footer_prensa == "no") {
			if (cuerpo < alto) {
				$("footer").addClass("topper");
				$("footer").css("position","absolute");
				$("footer").css("top",alto-footer+"px");
			} else {
				$("footer").removeClass("top");
				$("footer").css("bottom","0");
				$("footer").css("position","relative");
				$("footer").css("top","0");
			}
		} else {
				$("footer").css("position","relative");
				$("footer").css("top","0");
		}
	}


$(document).ready(function() {
	
	footer = $("footer").height();
	hom = $(".home").height();
	header = $("header").height();
	cuerpo = $("body").height();
	posiciones();
	
	$(".oferta").hide();
	$(".oferta").fadeIn(1000);

// CUADRO MOSTRAR IDIOMAS	
	$('#idiomas a').click(function() {
	  $('#langs').fadeToggle('slow', function() {
		if( $('#langs').is(":visible") ) {
			$('#idiomas a').addClass('desplegado');
		} else {
			$('#idiomas a').removeClass('desplegado');			
		}
	  });
	});	
	
	
//  SCRIPT QUE MUESTRA EL CUADRO CON LA INFORMACIÓN DE LA HABITACIÓN AL HACER CLIC EN LA PÁGINA DE "RESERVAS"	
	$('a.ventanapop').click(function(e){
		e.preventDefault();
		idroom = $(this).attr('data-idroom');
		$('#overlay').fadeIn('fast',function(){
			$("#window_content").load("info_reserva.php?id="+idroom, function() {
					$('#box').fadeIn().animate({'top':'30px'},1500, 'easeOutElastic');
			});
			
		});
	});


// MUESTRA CUADRO DE LA NEWSLETTER
	$('a.newsletter').click(function(e){
		e.preventDefault();
		$('#overlay').fadeIn('fast',function(){
			$("#window_content").load("inc.newsletter.php", function() {
					$('#box').fadeIn().animate({'top':'30px'},1500, 'easeOutElastic');
			});
			
		});
	});
	

// MUESTRA CUADRO DEL AVISO LEGAL (footer)
	$('a.avisolegal').click(function(e){
		e.preventDefault();
		$('#overlay').fadeIn('fast',function(){
			$("#window_content").load("aviso_legal.php", function() {
					$('#box').fadeIn().animate({'top':'30px'},1500, 'easeOutElastic');
			});
			
		});
	});
	
// MUESTRA CUADRO DE LOS REGALOS
	$('.regal_exp a').click(function(e){
		e.preventDefault();
		$('#overlay').fadeIn('fast',function(){
			$('#box2').fadeIn().animate({'top':'30px'},1500, 'easeOutElastic');
		});
	});
	
// CERRAR CAJA FLOTANTE CLICANDO EN LA "X"
	$('#boxclose').click(function(e){
		e.preventDefault();		
		$('#box').animate({'top':'-700px'},1500, 'easeInBack', function(){
			$("#window_content").html("");
			$('#box').hide();
			$('#overlay').fadeOut('fast');
		});
	});
	
// CERRAR CAJA FLOTANTE CLICANDO EN LA "X" BOX2
	$('#boxclose2').click(function(e){
		e.preventDefault();		
		$('#box2').animate({'top':'-700px'},1500, 'easeInBack', function(){
			$('#box2').hide();
			$('#overlay').fadeOut('fast');
		});
	});

// MOSTRAR CREDITOS EN FOOTER
	$('a#creditos_box').click(function(e){
		e.preventDefault();		
			$("ul#footer_links").fadeOut("2000");
			$("ul#creditos_link").fadeIn("2000");
	});
		$('#creditos_link a.cerrar').click(function(e){
		e.preventDefault();		
			$("ul#creditos_link").fadeOut("2000");
			$("ul#footer_links").fadeIn("2000");
	});
	
	
// EFECTO HOVER EN MINIATURAS SECCIÓN 'HABITACIONES'
	$(".galeria li").hover(
		function () {
			$(this).addClass("hover");
				$(this).animate({
					top: '-=5',
					}, 100);
		}, 
		function () {
			$(this).removeClass("hover");
			$(this).animate({
					top: '0',
					}, 100);
		}
	);
	

// SI HAY MÁS DE DOS FOTOS EN ALGUN VISOR, CREA UN 'slide' AUTOMÁTICO
	$(function(){
		var cantidadIMG = $('#visor img').length;
		if (cantidadIMG > 1) {
			$('#visor img:gt(0)').hide();
			setInterval(function(){$('#visor :first-child').fadeOut(3000).next('img').show().end().appendTo('#visor');}, 5000);
		}
	});


//BANNER HOME
		$("#banner_home").hover(function(){
			$(this).animate({"height": "335"}, "normal");
		}, function() {
			$(this).animate({"height": "128"}, "normal");
		});
		
	
//CAMBIAMOS OPACIDAD AL SITUAR EL CURSOR EN EL MENÚ
	$("nav ul").hover(
		function () {
				$(".contener").animate({
					opacity: '0.4',
					}, 400);
				$("#backstretch").animate({
					opacity: '0.6',
					}, 400);
		}, 
		function () {
			$(".contener, #backstretch").animate({
					opacity: '1',
					}, 400);
					$("#backstretch").animate({
					opacity: '1',
					}, 400);
		}
	);

// DESPLEGAR CARTA (EN RESTAURANTE)	
	$(".carta table tr:nth-child(even)").addClass("even");
		$("h5.radius a").click(function(){
			$(".carta table").fadeOut(200);
			if( $(this).parents().next(".carta table").is(":visible") ) {
				$("h5 a").removeClass("desplegado");
			}
			else {
				// element is not visible
				$("h5 a").removeClass("desplegado");
				$(this).addClass("desplegado");
				$(this).parents().next(".carta table").delay("200").fadeIn(300);
			}
			return false;
		});
		
		
		$("a.fancy").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'titlePosition'	: 'inside'			
		});
		
		
		
		
// MENÚ Y SUS EFECTOS
	$('#sdt_menu > li').bind('mouseenter',function(){
		var $elem = $(this);
		$elem.find('img')
			 .stop(true)
			 .animate({
				'width':'160px',
				'height':'160px',
				'left':'0px'
			 },400,'easeOutBack')
			 .andSelf()
			 .find('.sdt_wrap')
			 .stop(true)
			 .animate({'top':'97px'},500,'easeOutElastic')
			 .andSelf()
			 .find('.sdt_active')
			 .stop(true)
			 .animate({'height':'160px'},300,'easeOutBack',function(){
			var $sub_menu = $elem.find('.sdt_box');
			if($sub_menu.length){
				var left = '160px';
				if($elem.parent().children().length == $elem.index()+1)
					left = '-160px';
				$sub_menu.show().animate({'left':left},200);
			}	
		});
	}).bind('mouseleave',function(){
		var $elem = $(this);
		var $sub_menu = $elem.find('.sdt_box');
		if($sub_menu.length)
			$sub_menu.hide().css('left','0px');
		
		$elem.find('.sdt_active')
			 .stop(true)
			 .animate({'height':'0px'},300)
			 .andSelf().find('img')
			 .stop(true)
			 .animate({
				'width':'0px',
				'height':'0px',
				'left':'85px'},400)
			 .andSelf()
			 .find('.sdt_wrap')
			 .stop(true)
			 .animate({'top':'25px'},500);
	});
	
	
	
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		
		function desaparece() {
			var $elem = $("#sdt_menu > li");
			var $sub_menu = $elem.find('.sdt_box');
			if($sub_menu.length)
				$sub_menu.hide().css('left','0px');
			
			$elem.find('.sdt_active')
				 .stop(true)
				 .animate({'height':'0px'},300)
				 .andSelf().find('img')
				 .stop(true)
				 .animate({
					'width':'0px',
					'height':'0px',
					'left':'85px'},400)
				 .andSelf()
				 .find('.sdt_wrap')
				 .stop(true)
				 .animate({'top':'25px'},500);
		}
		
			$("#sdt_menu > li").bind('touchstart', function(){
				desaparece();
				var $elem = $(this);
				$elem.find('img')
				.stop(true)
				.animate({
				'width':'160px',
				'height':'160px',
				'left':'0px'
				},400,'easeOutBack')
				.andSelf()
				.find('.sdt_wrap')
				.stop(true)
				.animate({'top':'97px'},500,'easeOutElastic')
				.andSelf()
				.find('.sdt_active')
				.stop(true)
				.animate({'height':'160px'},300,'easeOutBack',function(){
				var $sub_menu = $elem.find('.sdt_box');
				if($sub_menu.length){
				var left = '160px';
				if($elem.parent().children().length == $elem.index()+1)
					left = '-160px';
				$sub_menu.show().animate({'left':left},200);
				}	
				})
				//return false;
    		});
	
		
		
	}
	
});
