$(function() {
	 //fall-promo lightbox
		$("#fall-promo-modal").each(function() {
		var windowWidth = ($(window).width()-$(this).width())/2;
		$(this).css('left',windowWidth);
		$(this).css('top','120px');
		$(this).jqm({closeClass:'fall-promo-close,'}).jqmShow();
	}); 
	 
	
	$('div#content h1').sifr({ strSWF: '/flash/claridge-italic.swf', strColor: '#EADDC5', strWmode: 'transparent' },{ expressInstall: true });

	$('div#home-push-wrapper ul#home-push').jcarousel({
		scroll: 1
	});
	
	$('.toggle-promo').click(function(e){
		e.preventDefault();
		$('#promo-codes').toggle(0,function(){
			if($(this).is(':visible')) {
				$('#group-code').focus();
				$('.toggle-promo').css("background-position","0px -23px");
			}
			else {
				$('.toggle-promo').css("background-position","0px 0px");				
			}
		});
	});

	$("div.accommadation-wrapper").each(function(){
		$('div.accommodation-content').hide();
		var x = $(this);
      $("h3 a.show-it",x).toggle(function(){
           $('div.accommodation-content', x).slideDown();
           $(this).addClass("active");
      }, function() {
           $('div.accommodation-content', x).slideUp();
           $(this).removeClass("active");
      });
	});


	$('div#promo-codes a').click(function(e){
		e.preventDefault();
		$('#promo-codes').hide();
	});	
	
	$("#special-offers-signup .textfield, #blog-comment .textfield").unbind('focus').unbind('blur');
	
	
	
	$('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();
	  }
	);
	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--;
	});
	
    var xml = $('#home-masthead').attr('rel');
    if(xml==''){
        xml = 'home-masthead-main.xml';
    } 
	$('#home-masthead').html('').flash({
        swf:"flash/home-masthead.swf",
        width:"100%",
        height:"486",
        params:{
            allowscriptaccess:"always",
            wmode:"transparent",
            flashvars:{
                xmlPath:'flash/xml/'+xml
            }
        }
    });
	
	$('#photo-gallery').html('').flash({
        swf:"flash/photo-gallery.swf",
        width:"639",
        height:"402",
        params:{
            allowscriptaccess:"always",
            wmode:"transparent",
            flashvars:{
                xmlPath:'flash/xml/images.xml',
				epostConfigXML:'/flash/xml/epostConfig.xml',
				gatewayURL:'/flashservices/gateway.php'
            }
        }
    });
	
	$('#wedding-photo-gallery').html('').flash({
        swf:"flash/wedd-photo-gallery.swf",
        width:"639",
        height:"402",
        params:{
            allowscriptaccess:"always",
            wmode:"transparent",
            flashvars:{
                xmlPath:'flash/xml/wedding-images.xml',
				epostConfigXML:'/flash/xml/epostConfig.xml',
				gatewayURL:'/flashservices/gateway.php'
            }
        }
    });
	
	$('#meeting-space-map').html('').flash({
        swf:"flash/meeting-map.swf",
        width:"639",
        height:"402",
        params:{
            allowscriptaccess:"always",
            wmode:"transparent",
            flashvars:{
                xmlPath:'flash/xml/meeting-map.xml'
            }
        }
    });

	$('#wedding-gallery-ashley-rhian').html('').flash({
        swf:"flash/gallery/ashley-rhian/ashley-rhian-gallery.swf", width:"674", height:"428",
        params:{
            allowscriptaccess:"always", wmode:"transparent",
            flashvars:{
                xmlPath:'flash/gallery/ashley-rhian/xml/images.xml'
            }
        }
    });
	
	$('#wedding-gallery-christina-ryan').html('').flash({
        swf:"flash/gallery/christina-ryan/christina-ryan-gallery.swf", width:"674", height:"428",
        params:{
            allowscriptaccess:"always", wmode:"transparent",
            flashvars:{
                xmlPath:'flash/gallery/christina-ryan/xml/images.xml'
            }
        }
    });
	
	$('#wedding-gallery-jennifer-griff').html('').flash({
        swf:"flash/gallery/jennifer-griff/jennifer-griff-gallery.swf", width:"674", height:"428",
        params:{
            allowscriptaccess:"always", wmode:"transparent",
            flashvars:{
                xmlPath:'flash/gallery/jennifer-griff/xml/images.xml'
            }
        }
    });
	
	$('#wedding-gallery-ruchi-chris').html('').flash({
        swf:"flash/gallery/ruchi-chris/ruchi-chris-gallery.swf", width:"674", height:"428",
        params:{
            allowscriptaccess:"always", wmode:"transparent",
            flashvars:{
                xmlPath:'flash/gallery/ruchi-chris/xml/images.xml'
            }
        }
    });
	
	
	



	if ( window.location.hash != '#blog-comment-form') {
		$('#blog-comment').hide();
	};
	
	$('.add-comment-toggle').click(function(){
      if($('#blog-comment').is(':visible')){
        $('#blog-comment').slideUp();
      }else{
		  $('#blog-comment').slideDown();
	  }
	});
	
	//Bing map
	var openFn=function(hash){
		hash.w.show();
		var leftPos = ($(window).width()-$('#map-jqmodal').width())/2;
		var topPos = Math.max($(window).scrollTop(),parseInt($('#map-jqmodal').css('top')));
		$('#map-jqmodal').css({left:leftPos,top:topPos});
		$('#map').msnMap({listView:true, hotelOnly: true});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$('#map-jqmodal').jqm({trigger:'#btn-msnmap', onShow: openFn, onHide: hideFn});
	
	//Interactive Golf Map
	
	$('#golf-course-map').each(function() {
	
		var initial = false;
		window.log=function(msg){ if (window.console)console.log(msg)}
	
		function hideSiblingsExcept( el ) {
		$('#golf-course-content').scrollTo( el, 1337, {axis:'x'} );
		}
			var firstTab = $('#golf-course-navigation', this).find('a:first'),
			open = firstTab.attr('href').slice(1),
			content = $('#golf-course-content');
	
		$('#control-prev').hide();
		hideSiblingsExcept( $('#' + open ) );
		$(firstTab).parent().addClass('currentCourse');
	
		$('#golf-course-navigation li').each(function() {
			if ( !$(this).prev().length ) {
			$(this).addClass('first');
			} else if ( !$(this).next().length ) {
			$(this).addClass('last');
			}
		});
	
		$('#golf-course-navigation a').click(function(e) {
		e.preventDefault();
		$(this).parent().addClass('currentCourse').siblings().removeClass('currentCourse');
		var id = '#' + $(this).attr('href').slice(1);
		hideSiblingsExcept( $( id ) );
	
		if ( $('.currentCourse').is('.last') ) {
			$('#control-next').hide();
			$('#control-prev').show()
		} else if ( $('.currentCourse').is('.first') ) {
			$('#control-prev').hide();
			$('#control-next').show();
		} else {
			$('#control-prev, #control-next').show();
		}
		});
	
		$('#golf-course-controls a').each(function() {
		$(this).click(function(e){
			log('clicked')
			e.preventDefault();
			if ( $(this).parent().is('#control-next') ) {
			log('next')
			$('.currentCourse').next().find('a').trigger('click');
			} else {
			log('else')
			$('.currentCourse').prev().find('a').trigger('click');
			}
		});
		});
	
	});
	
	$('.partner').each(function(){
		$(this).children('.partner-details').hide();
	});

	$('.partner .toggle').click(
      function (event) {
		  event.preventDefault();
		  if($(this).siblings('.partner-details').is(':visible')){ 
		  	$(this).siblings('.partner-details').slideUp('slow');
			$(this).removeClass('active');
		  } else {
			  $(this).siblings('.partner-details').slideDown('slow');
			  $(this).addClass('active');
		  }
      }
    );
	
	//What's the Buzz - Article Scroller
	$('ul#news-scroller').jcarousel({scroll: 5});
	
	//Video Page Modal
	var openFn=function(hash){
		hash.w.show();
		var leftPos = ($(window).width()-$('#video-modal').width())/2;
		var topPos = ($(window).scrollTop())+(($(window).height()-$('#video-modal').height())/2);
		$('#video-modal').css({left:leftPos,top:topPos});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
	};
	$('#video-modal').jqm({trigger:'.thumb', onShow: openFn, onHide: hideFn});
	
	$('.video-summary .thumb').click(function(){
		var videoID = $(this).attr("id");
		$('#resort-video').html('').flash({
			swf:"flash/video-gallery/videointerface.swf",
			width:"800",
			height:"488",
			params:{
				allowscriptaccess:"sameDomain",
				wmode:"transparent",
				quality:"high",
				flashvars:{
					videoSkin:"/flash/video-gallery/SkinUnderPlaySeekMute.swf",
					videoPath:"/flash/video-gallery/assets/videos/"+videoID+".flv"	
				}
			}
		});
	});
	
	
	//If the URL has a hash (anchor) bit, scroll to that.
	if ( window.location.hash ) {
		$.scrollTo(window.location.hash);
	}
	//Center Trail Map modal function
	var centerTrailMap=function(hash){
		hash.w.show();
		hash.w.css("position","absolute");
		var top = ( $(window).height() - hash.w.outerHeight() ) / 2+$(window).scrollTop();
		if ( top < 0 ) {
			top = 10;
		}
		hash.w.css("top", top + "px");
		hash.w.css("left", ( $(window).width() - hash.w.outerWidth() ) / 2+$(window).scrollLeft() + "px");
	};
	
	//$('#trail-map-modal').jqm({trigger:'#trail-map-click'});
	$('#trail-map-modal').jqm({onShow:centerTrailMap,trigger:'#tertiary-trailmap'});
	$('#trail-map-modal2').jqm({onShow:centerTrailMap,trigger:'#trailmap'});
	
	$("#spring-sale-modal").each(function() {
		var springModalWidth = ($(window).width()-$(this).width())/2;
		$(this).css('left',springModalWidth);
		$(this).css('top','120px');
		$(this).jqm({closeClass:'spring-sale-close,'}).jqmShow();
	});
	
	$('.recipe-details').hide();
	$('a.recipe-expand').toggle(function() {
		var el = $(this);
		el.html('Hide Details').parent().addClass('active').parent().find('.recipe-details').slideDown('slow');
		return false;								   
	},function() { 
		var el = $(this);
		el.html('View More');
		$('.recipe-details').hide();
		return false;								   
	});
	
	//ArborTrek Modal
	//$('#arbortrek-modal').jqm({trigger:'#arbortrek-trigger'});
	//$('#arbortrek-modal').jqm({ajax: '/includes/arbortrek-widget.php', trigger:'#arbortrek-trigger'});
	//$('#arbortrek-trigger').click(function(){
		//$.scrollTo(0);
	//});
	
});	
 
