// Gallery Hide from Flash...
function winGalleryHide () {
	$(".win_gallery").fadeOut(500);
	$("#body_off").slideUp("slow");
};

// Gallery Hide from Flash...
function winFormFriendHide() {
	$(".win_form_friend").fadeOut(500);
	$("#body_off").slideUp("slow");
};

function winFormFriendHide2() {
	$(".win_form_friend2").fadeOut(500);
	$("#body_off").slideUp("slow");
}

$(document).ready(function() {
	// alto beta
	var alphaH = $("#alpha").height() + 31;  //(20 padding-top + 20 padding-bottom de alpha) - (5 padding-top + 5 padding-bottom de beta) + 1 porque si
	if(alphaH > 510){
		$(".no-front #beta").css('height',alphaH);
	}
	
	// Win - Ventana idioma
	$("#df_b_lng").click(function () {
		$("#win_lng").slideToggle(300);
		return false;
	});
	
	// Ventana modificar reservas
	$("#df_edit_reserva").click(function () {
		$(".reserva").slideToggle(300);
		$(this).toggleClass("down");
		return false;
	});
	
	// Win - Ventana compartir
	$("#df_b_comp").click(function () {
		$("#win_comp").slideToggle(300);
		return false;
	});
	
	
	// RESERVA YA! - Home
	$("#df_oferta").click(function () {
		$("#home_bookbox").slideToggle(300);
		return false;
	});
	
	
	// Menu desplegable
	$(".itemSup").click(function () {
		$(this).next(".collapsed").slideToggle(300);
		return false;
	});
	
	
	// Rates conditions y mas info
	$(".masInfo").click(
		function() {
			$(this).prev(".win").fadeIn(200);	
			return false;
		}	   
	);
	
	
	// Info Room
	$("p .info_room").click(
		function() {
			$(this).parent().prev(".win").fadeIn(200);
			return false;
		}	   
	);
	
	// RV STEP 2
	// More Info
	$(".more_info").click(
		function() {
			$(this).prevAll(".win").fadeIn(200);
			return false;
		}	   
	);
	
	
	// Ver opciones extras
	$(".extra").change(function () {
		$(".selecTools").toggle();
		return false;
	});
	
	
	// VEr grafica
	$(".df_list_link_grafica").click(function () {
		$(".graficaBlock").slideToggle(300);
		return false;
	});
	
	
	
	// Body OFF
	if ( $("#body_off").length > 0 ) {
		$("#body_off").css({'width': $(document).width()});
		$("#body_off").css({'height': $(document).height()});	
	}
	// Window Resize...
	// gallery
	if ( $(".win_gallery").length > 0 ) {
		$(window).resize(function(){
			var w = $(".win_gallery").width()/2;
			var l = $(window).width()/2-w;
			$(".win_gallery").css({'left': l});
			$("#body_off").css({'width': $(window).width()});
			$("#body_off").css({'height': $(document).height()});
			
		});
		$("#body_off").click(function(){
			$(".win_gallery").fadeOut(500);
			$("#body_off").slideUp("slow");
		});
	}
	
	// Window Resize...
	// send
	if ( $(".win_form_friend").length > 0 ) {
		$(window).resize(function(){
			var w = $(".win_form_friend").width()/2;
			var l = $(window).width()/2-w;
			$(".win_form_friend").css({'left': l});
			$("#body_off").css({'width': $(window).width()});
			$("#body_off").css({'height': $(document).height()});
			
		});
		$("#body_off").click(function(){
			$(".win_form_friend").fadeOut(500);
			$("#body_off").slideUp("slow");
		});
	}
	if ( $(".win_form_friend2").length > 0 ) {
		$("#body_off").click(function(){
			$(".win_form_friend2").fadeOut(500);
			$("#body_off").slideUp("slow");
		});
	}
	
	// loading
	if ( $("#win_loading").length > 0 ) {
		$(window).resize(function(){
			$("#body_off").css({'width': $(window).width()});
			$("#body_off").css({'height': $(document).height()});
		});
	}
	
	// Cerrar la ventana send friend
	$(".win_form_friend .close").click(
		 function () { 
			winFormFriendHide();
		  }
	);
	$(".win_form_friend2 .close").click(
		 function () { 
			winFormFriendHide2();
		  }
	);
	
	
	// Cerrar las ventanas
	$(".win .close").click(
		function() {
			$(this).parent().parent(".win").fadeOut(150);
			return false;
		}
	);
	
	// RV STEP 3
	$("#rv_b_send_passw").toggle(
	  function () { 
		$("#send_password").slideDown(500);
		return false;
	  },
	  function () {		  
		$("#send_password").hide();
		return false;
	  }
	);
	
	// RV GALLERY LISTADO
	$(".df_list_link_gallery").click(function () {
		/*var vars = ($(this).attr("id")).split("_");
		$('#galleryFlash').attr("data","/i/gallery.swf?dir=/&type=php&ht="+ vars[0] +"&lng="+ vars[1]);*/
		var t = $(this).position();
		var w = $(".win_gallery").width()/2;
		var l = $(window).width()/2-w;
		if(t.top < 400){
			  $(".win_gallery").css({'top' : t.top-250 });
		}else {
			  $(".win_gallery").css({'top' : t.top-400 });
		}
		$(".win_gallery").css({'left': l});
		$(".win_gallery").fadeIn(500);
		$("#body_off").slideDown("slow");
		return false;
	});
	// RV GALLERY HOTEL
	$(".df_link_gallery").click(function () {
		var t = $(this).position();
		var w = $(".win_gallery").width()/2;
		var l = $(window).width()/2-w;
		/*if(t.top < 400){
			  $(".win_gallery").css({'top' : t.top-250 });
		}else {
			  $(".win_gallery").css({'top' : t.top-400 });
		}*/
		
		$(".win_gallery").css({'top' : 175 });
		
		$(".win_gallery").css({'left': l});
		$(".win_gallery").fadeIn(500);
		$("#body_off").slideDown("slow");
		return false;
	});
	
	// SEND FRIEND HOTEL
	$(".df_sendFriend").click(function () {
		 $("html").animate({ scrollTop: 0 }, "slow");

		var t = $(this).position();
		var w = $(".win_form_friend").width()/2;
		var l = $(window).width()/2-w;
		if(t.top < 400){
			  $(".win_form_friend").css({'top' : t.top-250 });
			  $(".win_form_friend2").css({'top' : t.top-250 });
		}else {
			  $(".win_form_friend").css({'top' : t.top-400 });
			  $(".win_form_friend2").css({'top' : t.top-400 });
		}
		$(".win_form_friend").css({'left': l});
		$(".win_form_friend2").css({'left': l});
		$(".win_form_friend").fadeIn(500);
		$("#body_off").slideDown("slow");
		return false;
	});
	
	/*$("#rv_b1-1").click(function () {
		$("#step1-1").slideUp(1000, show1_2);
		function show1_2() {
		  $("#step1-2").slideDown(1000);
		  $("#info1-2").slideDown(1000);	
		}
		return false;
	});*/
	$("#rv_b1-1-nodisp").click(function () {
		$("#calendars").slideDown(500);
		$("#other_hotels").slideDown(500);
		return false;
	});	
			
	/* SLIDESHOW */

	jQuery(function($) {
	var timer;
	function button1_click(event)
	{
		$(".slide").css("visibility","hidden");
		$("#image1").css("visibility","visible");
		$("#image1").css("opacity","0");
		$("#image1").animate({"opacity":1},300, "linear", null);
		$("ul.buttons li").removeClass("active");
		$("#image1").animate({"opacity":1},300, "linear", null);
		$("#button1").addClass("active");
		clearTimeout(timer);
		timer = setTimeout(eval("button2_click"),"5000");
		$("#image1").animate({"opacity":1},300, "linear", null);
	}
	
	function button2_click(event)
	{
		$(".slide").css("visibility","hidden");
		$("#image2").css("visibility","visible");
		$("#image2").css("opacity","0");
		$("#image2").animate({"opacity":1},300, "linear", null);
		$("ul.buttons li").removeClass("active");
		$("#image2").animate({"opacity":1},300, "linear", null);
		$("#button2").addClass("active");
		clearTimeout(timer);
		timer = setTimeout(eval("button3_click"),"5000");
		$("#image2").animate({"opacity":1},300, "linear", null);
	}
	
	function button3_click(event)
	{
		$(".slide").css("visibility","hidden");
		$("#image3").css("visibility","visible");
		$("#image3").css("opacity","0");
		$("#image3").animate({"opacity":1},300, "linear", null);
		$("ul.buttons li").removeClass("active");
		$("#image3").animate({"opacity":1},300, "linear", null);
		$("#button3").addClass("active");
		clearTimeout(timer);
		timer = setTimeout(eval("button4_click"),"5000");
		$("#image3").animate({"opacity":1},300, "linear", null);
	}
	
	function button4_click(event)
	{
		$(".slide").css("visibility","hidden");
		$("#image4").css("visibility","visible");
		$("#image4").css("opacity","0");
		$("#image4").animate({"opacity":1},300, "linear", null);
		$("ul.buttons li").removeClass("active");
		$("#image4").animate({"opacity":1},300, "linear", null);
		$("#button4").addClass("active");
		clearTimeout(timer);
		timer = setTimeout(eval("button5_click"),"5000");
		$("#image4").animate({"opacity":1},300, "linear", null);
	}
	
	function button5_click(event)
	{
		$(".slide").css("visibility","hidden");
		$("#image5").css("visibility","visible");
		$("#image5").css("opacity","0");
		$("#image5").animate({"opacity":1},300, "linear", null);
		$("ul.buttons li").removeClass("active");
		$("#image5").animate({"opacity":1},300, "linear", null);
		$("#button5").addClass("active");
		clearTimeout(timer);
		timer = setTimeout(eval("button1_click"),"5000");
		$("#image5").animate({"opacity":1},300, "linear", null);
	}
	
	function OnLoad(event)
	{
		clearTimeout(timer);
		timer = setTimeout(eval("button2_click"),"5000");
	}
	
	$('#button1').bind('click', button1_click);
	
	$('#button2').bind('click', button2_click);
	
	$('#button3').bind('click', button3_click);
	
	$('#button4').bind('click', button4_click);
	
	$('#button5').bind('click', button5_click);
	
	OnLoad();
	
	});
	
	
	
	// Browser detection
	// Internet Explorer
	var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);
	//Imagen hover
	if(!ie6){
		$("ul.xxxxxx li").hover(function() {
		$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({
				marginTop: '-25px', /* The next 4 lines will vertically align this image */ 
				marginLeft: '-25px',
				top: '50%',
				left: '50%',
				width: '174px', /* Set new width */
				height: '174px', /* Set new height */
				padding: '20px'
			}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	
		} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				marginTop: '0', /* Set alignment back to default */
				marginLeft: '0',
				top: '0',
				left: '0',
				width: '160px', /* Set width back to default */
				height: '150px', /* Set height back to default */
				padding: '5px'
			}, 400);
		});
	}else{
		$("ul.xxxxxx li").hover(function() {
		$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({				
				opacity: 0.7
			}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	
		} , function() {
		$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				opacity: 1
			}, 400);
		});
	}
	
	$("#grupos-eventos #alpha .datepicker").datepicker({
		showOtherMonths: true,
		showOn: 'button',
		buttonImage: 'i/df_ico_calendar1.gif',
		buttonImageOnly: true,
		regional:'es',
		showAnim: "slideDown"
	});
	
	
	$(".breakdown .datepicker").datepicker({
		showOtherMonths: true,
		showOn: 'button',
		buttonImage: 'i/df_ico_calendar1.gif',
		buttonImageOnly: true,
		regional:'es',
		showAnim: "slideDown"
	});
	
	
	
});
