//CAJETINES

function updateCajetin(){
		var numHab = document.getElementById('cajetin_numHabitaciones').value;
		updateCajetinHab(1, true);
		updateCajetinHab(2, numHab>1);
		updateCajetinHab(3, numHab>2);
		if(numHab==1) {
			document.getElementById("texto_habitacion1").style.display='none';
		} else {
			document.getElementById("texto_habitacion1").style.display='';
		}
}; 
	
function updateCajetinHab(numHab, show){
		if(show){
			
			document.getElementById('cajetin:hab'+numHab).style.display='';
			var numNinos = document.getElementById('cajetin_ninos'+numHab).value;
			 document.getElementById('cajetin:hab'+numHab+':edad1').style.display= (numNinos < 1 ?'none':'');
			 document.getElementById('cajetin:hab'+numHab+':edad2').style.display= (numNinos < 2?'none':'');	
			 document.getElementById('cajetin:hab'+numHab+':edad3').style.display= (numNinos < 3?'none':'');
		} else {
			document.getElementById('cajetin:hab'+numHab).style.display='none';
			document.getElementById('cajetin:hab'+numHab+':edad1').style.display='none';
			document.getElementById('cajetin:hab'+numHab+':edad2').style.display='none';
			document.getElementById('cajetin:hab'+numHab+':edad3').style.display='none';
		}
			
	};


// 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() {
	//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");
		});
	}

	//Cerrar la ventana send friend
	$(".win_form_friend .close").click(
		 function () { 
			winFormFriendHide();
		  }
	);
	$(".win_form_friend2 .close").click(
			 function () { 
				winFormFriendHide2();
			  }
		);
	//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;
	});
	
	$("#df_sendFriend1").click(function () {
		$("html").animate({ scrollTop: 0 }, "slow");
		$(this).parent().parent(".win").fadeOut(150);
		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 });
		}else {
			  $(".win_form_friend").css({'top' : t.top-400 });
		}
		$("#win_comp").hide();
		$(".win_form_friend").css({'left': l});
		$(".win_form_friend").fadeIn(500);
		$("#body_off").slideDown("slow");
		return false;
	});
	// 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;
	});
	
	
	// 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");
		});
	}
	
	// loading
	if ( $("#win_loading").length > 0 ) {
		$(window).resize(function(){
			$("#body_off").css({'width': $(window).width()});
			$("#body_off").css({'height': $(document).height()});
		});
	}
	
	// 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("_");
		showSWFPreview("/i/gallery.swf?dir=/&type=php&ht="+ vars[0] +"&lng="+ vars[1]);
		var t = $(this).offset();
        var w = $(".win_gallery").width()/2;
        var l = $(window).width()/2-w;
        if(t.top < 400){
              $(".win_gallery").css({'top' : t.top-0 });
        }else {
              $(".win_gallery").css({'top' : t.top-400 });
        }
        $(".win_gallery").css({'left': l});
       	$(".win_gallery").fadeIn(500);
        $("#body_off").slideDown("slow");
        return false;
  	});
	
	function showSWFPreview(currSWF){
		var isSelection = currSWF;
		var flashObjStr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="900" height="500" id="FlashID" title="Photos / Fotos">';
		flashObjStr = flashObjStr+'<param name="quality" value="high" />';
		flashObjStr = flashObjStr+'<param name="wmode" value="transparent" />';
		flashObjStr = flashObjStr+'<param name="swfversion" value="6.0.65.0" />';
		flashObjStr = flashObjStr+'	<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you donâ€™t want users to see the prompt. -->';
		flashObjStr = flashObjStr+'	<param name="expressinstall" value="/js/expressInstall.swf" />';
		flashObjStr = flashObjStr+'	<param name="salign" value="lt" />';
		flashObjStr = flashObjStr+'	<param name="movie" id="movie" value="'+isSelection+'"/>';
		flashObjStr = flashObjStr+'	<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->';
		flashObjStr = flashObjStr+'	<!--[if !IE]>-->';
		flashObjStr = flashObjStr+'	<object id = "galleryFlash" type="application/x-shockwave-flash" data="'+isSelection+'" width="900" height="500">';
		flashObjStr = flashObjStr+'		<!--<![endif]-->';
		flashObjStr = flashObjStr+'		<param name="quality" value="high" />';
		flashObjStr = flashObjStr+'		<param name="wmode" value="transparent" />';
		flashObjStr = flashObjStr+'		<param name="swfversion" value="6.0.65.0" />';
		flashObjStr = flashObjStr+'		<param name="expressinstall" value="/js/expressInstall.swf" />';
		flashObjStr = flashObjStr+'		<param name="salign" value="lt" />';
		flashObjStr = flashObjStr+'		<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->';
		flashObjStr = flashObjStr+'		<div>';
		flashObjStr = flashObjStr+'			<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>';
		flashObjStr = flashObjStr+'			<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>';
		flashObjStr = flashObjStr+'		</div>';
		flashObjStr = flashObjStr+'		<!--[if !IE]>-->';
		flashObjStr = flashObjStr+'	</object>';
		flashObjStr = flashObjStr+'	<!--<![endif]-->';
		flashObjStr = flashObjStr+'</object>';
		document.getElementById('win_gallery').innerHTML = flashObjStr;
	}
	
	// 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({'left': l});
		$(".win_gallery").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.imagenes 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.imagenes 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);
		});
	}
	

	
	$(".breakdown .datepicker").datepicker({
		showOtherMonths: true,
		showOn: 'button',
		buttonImage: '/i/df_ico_calendar1.gif',
		buttonImageOnly: true,
		regional:'es',
		showAnim: "slideDown"
	});

	// Colores Grid rv_01_2.html
	
	$('.TabbedPanelsTab').click(function () {
		var tab_n = $(this).attr('tabindex');
		switch (tab_n) {
			case "0":
			var tab_color = "#DCF4F5";
			break;
			case "1":
			var tab_color = "#DFF4E9";
			break;
			case "2":
			var tab_color = "#E3F5DD";
			break;
			case "3":
			var tab_color = "#E5F2E3";
			break;
			case "4":
			var tab_color = "#E8EFED";
			break;
			case "5":
			var tab_color = "#EAECF6";
			break;
		}
		$(this).css('border-bottom-color', tab_color);
		$(this).parent().next().find('.TabbedPanelsContent').css('background-color', tab_color);
		$(this).parent().next().find('.roomTable th.noBg').css({'background-color' : tab_color, 'border-top-color' : tab_color, 'border-left-color' : tab_color});
	});
	
	//Init
	$('.TabbedPanelsTab[tabindex|="0"]').css('background-color', '#DCF4F5');
	$('.TabbedPanelsTab[tabindex|="1"]').css('background-color', '#DFF4E9');
	$('.TabbedPanelsTab[tabindex|="2"]').css('background-color', '#E3F5DD');
	$('.TabbedPanelsTab[tabindex|="3"]').css('background-color', '#E5F2E3');
	$('.TabbedPanelsTab[tabindex|="4"]').css('background-color', '#E8EFED');
	$('.TabbedPanelsTab[tabindex|="5"]').css('background-color', '#EAECF6');
	
});
