$(function() {
		
	// 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;
	});
	

	//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") 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 }
	);
	
	$("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));
		});

	//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();
	});

	$("#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");
	});
	
	// 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');
	
});

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