$(function() {
	//Documentation located in special.docs.js
	
	// H1 sifr
	$('div#content h1').sifr(
		{ strSWF: '/flash/mrs-eaves-allcaps.swf', strColor: '#140b01', strLinkColor: '#140b01', strHoverColor: '#140b01', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=left&letterSpacing=2&' },
		{ expressInstall: true }
	);
	
	// Find first letter of every first p in content

	$("div#content").each( function() {
		var first_paragraph = $('h2 + p')[0];
		if (!first_paragraph) return false;
		var text = first_paragraph.firstChild.nodeValue;
        if(text){	
		    var first_letter = text.substr(0,1);
		    if (first_letter == '\n') {
			    first_letter=text.substr(1,1);
			    first_paragraph.firstChild.nodeValue = text.slice(2);
		    } else {
			    first_paragraph.firstChild.nodeValue = text.slice(1);
	    
		    }
        }
		if ( text ) {
			$('h2 + p').prepend('<span class="first">'+first_letter+'</span>');
		}
	});

	// Find first letter of every page without an h2
	$("div#content").each( function() {
		var first_paragraph_withouth = $('#page-header-crumbs-wrapper + p')[0];
		if (!first_paragraph_withouth) return false;
		var text = first_paragraph_withouth.firstChild.nodeValue;	
		first_letter_withouth = text.substr(0,1);
		if (first_letter_withouth == '\n') {
			first_letter_withouth=text.substr(1,1);
			first_paragraph_withouth.firstChild.nodeValue = text.slice(2);
		} else {
			first_paragraph_withouth.firstChild.nodeValue = text.slice(1);
	
		}
		if ( text ) {
			$('#page-header-crumbs-wrapper + p').prepend('<span class="first">'+first_letter_withouth+'</span>');
		}
	});
	
	// Homepage JS for push marketing hover effect


	$(".push-hover-content").hide();
	$("#homepage-push li").each( function() {
		var x = $(this);
		x.hover(
		function() {
			$(this).addClass("hover-effect").css("z-index","10");
			$(".push-hover-content", x).show();
		},
		function() {
			$(this).removeClass("hover-effect").css("z-index","1");
			$(".push-hover-content", x).hide();
		});
	});

	// Home push marketing js
	$("body.home").each( function() {
		$('#homepage-push').jcarousel();
	});
	
	
	// CSS IE6 min-height hack was not working so wrote some js for IE6 to make it work
	
	if($.browser.msie){
		var x = $("div#content").height();
		x = parseInt(x,10);
		if (x < 390) { $("div#content").css("height","390px");	};
	};

	//MSN Map
	var openFn=function(hash){
		hash.w.show();
		var difference = $(window).width() - $('#map-jqmodal').width();
		difference = difference / 2;
		$('#map-jqmodal').css({left:difference+275,top:$(window).scrollTop()+10});
		$('#map').msnMap({listView:true, hotelOnly: true});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$("#msnmap").each(function() {
		$('#map-jqmodal').jqm({trigger:'#msnmap', onShow: openFn, onHide: hideFn});
	});

	
	
	// JS for Plan your stay form
	
	$("#courses_filters li").each(function() {
		var x = $(this);
		$(".activity-click", x).click( function() {
		 	if ( $(this).is(':checked') ) {
				$(".activity-details", x).show();
			} else {
				$(".activity-details", x).hide();
			};
		});
	});
	
	// JS for golf course pages
	
	$("#golf-details-content").hide();
	$("#golf-tables-wrapper").each( function() {
		$("#golf-details a").toggle( function() {
			$(this).text("Hide Details").addClass("open").removeClass("close");
			$("#golf-details-content").slideDown("slow");
			}, function() {
			$(this).text("Show Details").addClass("close").removeClass("open");
			$("#golf-details-content").slideUp("slow");
		});
	});
		
	// jqmodal for golf course pages popup and other pages


	$("#golf-tables-wrapper").each( function() {

		$('#golf-jqmodal').jqm({trigger:'#golf-video-click'});
		$('#golf-pic-jqmodal').jqm({trigger:'#golf-photo-click'});

		var x = $(".jqmWindow");
		var fid = $(".golf-flash", x).attr('id').slice(11);
		fid = parseInt(fid);

		$("div#vid-course-"+fid).flash(
			{src:"flash/videoGallery-slideshow.swf",
			 width:435,
			 height:390,
			 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.xmlFile = "flash/video-slideshow-course"+fid+".xml";
					//htmlOptions.flashvars.langXML="/flash/xml/i18n/"+LANG+"_formLabels.xml";
					//htmlOptions.flashvars.browser = BROWSER;  //Used for SSP Postcard feature, comment out if not needed.
					$(this).html($.fn.flash.transform(htmlOptions));
			});
	
		$("div#pic-course-"+fid).flash(
			{src:"flash/photoGallery-slideshow.swf",
			 width:435,
			 height:390,
			 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.xmlFile = "flash/slideshow-golf-course"+fid+".xml";
					//htmlOptions.flashvars.langXML="/flash/xml/i18n/"+LANG+"_formLabels.xml";
					//htmlOptions.flashvars.browser = BROWSER;  //Used for SSP Postcard feature, comment out if not needed.
					$(this).html($.fn.flash.transform(htmlOptions));
			});
				
	});

	$("#other-tables-wrapper").each( function() {
		$('#other-jqmodal').jqm({trigger:'#other-photo-click'});
		var x = $(".jqmWindow");
		var fid = $(".other-flash", x).attr('id');
	$("div#"+fid).flash(
			{src:"flash/photoGallery-slideshow.swf",
			 width:435,
			 height:390,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"},
				function(htmlOptions) { 
					htmlOptions.flashvars.xmlFile = "flash/slideshow-"+fid+".xml";
					$(this).html($.fn.flash.transform(htmlOptions));
			});
	});
	
	$('#other-video-jqmodal').jqm({trigger:'#other-video-click'});	
	$(".video-wrapper").each( function() {
	var fid = $(this).attr('id');
	$("div#"+fid).flash(
			{src:"flash/videoGallery-slideshow.swf",
			 width:435,
			 height:390,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"},
				function(htmlOptions) { 
					htmlOptions.flashvars.xmlFile = "flash/video-slideshow-"+fid+".xml";
					$(this).html($.fn.flash.transform(htmlOptions));
			});
										  });
	// Email push flash
	
			$("#email-signup-flash").flash(
			{src:"flash/email-form.swf",
			 width:217,
			 height:320,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"8"});
						
			
	// Homepage Flash
	
	$(".home div#masthead").flash(
			{src:"/flash/home-masthead.swf",
			 width:763,
			 height:369,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"9"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					//htmlOptions.flashvars.epostConfigXML = "/flash/xml/epostConfig.xml";
					htmlOptions.flashvars.xmlFile = "/flash/xml/home-masthead.xml";
					//htmlOptions.flashvars.langXML="/flash/xml/i18n/"+LANG+"_formLabels.xml";
					//htmlOptions.flashvars.browser = BROWSER;  //Used for SSP Postcard feature, comment out if not needed.
					$(this).html($.fn.flash.transform(htmlOptions));
			});
	

	// Golf site flashes

	$("div#pine-straw-shot").flash(
		{src:'/flash/PunchShot_PineGrass.swf',
		width:400,
		height:267,
		wmode:'transparent',
		quality:'high'},
		{version:'8'});
		
	$("div#putting-around-green").flash(
		{src:'/flash/PutToThePin.swf',
		width:400,
		height:267,
		wmode:'transparent',
		quality:'high'},
		{version:'8'});
	$("div#love-grass-recovery").flash(
		{src:'/flash/Instructor_Lovegrass2.swf',
		width:400,
		height:267,
		wmode:'transparent',
		quality:'high'},
		{version:'8'});

	$("div#golf-improvement-1").flash(
		{src:'/flash/golf-video-1.swf',
		width:400,
		height:340,
		wmode:'transparent',
		quality:'high'},
		{version: '8'});
	
	$('div#golf-improvement-2').flash(
		{src:'/flash/golf-video-2.swf',
		width:400,
		height:340,
		wmode:'transparent',
		quality:'high'},
		{version: '8'});
	
	// Packages share button JS
	
	$(".package-wrapper").each( function() {
		var x = $(this);
		$("a.share-link", x).click( function() {
			$(".share-panel", x).show();
		});
		$("a.share-close", x).click( function() {
			$(".share-panel", x).slideUp();
		});
	});
	
	// js for top site nav
	
	$("#nav-primary").each( function() {
		$("#site-pinehurst a").css("background-position","0 0");
	});
	
	$("#golf-nav-primary").each( function() {
		$("#site-golf-academy a").css("background-position","0 0");
	});
	
	// js hack for ie required icon for select fields
	
	/*
	if ($.browser.msie) {
		$(".field").each( function() {
			var x = $(this);				   
			$("select.required", x).each( function() {
				$("label", x).parents(".field").prepend('<img class="ie-required" src="/images/icon-required.gif" alt="" border="0" />');
			});
		});
	};
	*/
	
	// Homepage js for body bottom bar
	
	/*$("body.home").each( function() {
		$(this).append('<div id="home-bottom-bar"></div>');
	});*/

	// Directions page js

	$(".directions-info-wrapper").each( function() {
		$(".directions-info-details").hide();
		var x = $(this);
		$("a.directions-link", x).toggle( function() {
			$(".directions-info-details", x).slideDown();
			return false;
		}, function () {
			$(".directions-info-details", x).slideUp();
			return false;
		});
	});
	
	// Quat nav js hack
	
	$("#tertiary-north-south-tournament").each( function() {
		if ( $(this).hasClass("current") ) {
			$(this).css("background-image","none");
		};
	});
	
	// JS for golf tournaments
	
	$(".golf-tournament-details").hide();
	$(".golf-tournament-wrapper").each( function() {
		var x = $(this);
		$("a.tournament-details", x).toggle( function() {
			$(".golf-tournament-details", x).slideDown();
		}, function () {
			$(".golf-tournament-details", x).slideUp();
		});
	});
	
	// JS for the holiday schedule page
	
	$(".holiday-details").hide();
	$(".holiday-schedule-wrapper").each( function() {
		var x = $(this);
		$(".holiday-details-click", x).toggle( function() {
			$(".holiday-details", x).slideDown();
		}, function() {
			$(".holiday-details", x).slideUp();
		});
	});
	
	// Resort map flash
	
	$("#resort-map-wrapper").each( function() {
		var openFn=function(hash){
			hash.w.show();
			var difference = $(window).width() - $('#resort-map-wrapper').width();
			difference = difference / 2;
			$('#resort-map-wrapper').css({left:difference+275,top:$(window).scrollTop()+20});
		};
		$("#utility-resort-map a").addClass("jqmodal");
		$('#resort-map-wrapper').jqm({trigger:'#utility-resort-map a',onShow: openFn});
		$("#secondary-resort-map").each(function() {
			$("#secondary-resort-map a").click(function(){
				$("#utility-resort-map a").trigger('click');
				return false;
			});
		});
		$("div#resort-map-flash").flash(
				{src:"/flash/resort-map.swf",
				 width:960,
				 height:578,
				 wmode:"transparent",
				 quality:"high"},
				 {version:"8"},
					function(htmlOptions) { //Use this to specify a query string, take out if not needed.
						htmlOptions.flashvars.xmlFile = "/flash/xml/resort-map.xml";
						$(this).html($.fn.flash.transform(htmlOptions));
				});
	});
	
	/* adds "odd" class to odd rows in tables */
	
	$("table tr:nth-child(odd)").addClass("odd");
	
	// Generic JS for any type of listing (that has an id "show-hide-animation-list") that needs the show/hide animation
	$(".animation-list-item-details").hide();
	$(".show-hide-animation-list li").each( function() {
		var x = $(this);
		$("a.animation-click",x).toggle( function() {
			$(".animation-list-item-details",x).slideDown();
		}, function() {
			$(".animation-list-item-details",x).slideUp();
		});
	});	
	
    
    $(".animation-link").hide();
    $(".animation-list-item-details").each(function(){
        var aLink = $(".animation-link",this);
        if (aLink.text()!='') {
            var readMore = $('<a/>').attr('href',aLink.text()).text('Read More');
            $(this).append(readMore);
        }
    });

    window.GetFlashMap = function() {
	$('#utility-resort-map a').trigger('click');
    };
	
	$("#video-2014-wrapper").each(function(){
		var openVid=function(hash){
			hash.w.show();
			var difference = $(window).width() - $('#video-2014-wrapper').width();
			difference = difference / 2;
			$('#video-2014-wrapper').css({left:difference,top:$(window).scrollTop()+10});
			$("div#watch-video-2014").flash(
				{ src:"/flash/US-Open-video.swf",
					width:640,
					height:405,
					wmode:"transparent",
					quality:"high"
				}, {version:"9"});
		};
		var hideVid=function(hash){
			$("div#watch-video-2014").html('');
			hash.w.hide()
			hash.o.remove();
		};

		/*$("div#watch-video-2014").flash(
			{ src:"/flash/US-Open-video.swf",
				width:640,
				height:405,
				wmode:"transparent",
				quality:"high"
			}, {version:"9"});*/
		$("#video-2014-wrapper").jqm({trigger:'#video-2014-click', onShow: openVid, onHide: hideVid});
	});
	
});


function resizeSwf(size) {
	if ( size == 30 ) {
		$("#email-signup-flash").css("height","30px");
	} else {
		$("#email-signup-flash").css("height","320px");
	}
}
