$(function() {

	$('.package').packagePreview();
	$('.share-link').initializeSharing();
	$('.blog-post').postPreview();
	
// jquery.flash plugin

	$("div#flash-wrapper").flash(
		{src:"flash/home.swf",
			 width:588,
			 height:320,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"});
	$("div#dhr-footer").flash(
		{src:"http://www.destinationhotels.com/flash/branding/flash_logoDhr.swf?link=stowemountainlodge",
			 width:250,
			 height:25,
			 wmode:"transparent",
			 allowScriptAccess:"always",
			 quality:"high"},
			 {version:"8"});
	$("div#cabin-photo-gallery").flash(
		{src:"slideshow.swf",
			 width:461,
			 height:301,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"});
	$("div#stowe-photo-gallery").flash(
		{src:"flash/photogallery/photo_gallery.swf",
			 width:466,
			 height:400,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"});
			 
	$("div#resort-video").flash(
			{src:"flash/stowe-property.swf",
			 width:550,
			 height:448,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"7"});	
	
//activities form show/hide
$(this).find("#activities").each(function() {
										  
	$("#return_reason-no").hide();
	$("#return_reason-yes").hide();
	if($('#return-yes').attr("checked") == true ){
		$("#return_reason-yes").show();
	}
	if($('#return-no').attr("checked") == true ){
		$("#return_reason-no").show();
	}
	$('#return-no').click(function(){
		$("#return_reason-no").show();
		$("#return_reason-yes").hide();	
		
		$("#return_reason-yes").children("label").removeClass('required');
		$("#return_reason-yes").children("textarea").removeClass('required');
		$("#return_reason-no").children("label").addClass('required');
		$("#return_reason-no").children("ul").addClass('required');
		
	});
	$('#return-yes').click(function(){
		$("#return_reason-yes").show();	
		$("#return_reason-no").hide();
		$("#return_reason").addClass('required');
			if($("#noreturn_reason-list").hasClass('required')){
				$("#noreturn_reason-list").removeClass('required');
			}
		$("#noreturn_reason-list").find(".other").each(function(){
			$(this).removeClass('required');
											});
		$("#return_reason-yes").children("label").addClass('required');
		$("#return_reason-yes").children("textarea").addClass('required');
		
		$("#return_reason-no").children("label").removeClass('required');
		$("#return_reason-no").children("ul").removeClass('required');
			
	});
});

// Input Elements that need a calendar popup, but no calendar Icon, need a class of "makeitpopup"
	$(".makeitpopup2").click(function() {
		if($(this).is('.textfield')) {
			if($(this).is('.date-end')) {
				var arrive_string = $(this).parent().prev(".field").children(".date-begin").attr("value");
				var arrive_label = $(this).parent().prev(".field").children("label").html().replace(":","");
				//check to see if begin date has been set already and adjust disabled/current dates
				if (arrive_string != "mm/dd/yyyy" && arrive_string) {
					var arrive_array = arrive_string.split('/');
					var arrive_date = new Date(arrive_array[0]+'/'+arrive_array[1]+'/'+arrive_array[2]);
					var arrive_date = formatDate(arrive_date, "MM/dd/yyyy" );
					cal.clearDisabledDates();
					cal.addDisabledDates( null, arrive_date );
					cal.select(this,$(this).next().attr("id"),"MM/dd/yyyy", arrive_date);
					return false;
				}
				// begin date not set first, so pull label text and alert
				else {
					alert("Please select \"" + arrive_label + "\" first");
					if (document.all && window.ActiveXObject && !window.opera) { $(this).parents("form").find("select").css("visibility","visible"); }
					return false;
				}
			} else
				cal.select( this, $(this).next().attr('id'), "MM/dd/yyyy" );
		} else
			cal.select( this, this.id, "MM/dd/yyyy" );
		return false;
	});
	
	$('a#add-promo').toggle(function() {
		$('div#code-box').show();
		$(this).css('background-position', 'right 3px').parents('div#check-availability').addClass('check-long');
		return false; 
		}, function() { 
			$('div#code-box').hide();
			$(this).css('background-position', 'right bottom').parents('div#check-availability').removeClass('check-long'); 
			return false; 
		});
	
// sifr usage 
	// intPadding array order is: left, top, right, bottom - must match css for corresponding element

	$('div#content h2').sifr(
		{ strSWF: '/flash/claridge.swf', strColor: '#EAE7E5', strWmode: 'transparent', intPadding: [35, 8, 0, 10] },
		{ expressInstall: true }
	);

	$('fieldset#significant-other').hide();
	
	$('fieldset#child').hide();
	
	$('a#add-more-children').hide();

	
	
	$('fieldset#pet-preferences').hide();
	$('a#add-so').toggle(
	  function () {
		$('fieldset#significant-other').show();
	  },
	  function () {
		$('fieldset#significant-other').hide();
	  }
	);
	$('a#petpreferences').toggle(
	  function () {
		$('fieldset#pet-preferences').show();
	  },
	  function () {
		$('fieldset#pet-preferences').hide();
	  }
	);
	
	
/*	$('a.child-links').hide();
	$('a#add-child').toggle(
	  function () {
		$('fieldset#child').show();
		$('a.child-links').show();
		
	  },
	  function () {
		$('fieldset#child').hide();
		$('a.child-links').hide();
	  }
	);*/
	
	var theForm = $('#concierge-preference');
    $('form#concierge-preference fieldset.child').each(function() { $(this).hide(); });
    $('form#concierge-preference a.child-links').each(function() {
	if ($(this).attr('id') != 'child-0') {
	    $(this).hide();
	}
    });

    var childCounter = 0;
    $('a.child-links').toggle(
	function() {
	    if ( childCounter < 6 ) {
		childCounter++;
		$(this).next().show();
		$('#child-' + childCounter + '').show();
	    }
		if ( childCounter >= 6 ) {
			$('a#child-6').remove();
			}
	    return false;
	}, 
	function() {
	    $(this).next().hide();
	    $('#child-' + childCounter + '').hide();
	    childCounter--;
	});
	
	
	$('div.post-more-content').hide();
	$('a.post-read-more-btn').toggle(function() { 
		$(this).html('Read Less');									  
		$('div.post-more-content').slideDown();
		return false;
  	},function() {
		$(this).html('Read More');
		$('div.post-more-content').slideUp();
		return false;
	});
	
// Adds hover class for IE and animation for drop down nav - remove if not needed
	$("ul#nav-primary li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { 
		$("ul", this).hide();  
		} 
    );
    if (document.all) {
        $("ul#nav-primary li").hoverClass("over");
		$("ul#nav-primary li ul li").hoverClass("over");
    }


//code to rotate push marketing
	var count = $('ul#push-list li').size();
	
	$('ul#push-list li').not(':eq(0)').hide();
	$('ul#push-list li:eq(0)').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;
	});

});


// 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); }
		);
	});

};   
