$(function() {

	 $('#res-console').tabs();

// Flash
			
		$('#renovation-flash').flash({
		    src:'/flash/renovations.swf',
		    width:647,
		    height:551,
		    wmode:'transparent',
		    quality:'high'},
		    {version:'8'}
		);

		$("div#flash-masthead").flash(
			{src:"flash/homepage-masthead.swf",
			 width:927,
			 height:300,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#accommodations-masthead").flash(
			{src:"flash/accommodations-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#special-masthead").flash(
			{src:"flash/specialPackages-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#meetings-masthead").flash(
			{src:"flash/meetings-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#recreation-masthead").flash(
			{src:"flash/recreation-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#aria-masthead").flash(
			{src:"flash/ariaSpa-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#dining-masthead").flash(
			{src:"flash/dining-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#resort-masthead").flash(
			{src:"flash/resortInfo-masthead.swf",
			 width:432,
			 height:181,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
		
		$("div#content-photo-gallery").flash(
			{src:"/flash/photo_gallery.swf",
			 width:460,
			 height:380,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.epostConfigXML="flash/xml/epostConfig.xml";
				htmlOptions.flashvars.imagesXML="flash/xml/images.xml";
				htmlOptions.flashvars.langXML="flash/xml/i18n/en_formLabels.xml"; //en is language code, on production it looks like "flash/xml/i18n/"+LANG+"_formLabels.xml"
				$(this).html($.fn.flash.transform(htmlOptions));
		});

		$("div#wedding-photo-gallery").flash(
			{src:"/flash/gallery-weddings.swf",
			 width:645,
			 height:500,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"});

		$("div#dhr-flash").flash(
			{src:"http://www.destinationhotels.com/flash/branding/flash_logoDhr-white.swf?link=vailcascade",
			 width:250,
			 height:25,
			 wmode:"transparent",
			 allowScriptAccess:"always",
			 quality:"high"},
			 {version:"7"});
		
		$("div#resort-video").flash(
			{src:"flash/VailCascadeNoLogo.swf",
			 width:420,
			 height:280,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});
			 
		$("div#vermont-resort-video").flash(
			{src:"flash/stowe-property.swf",
			 width:550,
			 height:448,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});		 
		
		
		$('a.map-link').click( function() {
			window.open( 'resort-map.php','ResortMap','width=670,height=405, scrollbars=no')
			return false;
		});
		
	// Sifr
		$('div#content h2').sifr({ strSWF: '/flash/univers-condensed.swf', strColor: '#7E94AF', strWmode: 'transparent', intPadding: [0, 0, 0, 5]},	{ expressInstall: true });		
		$('div.push-marketing h4').sifr({ strSWF: '/flash/univers-condensed.swf', strColor: '#035788', strWmode: 'transparent', intPadding: [0, 0, 0, 0]},	{ expressInstall: true });
		$('body.home div.christmas h4').sifr({ strSWF: '/flash/univers-condensed.swf', strColor: '#bb0101', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=right&'},	{ expressInstall: true });
		$('body.home div.breast-cancer h4').sifr({ strSWF: '/flash/univers-condensed.swf', strColor: '#DA3090', strWmode: 'transparent', intPadding: [0, 0, 0, 0]}, { expressInstall: true });
		$('div.home-specials h4').sifr({ strSWF: '/flash/univers-condensed.swf', strColor: '#035788', strWmode: 'transparent', intPadding: [0, 0, 0, 0]},	{ expressInstall: true });
		$('div#archive-wrapper h2').sifr({ strSWF: 'f/lash/univers-condensed.swf', strColor: '#004476', strWmode: 'transparent', intPadding: [0, 0, 0, 0]},	{ expressInstall: true });
		//$('span.form-legend').sifr({ strSWF: 'flash/univers-condensed.swf', strColor: '#035788', strWmode: 'transparent', intPadding: [0, 0, 0, 0] }, { expressInstall: true });
		
		$('h4.search-legend ').sifr({ strSWF: '/flash/helvetica-condensed.swf', strColor: '#003356', strWmode: 'transparent', intPadding: [0, 0, 0, 0]},	{ expressInstall: true });
		$('div#request-list-wrapper h5').sifr({ strSWF: '/flash/future-condensed.swf', strColor: '#00375e', strWmode: 'transparent', strCase: 'upper'},	{ expressInstall: true });
		$('div#detail-info h5').sifr({ strSWF: '/flash/helvetica-condensed-bold.swf', strColor: '#214965', strWmode: 'transparent', strFlashVars: 'textalign=center&', strCase: 'upper'},	{ expressInstall: true });
		$('div.request-unit-wrapper h4').sifr({ strSWF: '/flash/helvetica-condensed.swf', strColor: '#003356', strWmode: 'transparent', intPadding: [0, 0, 0, 0]},	{ expressInstall: true });

	
	//code to rotate push marketing

		var count = $('ul#push-list li').size();
		var rand = Math.floor(Math.random()*count);
		
		$('ul#push-list li').not(':eq('+rand+')').hide();
		$('ul#push-list li:eq('+rand+')').addClass('current');
		$('.link-refresh a').click(function() {
			setTimeout(function() {
				$('div#push-loading img').attr("src", 'images/layout/ajax-loader.gif?random=' + new Date().getTime())
			}, 500);
			var h = $('div#push-loading').parent().height(); //ie6 won't fill the push box by default
			$('div#push-loading').addClass('loading').height(h);
			var nextItem = ($('ul#push-list li.current').next().html()) ? $('ul#push-list li.current').next() : $('ul#push-list li:eq(0)');
			$('ul#push-list li.current').removeClass('current').fadeOut('slow', function() {nextItem.addClass('current').fadeIn('slow', function() {$('div#push-loading').removeClass('loading')});})
			clearTimeout();
			return false;
		});
	
	//Used for the treatment select box
		$("select#treatment-select").change(function(){
			var value = $("option:selected").val();
			parent.location = value;
			});
	
	
		//Striping Tables
	$("table.striped tbody tr:nth-child(odd)").addClass("tr-odd");
	$("table#accom-details-table tbody tr:first").addClass("tr-first");
	$("table#accom-details-table tbody tr:nth-child(odd) td").addClass("trtd-odd");
	$("table#accom-details-table tbody tr:nth-child(even) td").addClass("trtd-even");
	$("table#accom-details-table tbody tr:nth-child(odd) th").addClass("trth-odd");
	$("table#accom-details-table tbody tr:nth-child(even) th").addClass("trth-even");

	$('div#promo-code-wrapper').hide();
	$('a#promo-link').click(function() { $('div#promo-code-wrapper').show(); $('div.push-marketing a').css("position","static"); return false; });
	$('a#close-link').click(function() { $('div#promo-code-wrapper').hide(); $('div.push-marketing a').css("position","relative"); return false; });
	
	// Fancybox
	$(".zoom-in").fancybox();
	
	$('.long-info').hide();
    
	$('.show-details').toggle(function() {
		$(this).parents(".package").find('.long-info').animate ({ height: 'show'}, 'slow');
		$(this).html('Hide Details');
	}, function() {
		$(this).parents(".package").find('.long-info').animate ({ height: 'hide'}, 'slow');
		$(this).html('Show Details');
	});

	
	$('.package-expandable').packagePreview();
	$('.vevent').eventPreview();
	$('.rss-item').initializeSharing();
    
    /* Loyalty Form state filtering */
    
    
    $('.filter-state').change(function(){
        if($(this).val()=='United States' || $(this).val()=='Canada'){
            $('.phone-format').show();   
        }else{
            $('.phone-format').hide();  
        }   
        
        $.get("ajax-filter-states.php",
           {country:$(this).val()},
           function(returned_data)
             {
                $('span.states-filter').html(returned_data);
             });
 
    });
	

	
	
});


// Function to add/remove "over" class for drop down nav - remove if not needed
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});

};   

function printFrame () {
	frames['TB_iframeContent'+randomIframeNum].focus();
	frames['TB_iframeContent'+randomIframeNum].print();
}


(function($) {		  
	
	$.fn.packagePreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'Show Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('a.view-details', this).toggle(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				var el = $(this);
				$.get('/includes/package-details.php', { package_id: this.id.substr(3), channel: this.rel, lang: 'EN' },function(data) { 
					el.html(opts.hideDetails).parent().addClass('active').parent().find('.package-long').hide().html(data).slideDown('slow');
				});
			},function(event) { 
				event.preventDefault();
				$('.share-panel').hide();
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
					$(this).html(''); 
				});
			});
		});
	};
	
	$.fn.eventPreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'View Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('.view-details', this).click(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				if ($(this).parent().hasClass('active')) {
					$(this).html(opts.viewDetails).parent().removeClass('active').parent().children('.event-description').slideUp('slow', function() { 
						$(this).html(''); 
					});
				}
				else {
					var el = $(this);
					var temp = this.rel.split(':');
					$.get('/includes/events-calendar-ajax.php', { permalink: temp[0], rssfeed: temp[1], lang: 'EN', op: 'details' },function(data) { 
						el.html(opts.hideDetails).parent().addClass('active').parent().children('.event-description').hide().html(data).slideDown('slow');});
				}
			});
		});
	};
	
	$.fn.initializeSharing = function() {
		return this.each(function() {
			$('.share-link').click(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				$(this).parents('.rss-item').find('.share-panel').css('display','inline');
			});
			$('.share-close').live('click',function(event){
				event.preventDefault();
				$(this).parents('.rss-item').find('.share-panel').slideUp('fast');
			});
		});
	};

	/*$.fn.packagePreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'View Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('.package-details a', this).toggle(function(event) {
				
				
				var el = $(this);
				$.get('/direct/package-details.php', { package_id: this.id.substr(3), channel: this.rel, lang: LANG },function(data) { 
					el.html(opts.hideDetails).parent().addClass('active').parent().find('.package-long').hide().html(data).slideDown('slow');
				});
			},function(event) { 
				event.preventDefault();
				$('.share-panel').hide();
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
					$(this).html(''); 
				});
			});
		});
	};*/

	
})(jQuery);  


function openPreview(urlrequest) {
	window.open(urlrequest, 'myWindow', 'width=800,height=600,left=100,top=100,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
	document.getElementById('flashCallBox').value = urlrequest;
}