$(function() {

	
	//Global variables
	for(var i in $.browser) {
		if ($.browser[i])
			BROWSER = i + (($.browser.msie)?$.browser.version.charAt(0):'');
	}
	
	var pagepath = window.location.pathname;
	var pagehref = pagepath.substring(pagepath.lastIndexOf('/') + 1);	
	if ( (pagehref == 'washington-state-vacation-rentals.php')  || (pagehref == 'accomm-search-results.php') || (pagehref == 'accomm-search-details.php'))
		$('#res-console').tabs(2);
	else
		$('#res-console').tabs();
	
	$("button.submit").hover( function() { $(this).css("background-position", "0 -51px"); }, function () { $(this).css("background-position", "0 0px"); });

	// Sifr
		$('div#weekly-photos h2').sifr( { strSWF: 'flash/scalasansot-regular.swf', strColor: '#4f8628', strWmode: 'transparent' }, { expressInstall: true } );
	$('div#content h2').sifr( { strSWF: 'flash/scalasansot-regular.swf', strColor: '#b48027', strWmode: 'transparent' }, { expressInstall: true } );
	$('h4.weather-day').sifr( { strSWF: 'flash/arial.swf', strColor: '#bc8f40', strWmode: 'transparent', strFlashVars: 'textalign=center&', strCase: 'upper' }, { expressInstall: true } );
	$('div#content h3.spa-treatments-header').sifr( { strSWF: 'flash/scalasansot-regular.swf', strColor: '#5d9631', strWmode: 'transparent', strCase: 'upper' }, { expressInstall: true } );

	// Flash
	$("body.home div#masthead").flash( {src:"flash/home-winter.swf", width:857, height:325, wmode:"transparent", quality:"high"}, {version:"8"});
	if($("div#resort-masthead")){
		$("div#resort-masthead").flash(
		{src:"flash/masthead2.swf",
		 width:857,
		 height:325,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			function(htmlOptions) {
				htmlOptions.flashvars.xmlPath = "flash/xml/real-estate.xml";
				$(this).html($.fn.flash.transform(htmlOptions));				
		});
		$('#header-real-estate').hide();
	}
	$("div#trail-map").flash( {src:"suncadia-map-shell.swf", width:651, height:390, wmode:"transparent", quality:"high"}, {version:"8"});
	$("div#village-map").flash( {src:"suncadia-map-village.swf", width:585, height:342, wmode:"transparent", quality:"high"}, {version:"8"});
	$("div#flash-video").flash( {	src:"flash/VillageAnimationLoRes.swf", width:600, height:442, wmode:"transparent", quality:"high"}, {version:"7"});
	$("div#dhr-logo").flash( {src:"flash/flash_logoDhr.swf?link=suncadiaresort", width:250, height:25, wmode:"transparent", allowScriptAccess:"always", quality:"high"}, {version:"7"});
	$("div#flash-special-offer").flash( {src:"flash/form.swf", width:250, height:555, wmode:"transparent", quality:"high"}, {version:"7"});
	$("div#flash-inset-special-offer").flash( {src:"flash/form.swf", width:250, height:555, wmode:"transparent", quality:"high"}, {version:"7"});
	$("div#video-popup").flash( {src:"flash/fox-news.swf", width:370, height:298, wmode:"transparent", quality:"high"}, {version:"7"});
	$("div#interactive-map").flash( {src:"flash/flashMap01.swf", width:800, height:620, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlFile = "flash/xml/mainNav.xml";
			$(this).before($.fn.flash.transform(htmlOptions));						
	});

	$("div#resort-gallery").flash( {src:"flash/photo_gallery.swf", width:466, height:420, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.configFile = "flash/xml/gallery_config.xml";
			htmlOptions.flashvars.xmlFile = "flash/xml/images.xml";
			$(this).before($.fn.flash.transform(htmlOptions));						
	});
	$("div#meetings-gallery").flash( {src:"flash/photo_gallery.swf", width:466, height:420, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.configFile = "flash/xml/gallery_config_meetings.xml";
			htmlOptions.flashvars.xmlFile = "flash/xml/images_meetings.xml";
			$(this).before($.fn.flash.transform(htmlOptions));						
	});


	$("body.home form#eclub-signup input").focus( function() { $(this).val(""); } );

	/*$("div.real-estate").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/real-estate.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});*/
	$("div.property").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/property-choices.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	})
	$("div.developers").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/developers.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	$("div.club").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/suncadia-club.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	$("div.contact").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/contact-us.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	$("div.current-listings").flash( {src:"flash/masthead.swf", width:855, height:325, wmode:"transparent", quality:"high"}, {version:"8"},
		function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "flash/xml/current-listings.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	
	$("div#real-estate-map").flash( {src:"main.swf", width:895, height:692, wmode:"transparent", quality:"high"}, {version:"8"});
	$("div#real-estate-map-flash").flash( {src:"/flash/real-estate-map.swf", width:598, height:352, wmode:"transparent", quality:"high"}, {version:"8"});
	
	// Inset Flash
	$("div#golf-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "golf/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#recreation-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "recreation/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#accommodations-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "accommodations/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#dining-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "dining/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#meeting-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "meeting/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#real_estate-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "real_estate/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#resort_overview-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "resort_overview/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#spa-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "spa/";
			$(this).html($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#specials_packages-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "specials_packages/";
			$(this).before($.fn.flash.transform(htmlOptions));						
		}
	);
	$("div#outdoor_activities-inset-flash").flash( { src:"flash/seasonal_rh_slide.swf", width:250, height:215, wmode:"transparent", quality:"high"}, {version:"7"},
		function(htmlOptions) {
			htmlOptions.flashvars.section = "outdoor_activities/";
			$(this).before($.fn.flash.transform(htmlOptions));
		}
	);
	//Popup window for interactive map
	$('a.pop-up').click( function () {
		var pLink = this.href;
		window.open( pLink,'PopUp','width=800,height=620, scrollbars=no')
		return false;
		});

	//Shows and hides disclaimer info for photo submission
	$('div.terms').hide();
	$('a.toggle').toggle(function(){ 
	  $(this).parents('li').children('.terms').show();
	  return false;
	},function(){ 
	  $(this).parents('li').children('.terms').hide();
	  return false;
	});


	$("ul#nav-primary li").hover(
        function(){ $("ul", this).show(); }, 
        function() { $("ul", this).hide();  } 
    );
    if (document.all) {
        $("ul#nav-primary li").hoverClass("over");
		$("ul#nav-primary li ul li").hoverClass("over");
    }
	
	//booking console
	
	$('.toggle-promo').click(function(){
		var theID = $(this).attr("id");
		if ( (theID == "done-promo") || (theID == "close-promo") ) {
			$("#promo-console").hide();
			if (BROWSER=='msie6') { $('select').show(); }
		} else {
			$("#promo-console").show();
			if (BROWSER=='msie6') { $('select').hide(); }
		}
		//Checks promo form values - shows green checkmark
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$('#complete-promo').show();
		}
		else {
			$('#complete-promo').hide();
		}
		return false;
	});
	
	


// General Toggelr
	$('.toggle-details').hide();
	$(".toggle-wrapper a.toggler").toggle(function() {
		$(this).parents(".toggle-wrapper").find(".toggle-details").animate({
			height: 'show'
			/*opacity: 'show'*/
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Hide Details");
	}, function() {
		$(this).parents(".toggle-wrapper").find(".toggle-details").animate({
			height: 'hide'
			/*opacity: 'hide'*/
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("View Details");
	});


	$(this).find("div#prospector-course-map").each(function() {
		var s1 = new SWFObject("flash/prospector/flvplayer.swf","single","600","320","7");
		s1.addParam("allowfullscreen","true"); 
		s1.addVariable("file","flash/prospector/content.xml"); 
		s1.addVariable("image","preview.jpg"); // Name and location of the preview image.
		s1.addVariable("autostart","true"); //Determines if flyover plays automatically. Set to True or False
		s1.addVariable("repeat","list"); //Determines if flyover repeats. Set to True or False
		s1.addVariable("shuffle","false"); //Set to false to play holes in order.  Set to true to play the holes in random order.
		s1.addVariable("showdownload","true"); //Shows or hides the Download Icon. Set to True of False.
		s1.addVariable("showicons","true"); //Shows or hides the Play/Pause button in the middle of the screen. Set to True of False.
		s1.addVariable("thumbsinplaylist","true"); // Shows or hides the thumbnails in the playlist
		s1.addVariable("linktarget","_blank"); //Sets the type of link when clicked.  DO NOT CHANGE
		s1.addVariable("showvolume","true"); //Shows or hides the volume Icon. Set to True of False.
		s1.addVariable("frontcolor","0x1D3214"); //Sets the color of the player buttons and text. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("backcolor","0xB1CB99"); //Sets the background color of the player. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("lightcolor","0x1D3214"); //Sets the rollover color of the player. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("displaywidth","400"); 
		s1.addVariable("bufferlength","10");
		s1.write("player1");
	});

	$(this).find("div#rider-course-map").each(function() {
		var s1 = new SWFObject("flash/roperider/flvplayer.swf","single","600","320","7");
		s1.addParam("allowfullscreen","true"); 
		s1.addVariable("file","flash/roperider/content.xml"); 
		s1.addVariable("image","preview.jpg"); // Name and location of the preview image.
		s1.addVariable("autostart","true"); //Determines if flyover plays automatically. Set to True or False
		s1.addVariable("repeat","list"); //Determines if flyover repeats. Set to True or False
		s1.addVariable("shuffle","false"); //Set to false to play holes in order.  Set to true to play the holes in random order.
		s1.addVariable("showdownload","true"); //Shows or hides the Download Icon. Set to True of False.
		s1.addVariable("showicons","true"); //Shows or hides the Play/Pause button in the middle of the screen. Set to True of False.
		s1.addVariable("thumbsinplaylist","true"); // Shows or hides the thumbnails in the playlist
		s1.addVariable("linktarget","_blank"); //Sets the type of link when clicked.  DO NOT CHANGE
		s1.addVariable("showvolume","true"); //Shows or hides the volume Icon. Set to True of False.
		s1.addVariable("frontcolor","0x1D3214"); //Sets the color of the player buttons and text. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("backcolor","0xB1CB99"); //Sets the background color of the player. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("lightcolor","0x1D3214"); //Sets the rollover color of the player. Replace hex color value after Ox. Eg. White would be 0xFFFFFF
		s1.addVariable("displaywidth","400"); 
		s1.addVariable("bufferlength","10");
		s1.write("player1");
	});

	//Striping Tables
	$("table.striped tbody tr:nth-child(odd)").addClass("tr-odd");

	$("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");

	// Fancybox
	$(".zoom-in").each(function(){$(this).fancybox();});
	
	$('.unit-gallery').each(function() {
		var obj = $(this); //for gallery
		var index = 0;
		var count = $('.img a', obj).length;
		$("span.gallery-count", obj).html(count);
		$('.img-move', obj).click(function() {
			if($(this).is('#img-last'))
				index--;
			else
				index++;
			if(index<0) index = count-1;
			if(index==count) index = 0;
		
			var newImg = $('#img a:eq('+index+')', obj).attr('href');
			$('.img a:eq('+index+')', obj).show().siblings().hide(); //Hides other images when you click next
			$('.count', obj).html((index+1)+' of '+count); // Adds text for [image #] of [total # of images]
			return false;
		});
									 
	});
	
	// For Each Package Wrapper add a Toggle Function if Neccessary
	$("div.package-landing-content").each(function() {
		// Div for the Toggler to be Held
		var packlong = $(this).children('div.package-long').html();
		if( packlong != null ) {
			$(this).append("<div class=\"package-landing-toggle\">");
			$(this).find("div.package-long").hide();
			$(this).find(".package-landing-toggle").append("<a href=\"#\">View Details</a>");
		}
	});
	
	// Once the Package Toggler Control is clicked
	// Toggle the details and chance the text
	$("div.package-landing-toggle a").toggle(function() {
		$(this).parents().parents("div.package-landing-wrapper").find("div.package-long").animate({
			height: 'show'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Hide Details");
	}, function() {
		$(this).parents().parents("div.package-landing-wrapper").find("div.package-long").animate({
			height: 'hide'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("View Details");
	});
	$('div#controls').hide();
	$("#mycarousel").each(function(){
	    $("#mycarousel").jcarousel({
            scroll: 1,
            initCallback: mycarousel_initCallback,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    });
	
	
	
	
});


function mycarousel_initCallback(carousel) {
	
	if(carousel.size() > 1)
		$('div#controls').show();
	
    $('#btn-next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#btn-prev').bind('click', function() {
        carousel.prev();
        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); }
		);
	});

};   
