(function() {

    window.resizeSwf = function( w, h ) {
	/*
	if ( window.console ) console.log(w)
	if ( window.console ) console.log(h)
	    */

	w+='px';
	h+='px';


	$('#specials-signup-wrap').css({width:w,height:h})

	if ( w == '566px' ) {
	    $('#specials-signup-wrap').css('overflow', 'visible');
	    $('#specials-signup').css('margin-left', '-20px');
	} else {
	    $('#specials-signup-wrap').css('overflow', 'hidden');
	    $('#specials-signup').css('margin-left', '-373px');
	}
    }
})();

$(function() {
	
	// Recipe form add ingredient
	$("#recipe-form").each(function(){
		var recipeForm = $(this);
		var x = 2;		
		$("#add-another-ingredient").click(function(e){
			e.preventDefault();
			$.get('/includes/ingredient-item.php?number='+x, function(data){
				$("#ingredients-list").append(data);		
			});
			x++;
		});
		// Refresh freecap
		$("#reload-freecap").click(function(){
			$("#freecap-img").attr("src","http://www.destinationhotels.com/direct/freecap/freecap.php?r=" + Math.random());
		});
	});
	
	// Kids recipe contest push widget
	if(BROWSER=='msie6') {
		$(window).scroll(function() {
			ieposfix();
		});
		ieposfix();
	}

	function ieposfix() {
		var pos = ($(window).scrollTop() + $(window).height()) - $('div#bottom-kids-recipe-contest-promo-outer-wrapper').height();
		$("div#bottom-kids-recipe-contest-promo-outer-wrapper").css("top", pos + "px").css("position","absolute").css("bottom","auto");
	}
	
	$('#close-button').click(function(){
		$("div#bottom-kids-recipe-contest-promo-outer-wrapper").remove().html('');
	});
	
	$('form#signup .textfield').focus(function() {
		  $(this).val('');
	});
	
	
	

	
	// Show hide for ski tips
	
	$('.ski-tips-section').each(function() {
		var skiToggle = $(this);
		$('.ski-expand',skiToggle).toggle(function() {
			$('.ski-tips-long',skiToggle).slideDown();
			$('.ski-expand',skiToggle).text('Collapse Post');
		}, function() {
			$('.ski-tips-long',skiToggle).slideUp();
			$('.ski-expand',skiToggle).text('Read Full Post');
		});
	});
	
	// Show hide for ski directions
	
	$('.ski-directions-interior').each(function() {
		var skiToggle = $(this);
		$('.ski-expand',skiToggle).toggle(function() {
			$('.ski-directions-long',skiToggle).slideDown();
			$('.ski-expand',skiToggle).addClass('ski-collapse');
		}, function() {
			$('.ski-directions-long',skiToggle).slideUp();
			$('.ski-expand',skiToggle).removeClass('ski-collapse');
		});
		$('.collapse-long').click(function(e) {
			e.preventDefault();
			$(this).parent().slideUp();
			$('.ski-expand',skiToggle).removeClass('ski-collapse');
		});
	});
	
	// Show hide for recipes
	
	$('.recipe-interior').each(function() {
		var skiToggle = $(this);
		$('.recipe-expand',skiToggle).toggle(function() {
			$('.recipe-long',skiToggle).slideDown();
			$('.recipe-expand',skiToggle).addClass('recipe-collapse');
		}, function() {
			$('.recipe-long',skiToggle).slideUp();
			$('.recipe-expand',skiToggle).removeClass('recipe-collapse');
		});
		$('.collapse-long').click(function(e) {
			e.preventDefault();
			$(this).parent().slideUp();
			$('.recipe-expand',skiToggle).removeClass('recipe-collapse');
		});
	});
	
    $('#weather-wrapper div.weather').each(function() {
	//if ( window.console ) console.log( $(this)[0] );
	//if ( window.console ) console.log( $(this).find('.toggle').length )
	$(this).find('.toggle').toggle(function(e) {e.preventDefault()
	    var id = $(this).attr('href');
	    //if ( window.console ) console.log( id ) 
	    $(id ).fadeIn();
	    $(this).removeClass('toggle')
	    $(this).addClass('toggled')
	}, function(e){e.preventDefault()
	    var id = $(this).attr('href');
	    $(id).fadeOut();
	    $(this).removeClass('toggled')
	    $(this).addClass('toggle')
	});
    });

    if ( window.console ) console.log( $('#signup-toggle').length )

    $('#signup-toggle').toggle(function(e){
	$(this).addClass('toggled')
	e.preventDefault();
	$('#signup-new').addClass('open')
    }, function(e) {
	$(this).removeClass('toggled')
	$('#signup-new').removeClass('open')
	e.preventDefault();
    });

	/*
	$('#specials-signup').css({
	    width: 213,
	    height: 62
	})
	*/


	$(document).pngFix({
	    blankgif:'/images/blank.gif'
	});

	if ( window.Cufon ) {
	    $('#push-earth-links').each(function() {
		Cufon.replace('#push-earth-links span', { fontFamily: 'GillSans Light', printable:false });
	    });
	}

	// for debugging IE...
	/*
	if ( location.href.indexOf('debugger') != -1 ) {
	    $('<div id="debugger"></div>').appendTo('body')
	    $('<iframe/>').attr('src', 'javascript:false').attr('id', 'debugger-shim').appendTo('body')
	    $('<form id="console-form"><textarea name="text" id="console-input"></textarea><input type="submit" value="Run"/></form>').appendTo('#debugger');
	    $('<ol/>').appendTo('#debugger');
	    $('#console-form').submit(function(e) {
		e.preventDefault()
		eval( $('#console-input').val() );
	    });
	}
	*/

	window.log = function( msg ) {
	    /*
	    if ( window.console && console.log ) {
		console.log.call( console, msg )
	    }
	    */
	    if ( $('#debugger').length ) {
		$('#debugger ol').append( $('<li/>').text( msg ) );
	    }
	}
	
	//anything other than just a hash sign, let's scrollto
	if ( location.hash.length>1 ) {
	    $.scrollTo('#content');
	}
	//booking console
	$('.toggle-promo').click(function(e){
		e.preventDefault();
		$('#promo-console').toggle(0,function(){
			if($(this).is(':visible')) {
				$('#group-code').focus();
			}
			else {
				$('.submit').focus();
			}
		});
		if (BROWSER=='msie6') $('#basic-console select').toggle();
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$('#complete-promo').show();
		}
		else {
			$('#complete-promo').hide();
		}
	});
	
	$('#map-experiences a, #map-regions a').click(function(e){
		e.preventDefault();
		$('.map-destinations li a').css({color:'#ffffff'}).parents('.'+$(this).attr('rel')).children().animate({color:'#5f5244'},100).animate({color:'#79d6ff'}, 1000);
	});
	
	$('.filter').click(function(e){e.preventDefault();$(this).siblings().toggle();})
	    if ( $.fn.cycle ) {
		$('div.rotation-wrapper').cycle({
				fx:'scrollLeft',
				pause:1,
				timeout:0,
				next:'.rotation-next',		// selector for element to use as click trigger for next slide 
				slideExpr:'.rotation-item',
				cleartype:true,
				cleartypeNoBg:true,
				height:'180px',
				fastOnEvent:250	// force fast transitions when triggered manually (via pager or prev/next); value == time in ms 
		});
	    }
	var state='', city = '', type='', xml='', experience='';
	$('.state-map').each(function(){
		var arrPath = $(this).attr('id').split('_');
		if (arrPath[0]=='experiences'){
			state=arrPath[2];
			if(arrPath.length > 4) {
				city=arrPath[3];
			}
			xml='/xml/experience_map.xml';
			type='experiences';
			experience=arrPath[1];
		} else {
			state=arrPath[1];
			if(arrPath.length > 3) {
				city=arrPath[2];
			}
			xml='/xml/property_map.xml';
		}
	});
	$('.state-map').flash(
		{src:"/flash/state-map.swf",
		 width:191,
		 height:204,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.stateID = state;
				htmlOptions.flashvars.cityID = city;
				htmlOptions.flashvars.xmlPath=xml;
				htmlOptions.flashvars.mapType = type;
				htmlOptions.flashvars.experience = experience;
				htmlOptions.flashvars.browser = BROWSER;  //Used for SSP Postcard feature, comment out if not needed.
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	var type = '';
	var experience = '';
	var xml = '';
	var forceState = '';
	$('.experience-map').each(function(){
		if ( $(this).attr('id') == 'experiences_mountain_CO_map' ) {
			forceState = 'CO';
		}
	    if ( $.hasFlash() ) {
		$(this).css('display', 'inline');
	    }
		var arrPath = $(this).attr('id').split('_');
		//alert(arrPath.length);
		if (arrPath[0]=='experiences'){
			type=arrPath[0];
			experience=arrPath[1];
			xml='/xml/experience_map.xml';
		} else {
			type='states';
			xml='/xml/property_map.xml';
		}
	});
	$('.experience-map').flash(
		{src:"/flash/destination-map.swf",
		 width:412,
		 height:312,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.mapType = type;
				htmlOptions.flashvars.experienceType = experience;
				htmlOptions.flashvars.xmlPath=xml;
				htmlOptions.flashvars.forceState = forceState  // accepts any two letter state code
				htmlOptions.flashvars.browser = BROWSER;  //Used for SSP Postcard feature, comment out if not needed.
				$(this).html($.fn.flash.transform(htmlOptions));
		});
    var pageType = 'destinations';
    var displayCount = 3;
    var xmlPath = '/masthead-parser.php';
    var tags = '';
	var useStatic = false;
    $('.masthead').each(function(){
		//see if a masthead has been added via CMT
		$(this).children('img').css('visibility','visible');
		var altImg = $(this).children('img').attr('src')||'temp-masthead';
		if (altImg.indexOf('temp-masthead') == -1) {
			useStatic=true;
		}
		
        var startIndex = 1;
        var arrPath = $(this).attr('id').split('_');
        if(arrPath[0]!=''){
            pageType = arrPath[0];
            
            if(pageType == 'property'){
                xmlPath = '/resorts/'+arrPath[1]+'/mastheads.xml'; 
                startIndex = 2;
			} else if (pageType == 'red-lion-loyalty-club') { // so it only shows red lion mastheads
				xmlPath = '/resorts/69/mastheads.xml'; 
				tags = 'WA_seattle';
				startIndex = 2;
				pageType='property';
			} else {
				xmlPath = '/masthead-parser.php';
            }
            if(window.MASTHEAD_IMG){
                displayCount = MASTHEAD_IMG;
            }
            for (var i=startIndex;i<arrPath.length;i=i+1){ 
                if(arrPath[i]!='masthead'){
                    if(i!=(arrPath.length-1) && i!=startIndex){
                        tags = tags + "_";
                    }
                    tags = tags + arrPath[i];
                }
            }
        }
        
    });
	if (!useStatic) {
		$('.masthead').flash(
			{src:"/flash/interior-masthead.swf",
			 width:956,
			 height:300,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					htmlOptions.flashvars.pageType = pageType;
					htmlOptions.flashvars.displayCount = displayCount;
					htmlOptions.flashvars.xmlPath=xmlPath;
					htmlOptions.flashvars.tags = tags;
					$(this).html($.fn.flash.transform(htmlOptions));
			});
	}
    $('.home .masthead').flash(
        {src:"/flash/home-masthead.swf",
         width:962,
         height:447,
         wmode:"transparent",
         quality:"high"},
         {version:"8"},
            function(htmlOptions) { //Use this to specify a query string, take out if not needed.
                htmlOptions.flashvars.experienceXmlPath = "/xml/experience_map.xml";
                htmlOptions.flashvars.mapPath = "/flash/assets/destination-pop-map.swf";
                htmlOptions.flashvars.xmlPath="/xml/home_mastheads.xml";
                //htmlOptions.flashvars.tags = tags;
                $(this).html($.fn.flash.transform(htmlOptions));
        }).addClass('masthead_flash_home');
	$('#masthead-home-property').hide()
    $('.home #push-rotation-wrapper').flash(
        {src:"/flash/special-offers.swf",
         width:644,
         height:133,
         wmode:"transparent",
         quality:"high"},
         {version:"8"},
            function(htmlOptions) { //Use this to specify a query string, take out if not needed.
                //htmlOptions.flashvars.xmlPath="/xml/home-offers-rotation.xml";
                $(this).html($.fn.flash.transform(htmlOptions));
        });
	$('#industry-experts').each(function() {
	    $('.expert-copy').hide();
	    $('.expert').each(function(i,o) {
		var anchor = $('<a/>').attr('id','bio-'+i).addClass('modal-trigger').attr('href', '#').text('Read More')
			.appendTo( o )
		$('.expert-title span', o).click(function() {
		    $(this).closest('.expert').find('.modal-trigger').trigger('click');
		});
	    });
	});
	function contains( string, substring ) {
	    return string.indexOf(substring) != -1;
	}
	//Modal Setup - any links with class="modal-trigger" and id="whatever" will display the contents of the div within #modal-wrapper with id="modal-whatever"
	var openFn = function( hash ){
	    var id = hash.t.id,
		ref = $('#'+id);
		if ( contains( id, 'video') ) {
			hash.w.show().children('#modal-video-all').show().find('#hotel-video').trigger('change');
		}
		else if ( contains( id, 'bio' ) ) {
			var expertId = id + '-modal';
			if ( !$('#'+expertId).length ) {
			    var duplicateTitle = $(ref).siblings('.expert-title').clone(),
				container = $('<div/>')
				    .attr( 'id', expertId )
				    .prepend( $(duplicateTitle) )
				    .addClass('expert-content')
				    .append( $(ref).siblings('.expert-copy') )
				    .appendTo( '#modal-expert' )
				    .find('.expert-copy').show()
			}
			$('#'+expertId).show().siblings('.expert-content').hide()
			hash.w.show().children('#modal-expert').show();
		}
		else {
			hash.w.show().children('#modal-'+hash.t.id).show();
		}
		if ($(hash.t).hasClass('no-overlay')) hash.o.css({backgroundColor:'transparent'});
		var leftPos = ($(window).width()-$('#modal-wrapper').width())/2;
		var topPos = Math.max($(window).scrollTop(),parseInt($('#modal-wrapper').css('top')));
		$('#modal-wrapper').css({left:leftPos,top:topPos});
	};
	var hideFn=function(hash){
		hash.w.hide().css({left:0,top:0}).children('.modal-content').hide();
		hash.o.remove().css({backgroundColor:'#000'});
		$('.video-dhr').remove();
	};

	$('#modal-wrapper').each(function(){ $(this).jqm({trigger:'.modal-trigger', closeClass:'modal-close', overlayClass:'modal-overlay', onShow: openFn, onHide: hideFn});});
	$("#spring-sale-modal").each(function() {
		var springModalWidth = ($(window).width()-$(this).width())/2;
		$(this).css('left',springModalWidth);
		$(this).css('top','120px');
		$(this).jqm({closeClass:'spring-sale-close,'}).jqmShow();
	});
	
	/*$('#spring-sale-modal').each(function() {
		var springModalWidth = ($(window).width()-$(this).width())/2;
		$(this).css('left',springModalWidth);
		$(".spring-sale-overlay").height($(window).height()).css({ opacity: 0.6 });;
		$(this).show();
	});
	
	$('#spring-close-button').click(function() {
		$('#spring-sale-modal').hide();
		$('.spring-sale-overlay').hide();
	});*/
	
	$('.modal-video-trigger').each(function() {
		$(this).click(function(e) {
			e.preventDefault();
			var id = $(this).attr('id');
			id = id.split('-')[1];
			var code = embed[id];
			var cssWidth = width[id];
			$('.video-title').html($(this).parents().find('h3').html());
			$('#video-container').html(code);
			$('#news-videos').css('width',cssWidth);
			$('#modal-video-wrapper').jqm({closeClass:'modal-close'}).jqmShow();
		});
	});
	
	
	/*
	
	$('.modal-video-trigger').each(function() {
		
		$(this).click(function(e) {
			e.preventDefault();			   
			var id = $(this).attr('id');
			switch(id){
				case 'video-today-show':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<object width="420" height="245" id="msnbc39cef" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0"><param name="movie" value="http://www.msnbc.msn.com/id/32545640" /><param name="FlashVars" value="launch=38538843&amp;width=420&amp;height=245"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="wmode" value="opaque" /><embed name="msnbc39cef" src="http://www.msnbc.msn.com/id/32545640" width="420" height="245" FlashVars="launch=38538843&amp;width=420&amp;height=245" allowscriptaccess="always" allowFullScreen="true" wmode="opaque" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>');
					$("#news-videos").css('width','420px');
					break;
				case 'video-horsing-around':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<object width="503" height="294" data="http://www.equestrianlife.com/videoplayer/flowplayer-3.0.9.swf" type="application/x-shockwave-flash"><param name="movie" value="http://www.equestrianlife.com/videoplayer/flowplayer-3.0.9.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value=\'config={"plugins":{"h264streaming":{"url":"http://www.equestrianlife.com/videoplayer/flowplayer.h264streaming-3.0.5.swf"},"controls":{"sliderColor":"#414141","sliderGradient":"none","backgroundColor":"#CECEC2","durationColor":"#e7d5d5","buttonColor":"#102545","buttonOverColor":"#728B94","progressColor":"#213a60","borderRadius":"0","timeColor":"#e7d6d5","progressGradient":"medium","bufferGradient":"none","bufferColor":"#7081a7","bufferOverColor":"#102545","backgroundGradient":"none","opacity":1}},"clip":{"title":"Horsing Around The World - Ep2: San Deigo","autoPlay":false,"autoBuffering":true,"provider":"h264streaming"},"playlist":[{"url":"http://www.equestrianlife.com/img/tvscreens/HAW_Large.jpg","autoPlay":false,"title":"Horsing Around The World - Ep2: San Deigo","autoBuffering":true,"provider":"h264streaming"},{"url":"http://c.equestrianlife.com/videos/tv/HAW/HAW_EP2_Full.mp4","title":"Horsing Around The World - Ep2: San Deigo","autoPlay":false,"autoBuffering":true,"provider":"h264streaming"}],"contextMenu":["Equestrian Life Studios Video Player",{"View Related Videos":"function()"}]}\' /></object>');
					$("#news-videos").css('width','503px');
					break;
				case 'video-blooms-by-the-sea':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<object height="300" width="400"><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="http://vimeo.com/moogaloop.swf?clip_id=10245732&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" name="movie"><embed height="300" width="400" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" src="http://vimeo.com/moogaloop.swf?clip_id=10245732&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1"></object>');
					$("#news-videos").css('width','400');
					break;
				case 'video-romance':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<object height="363" width="456" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="flashObj"><param value="http://c.brightcove.com/services/viewer/federated_f9/16829212001?isVid=1&amp;publisherID=10228013001" name="movie"><param value="#FFFFFF" name="bgcolor"><param value="videoId=66171621001&amp;playerID=16829212001&amp;domain=embed&amp;" name="flashVars"><param value="http://admin.brightcove.com" name="base"><param value="false" name="seamlesstabbing"><param value="true" name="allowFullScreen"><param value="true" name="swLiveConnect"><param value="always" name="allowScriptAccess"><embed height="363" width="456" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" allowscriptaccess="always" swliveconnect="true" allowfullscreen="true" type="application/x-shockwave-flash" seamlesstabbing="false" name="flashObj" base="http://admin.brightcove.com" flashvars="videoId=66171621001&amp;playerID=16829212001&amp;domain=embed&amp;" bgcolor="#FFFFFF" src="http://c.brightcove.com/services/viewer/federated_f9/16829212001?isVid=1&amp;publisherID=10228013001"></object>');
					$("#news-videos").css('width','456px');
					break;
				case 'video-opening-day':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<embed height="325" width="380" quality="high" wmode="transparent" type="application/x-shockwave-flash" src="http://www.laubergedelmar.com/california-resort-highlights.swf" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="">');
					$("#news-videos").css('width','380px');
					break;
				case 'video-renovations':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<embed height="310" width="480" quality="high" wmode="transparent" type="application/x-shockwave-flash" src="http://www.laubergedelmar.com/flash/california-resort-renovation.swf" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="">');
					$("#news-videos").css('width','480px');
					break;
				case 'video-modern-luxury':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<object height="363" width="486" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="flashObj"><param value="http://c.brightcove.com/services/viewer/federated_f9/16829212001?isVid=1&amp;publisherID=10228013001" name="movie"><param value="#FFFFFF" name="bgcolor"><param value="videoId=22330027001&amp;playerID=16829212001&amp;domain=embed&amp;" name="flashVars"><param value="http://admin.brightcove.com" name="base"><param value="false" name="seamlesstabbing"><param value="true" name="allowFullScreen"><param value="true" name="swLiveConnect"><param value="always" name="allowScriptAccess"><embed height="363" width="486" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" allowscriptaccess="always" swliveconnect="true" allowfullscreen="true" type="application/x-shockwave-flash" seamlesstabbing="false" name="flashObj" base="http://admin.brightcove.com" flashvars="videoId=22330027001&amp;playerID=16829212001&amp;domain=embed&amp;" bgcolor="#FFFFFF" src="http://c.brightcove.com/services/viewer/federated_f9/16829212001?isVid=1&amp;publisherID=10228013001"></object>');
					$("#news-videos").css('width','486px');
					break;
				case 'video-travel-a-la-mode':
					$('.video-title').html($(this).parents().find('h3').html());
					$('#video-container').html('<embed height="363" width="480" quality="high" wmode="transparent" type="application/x-shockwave-flash" src="/flash/wedding-album.swf" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="">');
					$("#news-videos").css('width','480px');
					break;
				}
				
			$('#modal-video-wrapper').jqm({closeClass:'modal-close'}).jqmShow();
			
		});
		
		
	});
	*/
	
	$('#video-list ul li a').live('click', function(e) {
	    log('clicked on a video link')
	    e.preventDefault();
	    var link = $(this).attr('href');
		e.preventDefault();
		var iframe = $('#video-wrapper iframe'), iframeExists = iframe.length;
		if ( iframeExists ) {
		    log('iframe exists, changing the src... to ' + link)
		    $(iframe).attr('src', link);
		    $('.video-dhr')
			.attr('width', '410')
			.attr('height', '320')
			.removeClass('video-dhr');
		    log('toggled the width/height, removed video-dhr class')
		} else {
		    log('no iframe exists, replacing the image with one..')
		    $('#video-wrapper img').replaceWith('<iframe id="modal-iframe" frameborder="0" width="410" height="320" style="display:block;margin:0 auto;" />');
		    log('replaced img with an iframe')
		    $('#modal-iframe').attr('src', link);
		    log('changed the iframe src')
		    $('.video-dhr').removeClass('video-dhr');
		}
	});
	$('#hotel-video').change(function() {
	    var value = $(this).val(), name = $(':selected', this).text();
		//$("#video-wrapper iframe").attr('src','');
		$("#video-wrapper iframe").remove();
		log('iframe removed')
		$("#video-wrapper").html('<img src="/images/layout/modal-intro.jpg" alt="" border="0" />');
		log('.html invoked on #video-wrapper, showing default image and attempting to do ajax...')
	    if ( value ) {
			$.ajax({
				type:'GET',
				url:'/direct/video-request.php',
				data: 'property=' + value,
				success:function( data ) {
				    log('callback from ajax')
					$('#video-list-content').empty().append( data );
					log('within ajax, emptied list-content, appended with data.')
					if ( value == 'dhr-video' ) {
					    $("#video-list-content").html('<ul class="clear-float"><li><a href="http://www.destinationhotels.com/direct/video-dhr.php">Destination Hotels &amp; Resorts</a></li></ul>');
					}
				}
			});
			$('#property-name-lightbox').text( '- ' + name );
	    }
	});
	$('.inset-photos').each(function() {
	    if ( $.hasFlash() ) {
		$(this).css('display', 'inline');
	    }
	    var id = $(this).attr('id'), arr = id.split('_'),
		preview = location.href.indexOf('preview_property')!= -1;
	    if ( arr.length ) {
		$(this).flash(
			{src:"/flash/insets.swf",
			 width:285,
			 height:226,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					htmlOptions.flashvars.xmlPath='/xml/hotels-resorts/' + ( preview ? 'preview/' : '') + arr[0] + '.xml';
					$(this).html($.fn.flash.transform(htmlOptions));
			});
	    }
	});
	$('.help-link').click(function(e){e.preventDefault();$(this).parent().parent().find('.form-help').toggle();});
	// oh well.
	$('#awards-table tr:last td, body.industry-experts tr:last td').css('border', '0');
    
    $('div#articles-wrapper div.article-item:last').css('border','0');
	
	// Amex Promo form js
	
	$("#amex-promo").each(function(){
		var form = $(this);
		$("select#hotel",form).change(function(){
			form.submit();
		});
	});
	$('div.article-item a').each(function() {
	    var href = $(this).attr('href');
		var div = $(this).parent().children('div.article-copy');
		div.append( $('<a/>').addClass('read-more').attr('href', href).text('Read the article') );
	});
	var externalLinks = [
	    /\.pdf/,
	    /\.doc/,
	    /^http/
	];
	
	// sup:contains('®') doesn't want to work?
	$("sup").each(function(){temp=$(this).text();if (escape(temp)=="%AE") { $(this).addClass('fixR');}});
	$('a').each(function(i,o) {
	    var href = $(this).attr('href');
	    if ( href ||  !($(this).attr('target').length) ) {
		$(externalLinks).each(function() {
		    if ( this.test(href) ) {
			$(o).attr('target', '_blank');
		    }
		});
	    }
	});
	
	$('li#tertiary-destination-dish a').attr('target', '_blank');
	
	$('#specials-signup').flash(
        {src:"/flash/email-form.swf",
         width:566,
         height:101,
         wmode:"transparent",
         quality:"high"},
         {version:"9"});
	
	/* adds "odd" class to odd rows in tables with class "styled-table" */
	$("table.styled-table tr:nth-child(odd)").addClass("odd");
	
	/*
    $('body.industry-experts table tr').each(function() {
	var first = $('p:first', this), 
	    secondCell = $('td:last', this),
	    rest = $(first).nextAll('p')
		.hide(),
	text = {
	    hide:'Hide Information',
	    show:'Read more about this expert'
	}
	anchor = $('<a/>')
	    .addClass('read-more-expert')
	    .attr('href', '#')
	    .text( text['show'] )
	    .toggle(function() {   
		$(rest).slideDown('fast')
		$(this).text( text['hide'] )
	    }, function() {
		$(rest).slideUp('fast')
		$(this).text( text['show'] )
	    })
	if ( rest.length ) {
	    $(secondCell).append( anchor )
	}
    });
    */
	
	$(".property-listing-points").each(function(){
		var x = $(this);
		$("ul",x).hide();
		$(".property-listing-click",x).toggle(function(){
			$("ul",x).slideDown();
			$(this).html('Hide Details');
		}, function() {
			$("ul",x).slideUp();
			$(this).html('Show Details');
		});
	});
    $('form#form-news-archive select').change(function() {
	$(this).closest('form').submit();
    });
    $('form#form-news-archive .submit').hide();
    if ( location.href == 'http://www.destinationhotels.com/careers' || location.href == 'http://www.destinationhotels.com/careers/' ) {
	$('#utility-careers-careers').addClass('current');
    }
    $('body.home input#email_address').each(function() {
	var defaultText = 'Enter your email address here';
	this.value = defaultText; 
	$(this).click(function(){
	    if ( this.value == defaultText ) {
		this.value = ''
	    }
	});
	$(this).blur(function() {
	    if ( this.value.length === 0 ) this.value = defaultText
	});
    });
    $('#filters-wrapper').each(function() {
	$(this).find('.current').parent().show()
    });
	
	// Travel Professioanl Sign Up Form Popup
	$('#travel-pro-popup-signup-button').each(function(){
		//Center popup function
		var openPopup=function(hash){
			hash.w.show();
			hash.w.css("position","absolute");
			var top = ( $(window).height() - hash.w.outerHeight() ) / 2+$(window).scrollTop();
			if ( top < 0 ) {
				top = 10;
			}
			hash.w.css("top", top + "px");
			hash.w.css("left", ( $(window).width() - hash.w.outerWidth() ) / 2+$(window).scrollLeft() + "px");
		};
		//Hide Popup
		var closePopup=function(hash){
			hash.w.hide()
			hash.o.remove();
		};
		$(this).click(function(e){
			e.preventDefault();
			$('#travel-pro-signup-wrapper').jqm({closeClass:'jqmClose', overlayClass:'modal-overlay', onShow: openPopup, onHide: closePopup}).jqmShow();
		});
		
						function checkUsername(data,stepBtn) {
							if ( data == 1 ){
								hideAllSteps();
								stepBtn.attr('id','step2');
								$("#travel-pro-step-2").show();
								$("#travel-pro-signup-steps").html('screen 2 of 5');
							} else {
								alert('That username is already taken.');
								$("#username").focus();
							}
						}
		
		$("#travel-pro-step-change-button a").click(function(e){
			e.preventDefault();
			var stepBtn = $(this);
			var curStep = stepBtn.attr('id');
			var isValid;
			var checkUser;
			switch(curStep) {
				case 'step1':
					isValid = validateThis("#travel-pro-step-1");
					if ( isValid == true ) {
						if (BROWSER=='msie7') {
							var u = $.trim($('.ie7username').val());
						} else {
							var u = $.trim($('#professional-signup-popup input#username').val());
						}
						$.get('/direct/username-check.php?username='+u,function(data){
							  checkUsername(data,stepBtn);
						});
					}
					break;
				case 'step2':
					isValid = validateThis("#travel-pro-step-2");
					if ( isValid == true ) {
						hideAllSteps();
						stepBtn.attr('id','step3');
						$("#travel-pro-step-3").show();
						$("#travel-pro-signup-steps").html('screen 3 of 5');
					}
					break;
				case 'step3':
					isValid = validateThis("#travel-pro-step-3");
					if ( isValid == true ) {
						hideAllSteps();
						stepBtn.attr('id','step4');
						$("#travel-pro-step-4").show();
						$("#travel-pro-signup-steps").html('screen 4 of 5');
					}
					break;
				case 'step4':
					isValid = validateThis("#travel-pro-step-4");
					if ( isValid == true ) {
						hideAllSteps();
						stepBtn.attr('id','step5');
						$("#travel-pro-step-5").show();
						$("#travel-pro-signup-steps").html('screen 5 of 5');
					}
					break;
				case 'step5':
					isValid = validateThis("#travel-pro-step-5");
					if ( isValid == true ) {
						hideAllSteps();
						stepBtn.attr('id','stepLogin');
						$("#travel-pro-step-change-button a").addClass('login-btn');
						$("#travel-pro-thanks").show();
						$("#travel-pro-signup-steps").html('');
					}
					break;
				case 'stepLogin':
					$("#professional-signup-popup").submit();
			}
		});
		
		function hideAllSteps(){
			$('#travel-pro-step-1, #travel-pro-step-2, #travel-pro-step-3, #travel-pro-step-4, #travel-pro-step-5, #travel-pro-thanks, form#professional-signup-popup .buttons, #travel-pro-intro-text').hide();
		}
				
	});
	
	/* Kids Menu Table */
	$("body.kids-menu table tbody tr:odd").addClass('tr-odd');
	
	/* Webcam Modal */
	$('.webcam-modal').jqm();
	$('.webcam-toggle').click(function(){
		var propertyid = $(this).attr('id');
		$('#modal-'+propertyid).jqmShow();
	});
	
	//Facebook Widget 
	/*$(document).ready(function() {
		
		$("div.facebook-widget").each(function() {
			$(this).slideDown(1000);
			$(this).children('.close').click(function() {
				$("div.facebook-widget").slideUp();
			});
		});
	});*/
	
	
});


function validateThis(f){
	var form = f;
	var validTest = true;
	$(form).each(function() {
		var _errors = '';
		//Removes validation errors from previous submit
		$('.validation-error', form).remove();
		
		$('.required:not(label)', form).each(function() {
			var valid = true;
			
			if($(this).is(':input')) {
				var o = $.trim($(this).val());
				
				if($(this).hasClass('email')) {
					// if it's an email address make sure the email is valid using both regular expressions
					valid = /^[a-z0-9_+.-]+\@(?:[a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test(o);
					if($(this).hasClass('confirm-email')&&valid) {
						var prev = $.trim($(this).parents('.field').prev().children('.email').val());
						if(o!=prev)
							valid=!valid;
					}
				} else if (o.replace(/(?:^\s+)|(?:\s+$)/g,'').length < 1) {
					// if not an email address take out funky characters and see if its still blank
					valid = !valid;
				}
			} else if($(this).is('ul')) {
				valid = false;
				
				$(':radio, :checkbox', this).each(function() {
					if($(this).is(':checked'))
						valid = true;
				});
			}
			
			if(!valid) {
				var warn = $('<img />').attr('src', '/images/icon-warning.gif').addClass('validation-error');
				
				if( $(this).is('ul') )
					$('li:first', this).append(warn);
				else 
					$(this).parent().append(warn);
											
				if(_errors == '')
					_errors = $(this).attr("id");
			}
		});
		if(_errors.length) {
			var lbl = $('#'+_errors).parents('.field').children('label');
			if(lbl[0].title.length)
				alert(lbl[0].title);
			else 
				alert( 'A valid ' + lbl.html().replace(/[*:]/g, '') + ' is required.');
			$('#'+_errors, form).focus();
				validTest = false;
			return false;			
		} else {
			validTest = true;
		}
	});
	return validTest;
}

$(document).ready(function(){
	$(function() {
		$("div#flash-object").flash(
			{src:"flash/holiday-game-2011.swf",
			 width:940,
			 height:538,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"9"},
				function(htmlOptions) {
					$(this).html($.fn.flash.transform(htmlOptions));				
			});	
	});
});

