$(function() {	
		   
	$('#modal-wrapper').jqm({closeClass:'jqmClose'}).jqmShow();	   
	$("div.photo-gallery").flash(
		{src:"flash/photo_gallery.swf",
		 width:466,
		 height:416,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"},
		 	function(htmlOptions) {
				htmlOptions.flashvars.configFile = "flash/xml/gallery_config.xml";
				htmlOptions.flashvars.xmlFile = "flash/xml/images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
			});

	$("div#wedding-gallery").flash(
		{src:"flash/wedding-photo-gallery.swf",
		 width:700,
		 height:546,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			function(htmlOptions) {
				htmlOptions.flashvars.configFile = "flash/xml/wedding-gallery_config.xml";
				htmlOptions.flashvars.xmlPath = "flash/xml/wedding-images.xml";
				$(this).html($.fn.flash.transform(htmlOptions));				
		});	

	
	if ($("body").is(".home")) {
		$("div#masthead-wrapper").flash(
			{src:"flash/homepage.swf",
			 width:721,
			 height:315,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"}
		);
	}
	else {
		//grab the body class if it's there - set a default in case it's not
		var temp = $("body").attr("class") || "section-0-overview";
		temp = temp.split("-");
		// get the number at the end to pass in flashvars below
		var section = temp[1];
		// if it's an overview page, make it a flash masthead
		var flash = (temp[2]=='overview'?true:false);
		if (flash) {
			$("div#masthead-wrapper").flash(
				{src:"flash/masthead.swf",
				 width:721,
				 height:259,
				 wmode:"transparent",
				 quality:"high"},
				 {version:"8"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					htmlOptions.flashvars.theSection = section;
					$(this).html($.fn.flash.transform(htmlOptions));
				}
			);
		}
	}
	//$("a").click(function(){return false;});


	// intPadding array order is: left, top, right, bottom - must match css for corresponding element
	$('div#content h1').sifr(
		{ strSWF: 'flash/futura-medium-bt.swf', strColor: '#ffffff', strLinkColor: '#ffffff', strHoverColor: '#ffffff', strWmode: 'transparent', strCase: 'normal' },
		{ expressInstall: true }
	);
	

	//Video Specifications
	$('#utility-video-tour a').click(function() {
		window.open( "http://www.vfmii.com/exc/aspquery?command=invoke&ipid=1066879&ids=54679", "", "scrollbars=no, status=no, location=no, height=457, width=556, toolbar=no, menubar=no, directories=no, resizable=no");
		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() { } 
    );*/
    //if (document.all) {
        $("ul#nav-primary li").hoverClass("over");
		$("ul#nav-primary li ul li").hoverClass("over");
    //}

	//PNG fix for IE
	$('.png-bg-fix').ifixpng();

    $('#survey').each(function() {
	// since we cant edit the markup directly.. 
	var first = $('div:first', this),
	    firstLabel = $('<div class="label-first survey-headings"><strong>Prior to your stay:</strong><div class="labels"><label class="expectations">Exceeded Expectations</label><label class="not-expectations">Did Not Meet Expectations</label></div></div>'),
	    secondSet = $('input:text:eq(0)').parents('.field').next(),
	    secondLabel = $('<div class="label-second survey-headings"><strong>During your stay:</strong><div class="labels"><label class="expectations">Exceeded Expectations</label><label class="not-expectations">Did Not Meet Expectations</label></div></div>'),
		/*
		<div class="labels">
		<label class="label-location">Location</label>\
		<label class="label-eco">Eco</label>\
		<label class="label-prince">Prince</label>\
		<label class="label-osteria">Osteria</label>\
		<label class="label-terra">Hotel Terra</label>
		</div>) */
	    thirdSet = $('#div_3328bdf9a4b9504b9398284244fe97c2'),
	    thirdLabel = $('<div class="label-third survey-headings"><strong>Reflecting on your stay:</strong><div class="labels"><label class="expectations">Exceeded Expectations</label><label class="not-expectations">Did Not Meet Expectations</label></div></div>');

	    $(first).before(firstLabel);
	    $(secondSet).after(secondLabel);
	    $(thirdSet).before(thirdLabel)

	    $('input.button', this).wrap('<div class="button"></div>');
    });

$('ul#update-items li a').hover(function(){
			$('ul#update-items li div.update-popup').hide();
			elemPos = this;
			$(this).parent().children('div.update-popup').show();
		},function(){
			$('ul#update-items li div.update-popup').hide();
		});

 		$('#mycarousel').jcarousel({
			auto: 3,
			scroll: 1,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
		
$('.follow-link').initializeFollowing();


	//MSN Map
	var openFn=function(hash){
		hash.w.show();
		var difference = $(window).width() - $('#msnmap-wrapper').width();
		difference = difference / 2;
		$('#msnmap-wrapper').css({left:difference+275,top:$(window).scrollTop()+10});
		$('#map').msnMap({listView:true,hotelOnly:true});
		setTimeout(function() {
			$('.place:eq(0) .name').click();
		}, 500);
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$("#view-map-btn").each(function() {
		$('#msnmap-wrapper').jqm({trigger:'#view-map-btn', onShow: openFn, onHide: hideFn});
	});

});

$.fn.initializeFollowing = function() {
	return this.each(function() {
		$('.follow-link').live('click',function(event) {
			event.preventDefault();
			$('.follow-panel').hide();
			$(this).siblings('.follow-panel').css('display','inline');
		});
		$('.follow-close').live('click',function(event){
			event.preventDefault();
			$(this).parent().slideUp('fast');
		});
	});
};

// 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 mycarousel_initCallback(carousel){
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};
