$(function() {
	
	// Daily Events Testing
	$('#events-daily tr').each(function() {
		$('td:nth-child(1n+5)').addClass('events-right');
	});
	$('#cal-links tr td:nth-child(1)').addClass('cal-prev-month');
	$('#cal-links tr td:nth-child(4)').addClass('cal-next-month');
	$('a.daily-event').click(function(event) {
		event.preventDefault();
		var x = event.pageX;
		var y = event.pageY;
		if (x >= 775) { x = x-500 }
		else if (($(document).width() <= 1100) && (x >= 570)) { x = x-500 }
		var overlay = $('<div />').attr('id','events-overlay').css({width:$('.events-daily').width(),height:$('.events-daily').height(),opacity:0});
		var eventDescription = $('<div />').attr('id','event-description').css({
			'left': x,
			'top': y
		});
		overlay.appendTo('.events-daily');
		eventDescription.appendTo('.events-daily');
		var temp = this.rel.split(':');
		$.get('/direct/events-calendar-ajax-test.php', { permalink: temp[0], rssfeed: temp[1], lang: LANG, op: 'details' },function(data) { 
			$('#event-description').html((data));
		});
		$('.share-link').live('click',function(event) {
			event.preventDefault();
			$('.share-panel').hide();
			$(this).parents('#event-description').find('.share-panel').css('display','inline');
		});
		$('.share-close').live('click',function(event){
			event.preventDefault();
			$(this).parents('#event-description').find('.share-panel').slideUp('fast');
		});
	});
	$('#events-overlay').live('click',function() {
		$('#events-overlay').remove();
		$('#event-description').remove();							
	});
	$('.close-event').live('click',function() {
		$('#events-overlay').remove();
		$('#event-description').remove();
	});
	// End Daily Events Testing
	
    $('#package_type_dining').click(function(e) {
        $('#start_date,#end_date').removeClass('required')
        if ( this.checked ) 
            $('#capello_date').addClass('required')
        else
            $('#capello_date').addClass('required')
            
    });

    $('#package_type_romance').click(function(e) {
        $('#capello_date').removeClass('required')
        if ( this.checked ) {
            $('#start_date').addClass('required')
            $('#end_date').addClass('required')
        } else{
            $('#start_date').removeClass('required')
            $('#end_date').removeClass('required')
        }
            
    });
		
	// Booking Console Promo Fields Popup
	$("#promo-click a").click(function(){
		$("#extra-fields-wrapper").show();
		return false;
	});
	$("#extra-fields-close").click(function(){
		$("#extra-fields-wrapper").hide();
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$("#promo-click").addClass("selected-promo-click");
		} else {
			$("#promo-click").removeClass("selected-promo-click");
		}
		return false;
	});
	$("#promo-done-btn").click(function(){
		$("#extra-fields-wrapper").hide();
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$("#promo-click").addClass("selected-promo-click");
		} else {
			$("#promo-click").removeClass("selected-promo-click");
		}
		return false;
	});
	

	//decorating-game
	$("body.decorating-game #game").flash(
	{src:"/flash/decorating-game.swf",
	 width:914,
	 height:573,
	 wmode:"transparent",
	 quality:"high"},
	 {version:"8"});
	
	//DHR Flash in footer
	$("div#dhr").flash(
		{src:"http://www.destinationhotels.com/flash/branding/flash_logoDhr-white.swf?link=royalpalmshotel",
		width:250,
		height:25,
		wmode:"transparent",
		allowscriptaccess:"always",
		quality:"high"},
		{version:"8"});	

	// H1 sifr
	$('body:not("#tcooks", "#romantication") div#content h1').sifr(
		{ strSWF: '/flash/adobe-jenson-pro.swf', strColor: '#720a00', strLinkColor: '#720a00', strHoverColor: '#720a00', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=left&' },
		{ expressInstall: true }
	);
	
	$('#romantication div#content h1').sifr(
		{ strSWF: '/flash/p22-dearest-swash.swf', strColor: '#5b2209', strLinkColor: '#720a00', strHoverColor: '#720a00', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=center&' },
		{ expressInstall: true }
	);
	
	$("div#resort-video").flash(
		{src:"resort-video.swf",
		 width:640,
		 height:397,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
		 
	$("div#career-video").flash(
		{src:"hr-video.swf",
		 width:640,
		 height:397,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});		 
	
	$(".home #masthead").flash(
		{src:"/flash/home-masthead.swf",
		 width:960,
		 height:337,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/home-masthead.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	
	/*$("#romantic-masthead").flash(
		{src:"/flash/romance-masthead.swf",
		 width:960,
		 height:500,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/masthead.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	*/
	$("#romantic-masthead").flash(
		{src:"/romantication-master.swf",
		 width:960,
		 height:388,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});

	//Bing map
	var openFn=function(hash){
		hash.w.show();
		var difference = $(window).width() - $('#map-jqmodal').width();
		difference = difference / 2;
		$('#map-jqmodal').css({left:difference+275,top:$(window).scrollTop()+10});
		$('#map').msnMap({listView:true, hotelOnly: false});
		$("#cat-main:first").remove();
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$("#btn-map").each(function() {
		$('#map-jqmodal').jqm({trigger:'#btn-map', onShow: openFn, onHide: hideFn});
		$("#cat-main:first").remove();
	});

	//Floorplan Tab 
	
	$(".tab-trigger").each(function() {
		
		$(this).toggle(function() {
			$(this).parents(".section-room").find(".room-floorplan").slideDown();
			$(this).parents(".section-room").css('background-position','0 160px');
			$(this).html("Close Expanded View");
		},function() {
			$(this).parents(".section-room").find(".room-floorplan").slideUp();
			$(this).parents(".section-room").css('background-position','top');
			$(this).html("Floorplans");
		});
	});
	//Floorplan Modal
	$('.floorplan-trigger').each(function() {
			$(this).click(function(e) {
			e.preventDefault();			   
			var id = $(this).attr('id');
			switch(id){
				case 'valencia-casita':
					$("#valencia-casita-large").show();
					break;
				case 'montavista-terrace':
					$("#terrace-large").show();
					break;
				case 'designer-casita':
					$("#designer-casita-large").show();
					break;
				case 'montavista-suite':
					$("#montavista-suite-large").show();
					break;
				case 'alvadora-spa-suite':
					$("#alvadora-spa-suite-large").show();
					break;
				case 'alvadora-spa-villa':
					$("#alvadora-spa-villa-large").show();
					break;
				case 'camelback-villa':
					$("#camelback-villa-large").show();
					break;
				case 'honeymoon-villa':
					$("#honeymoon-villa-large").show();
					break;
				case 'presidential-villa':
					$("#presidential-villa-large").show();
					break;	
				}
				
				var difference = $(window).width() - $('#floorplan-container .floorplan img').width();
				difference = difference / 2;
				
				var hideFloorplan = function() {
					$("#floorplan-wrapper").hide();	
					$(".floorplan").hide();
					$(".jqmOverlay").hide();
				}
				$('#floorplan-wrapper').css({left:difference-325});
				$('#floorplan-wrapper').jqm({onHide:hideFloorplan,closeClass:'hide-floorplan'}).jqmShow();
		});
	});
	
	$('.inset-trigger').each(function() {
		
		
		$(this).click(function(e) {

			e.preventDefault();			   
			var id = $(this).attr('id');
			switch(id){
				case 'arizona-resort-accommodations':
					$("#arizona-resort-accommodations-large").show();
					break;
				case 'arizona-hotel-rooms':
					$("#arizona-hotel-rooms-large").show();
					break;
				case 'valencia-suite':
					$("#valencia-suite-large").show();
					break;
				case 'phoenix-deluxe-casita':
					$("#phoenix-deluxe-casita-large").show();
					break;
				case 'phoenix-designer-casitas':
					$("#phoenix-designer-casitas-large").show();
					break;
				case 'montavista-terrace':
					$("#montavista-terrace-large").show();
					break;
				case 'alvadora-spa-terrace':
					$("#alvadora-spa-terrace-large").show();
					break;
				case 'montavista-terrace-suites':
					$("#montavista-terrace-suites-large").show();
					break;
				case 'honeymoon-villa-inset':
					$("#honeymoon-villa-inset-large").show();
					break;
				case 'camelback-villa-inset':
					$("#camelback-villa-inset-large").show();
					break;
				case 'alvadora-spa-villa-inset':
					$("#alvadora-spa-villa-inset-large").show();
					break;
				case 'phoenix-hotel-suite':
					$("#phoenix-hotel-suite-large").show();
					break;
				}
				
				var difference = $(window).width() - $('#inset-container .inset img').width();
				difference = difference / 2;
				
				var hideFloorplan = function() {
					$("#inset-wrapper").hide();	
					$(".inset").hide();
					$(".jqmOverlay").hide();
				}
				
				$('#inset-wrapper').css({left:difference-275});
				$('#inset-wrapper').jqm({onHide:hideFloorplan,closeClass:'hide-inset'}).jqmShow();
				
		});
				
			
	});
	
	$("#wedding-album").flash(
		{src:"/flash/photo-gallery-weddings.swf",
		 width:500,
		 height:350,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/wedding_images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});

	$("#wedding-cakes").flash(
		{src:"/flash/photo-gallery-cake.swf",
		 width:500,
		 height:350,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/cake_images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});
        
     $("div#flash-signup-wrapper").flash(
        {src:"/flash/email-form.swf",
         width:236,
         height:415,
         wmode:"transparent",
         quality:"high"},
         {version:"9"},
            function(htmlOptions) {
                $(this).html($.fn.flash.transform(htmlOptions));
        });

	$("#photo-gallery").flash(
		{src:"/flash/photo-gallery.swf",
		 width:631,
		 height:484,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/resort_images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});

        
    /* Concierge Form boarding pass popup box. */
    
    $("#concierge-restrictions").hide();
    
    $("#print_pass").click(function(){
        var checked = $(this).attr("checked");
        if (checked) {
            $("#concierge-restrictions").css("position","absolute");
            $("#concierge-restrictions").css("bottom","39px");
            $("#concierge-restrictions").css("left","139px");
            $("#concierge-restrictions").show();
        }else{
            $("input#airline").val("");
            $("input#flight_reference").val("");
            $("input#alt_phone").val("");
            $("input#flight_provider").val("");
            $("input#reference_num").val("");
            $("input#pass_phone").val("");   
        }
    });
    
    $("#pass_submit").click(function(){
        var airline = $("input#flight_provider").val();
        var flight_reference = $("input#reference_num").val();
        var alt_phone = $("input#pass_phone").val();
        
        if(airline!='' && flight_reference!='' && alt_phone!=''){
            $("input#airline").val(airline);
            $("input#flight_reference").val(flight_reference);
            $("input#alt_phone").val(alt_phone);
            $("#concierge-restrictions").hide(); 
        }else{
            alert("All fields are required to print your boarding pass.");
            return false;   
        }
	});
    
	$("#pass_cancel").click(function(){
        $("#concierge-restrictions").hide(); 
        $("#print_pass").attr("checked",false);
    });
	
    /* Gift Cards Form */	
	$("#same_above").click(function(){
        var checked = $(this).attr("checked");
        if (checked) {
			$('#recipient_prefix').val($('#prefix').val());
			$('#recipient_first_name').val($('#first_name').val());
			$('#recipient_last_name').val($('#last_name').val());
			$('#recipient_email').val($('#email').val());
			$('#recipient_phone').val($('#phone').val());
			$('#recipient_address1').val($('#address1').val());
			$('#recipient_address2').val($('#address2').val());
			$('#recipient_city').val($('#city').val());
			$('#recipient_state').val($('#state').val());
			$('#recipient_state_other').val($('#state_other').val());
			$('#recipient_zip').val($('#zip').val());
        }else{
			$('#recipient_prefix,#recipient_first_name,#recipient_last_name,#recipient_email_address,#recipient_phone_number,#recipient_address1,#recipient_address2,#recipient_city,#recipient_state,#recipient_state_other,#recipient_zip').val('');
        }
    });

	$("#shipping-list input").click(function(){
		shipping = parseInt($(this).val(),10);
		amt = parseInt($('#other_amount').val(),10) || parseInt($('#gift_amount').val()) || 0;
		$('#total').val(amt+shipping);
    });
	
	$("#gift_amount, #other_amount").change(function(){
		shipping = parseInt($('#shipping-list input:checked').val(),10);
		amt = parseInt($('#other_amount').val(),10) || parseInt($('#gift_amount').val()) || 0;
		$('#total').val(amt+shipping);
    });
	
	$(".virtual-tour-link").each(function(){
		$(this).click(function(e){
			e.preventDefault();
			window.open(this.href, 'virtual_tour_popup', 'width=550,height=537,scrollbars=yes');
		});
	});


	$(".help-link").each(function(){
		$(".form-help").hide();
		$(this).toggle(function(){
			$(".form-help").show();
		}, function() {
			$(".form-help").hide();
		});
	});
	
	$("form#blog-comment").each(function(){
		var comment_form = $(this);
		comment_form.hide();
		$("#comment-btn a").click(function(){
			comment_form.show();
			$(this).remove();
		});
	});

	// Adds class on last boutique item
	 
	$(".boutique-item:last").each(function(){
		$(this).addClass("boutique-last");
	});

	// Timeline nav popup 
	$("#utility-sec-timeline a").each(function(){
		var openFntimeline=function(hash){
			hash.w.show();
			var difference = $(window).width() - $('#timeline-wrapper').width();
			difference = difference / 2;
			$('#timeline-wrapper').css({left:difference+275,top:$(window).scrollTop()+10});
		};
		$("#timeline-wrapper").jqm({trigger:this,onShow:openFntimeline});
	});
	$("#sitemap-utility-sec-timeline a").each(function(){
		var openFntimeline2=function(hash){
			hash.w.show();
			var difference = $(window).width() - $('#timeline-wrapper').width();
			difference = difference / 2;
			$('#timeline-wrapper').css({left:difference+275,top:$(window).scrollTop()+10});
		};
		$("#timeline-wrapper").jqm({trigger:this,onShow:openFntimeline2});
	});
    
    
    // Textarea character limit for Photo upload comments 
    $('textarea.maxlength').keyup(function(){
        var max = parseInt($(this).attr('maxlength'));
        if($(this).val().length > max){
            $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
        }
    });
    
    $('input.toggle-extras').click(function(){
        if($(this).is(':checked')){
            $('li.list-extra').each(function(){
                $(this).show();
            });
        }else{
            $('li.list-extra').each(function(){
                $(this).hide();
                $(this).children('input').attr('checked',false);
            });
        }   
    });
	
	// Photo blog popup
	$("#photo-blog-image-popup-wrapper").each(function(){
		var openPhotoPopup =function(hash){
			var imagelink = hash.t.id;
			$("#photo-blog-image-popup img").attr("src",imagelink);
			hash.w.show();
			//IE6 photo max width fix
			if(BROWSER=='msie6'){
				function ieFixImageSize() {
					var ieimagewidth = $("#photo-blog-image-popup img").width();
					if ( ieimagewidth > '600') {
						$("#photo-blog-image-popup img").css("width","600px");
					}
				}
				function ieTimer()
				{
					var t=setTimeout(ieFixImageSize,1);
				}
				ieTimer();
			}
			var difference = $(window).width() - $('#photo-blog-image-popup-wrapper').width();
			difference = difference / 2;
			$('#photo-blog-image-popup-wrapper').css({left:difference+275,top:$(window).scrollTop()+20});
		};
		var hidePhotoPopup =function(hash){
			hash.w.hide()
			hash.o.remove();
			$("#photo-blog-image-popup img").attr("src","").css("width","auto");;
		};
		$("#photo-blog-image-popup-wrapper").jqm({trigger:".photo-blog-large-link",onShow:openPhotoPopup,onHide: hidePhotoPopup});
	});
	
	// T. Cook's sidebar signup
	$("#push-email").each(function() {
		var defaultVal = $("#email").val();
		$("#email").click(function() {
			if ($(this).val() == defaultVal)
				$(this).val('');

		}); 
	});
	
	$("body.holiday div.menu-section:first").each(function() {
		//$(this).css("background-image", "none"); //removed temporarily ?
	});
	
	// Print Buttons
	$(".print-me").click(function() {
		window.print();
		return false;
	});
		
	//Connect Push
	$(document).ready(function(){
		if ($.cookie('connect-rp') != 'clicked-connect') {
			$.cookie('connect-rp', 'not-clicked');
			$("div#bottom-connect-with-outer-wrapper").show().animate({ bottom: 0 }, 500 );
			//alert($.cookie('connect-with'));
		}
	});
	
	$('div#bottom-connect-with-outer-wrapper a').click(function() {
		$("div#bottom-connect-with-outer-wrapper").animate({ bottom: -60 }, 200 ).hide();
		$.cookie('connect-rp', 'clicked-connect');
		//alert($.cookie('connect-with'));		
	});
	
	// Connect push fix for iOS devices - will need to modify if we change for android/palm
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' || (navigator.userAgent.indexOf('Android') != -1) ) {
		$("div#bottom-connect-with-outer-wrapper").css("position", "static");
	};

    
    // Restaurant Team Last item fix. restaurant/phoenix-az-restaurant-team.php
    $('div.meet-staff:last').addClass('last');
	
	// Romnatication Form
	$('#romantication-form').each(function(){
		$('#passport-to-romance, #via-capello-dining').hide();
		//$("input[name='package_type']").change(function(){
		$("input.change_type").click(function(){
			var packageType = $("input[name='package_type']:checked").val();
			switch(packageType) {
				case 'Passport to Romance':
					$('#via-capello-dining').hide();
					$('#passport-to-romance').show();
					break;
				case 'Via Cappello Dining':
					$('#passport-to-romance').hide();
					$('#via-capello-dining').show();
					break;
			}
		});
		$("input[name='passport_dinner_option']").click(function(){
			var dinnerOption = $("input[name='passport_dinner_option']:checked").attr('id');
			switch(dinnerOption) {
				case 'full_dinner_via_capello':
					$('#via-capello-dining').show();
					break;
				default:
					$('#via-capello-dining').hide();
					break;
			}
		});
										  
	});
	
	$('#mycarousel').jcarousel({
	scroll: 1,
	visible: 4,
	auto:4,
	wrap: "circular"
	});
	
	$('.set-flood-light').each(function(){
		URCHIN2 = typeof(pageTracker)=='undefined'?true:false;
		var axel = Math.random() + "";
		var a = axel * 10000000000000;
		var tag = '/'+$(this).attr('name').replace(/:/g,'/');
		$(this).click(function(e){
			var packageType = $(this).attr('rel');
			if (packageType == "juliet") {
				$('body').append('<iframe src="https://fls.doubleclick.net/activityi;src=2802564;type=julie873;cat=julie760;ord=' + a + '?" width="1" height="1" frameborder="0"></iframe>');
			} else if (packageType == "romeo") {
				$('body').append('<iframe src="https://fls.doubleclick.net/activityi;src=2802564;type=romeo213;cat=romeo631;ord=' + a + '?" width="1" height="1" frameborder="0"></iframe>');
			} else if (packageType == "stay-dine-unwind") {
				$('body').append('<iframe src="https://fls.doubleclick.net/activityi;src=2802564;type=sdust970;cat=sdust195;ord=' + a + '?" width="1" height="1" frameborder="0"></iframe>');
			}
			URCHIN2?urchinTracker(tag):pageTracker._trackPageview(tag);
			if(tag.indexOf("reservations")>0) {
				e.preventDefault();
				var l = URCHIN2?__utmLinkerUrl(this.href):pageTracker._getLinkerUrl(this.href);
				$(this).attr('target')=='_blank'?window.open(l,''):window.location=l;
			}			
		});
	});
	
    $(".jcarousel-lite").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		auto: 6000,
    	speed: 800,
		circular: false,
		btnGo:
    	["#photo-blog-wrapper .1"]
    });
	
});

function resizeSwf(size) {
	if ( size == 40 ) {
		$("div#flash-signup-wrapper").css("height","40px");
	} else {
		$("div#flash-signup-wrapper").css("height","415px");
	}
}

