$(function() {
	//Documentation located in special.docs.js
	$('div#content-wrapper h1').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#FFF7E0', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'letter-spacing=12&' }, { expressInstall: true });
	$('h3.push-title').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#5a2f0e', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textAlign=center&' }, { expressInstall: true });
	$('#archive-wrapper h2').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#5a2f0e', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textAlign=center&' }, { expressInstall: true });	
	$('#scrapbook-tags h2').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#5a2f0e', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textAlign=center&' }, { expressInstall: true });		
	//$('body.home div#content h2').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#5a2f0e', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'letter-spacing=0&' }, { expressInstall: true });
	$('div.posts-pagination span#pagination').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#5a2f0e', strWmode: 'transparent', strCase: 'upper', intPadding: [0, 0, 0, 0], strFlashVars: 'letter-spacing=0&' }, { expressInstall: true });		
	//$('div.weather-sidebar a').sifr({ strSWF: '/flash/futura-light.swf', strColor: '#5A2F0E', strWmode: 'transparent', strCase: 'upper', intPadding: [0, 0, 0, 0],  strFlashVars: 'textAlign=center&' }, { expressInstall: true });

	//$('body.home h2').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#5A2F0E', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'letter-spacing=12&' }, { expressInstall: true });	


	//Homepage Countdown
	$('#home-push').each(function() {		
		$("#mycarousel").carouFredSel({
			items               : 3,
			width				: 660,
			curcular			: true,
			prev				: "#go-prev",
			next				: "#go-next",
			scroll				: {
				items: 1
			},
			auto				: {
				pauseDuration: 3000,
				pauseOnHover: true,
				delay: 3000
			}
		}); 
	}); 

	var targetDay = new Date(2011, 10, 25);

	var day = Date.today();
	day = day.getDay();
	
	var hour = new Date();
	hour = hour.getHours();
	
	day = targetDay.getDate();

	$('li#countdown').each(function(){
		$('#countdown_dashboard').countDown({
			targetDate: {
				'day': 		day,
				'month': 	targetDay.getMonth() + 1,
				'year': 	targetDay.getFullYear(),
				'hour': 	targetDay.getHours(),
				'min': 		targetDay.getMinutes(),
				'sec': 		0
			},
			omitWeeks: true
		});
	});

	$('#posts-wrapper .post').each(function() {
		var img = $('img', this );
		if ( img.width() > 500 ) {
			img.attr('width', 500 )
			img.removeAttr('height')
		}
        });

	$('div#code-box').hide();
	$('a#promo-link').toggle(function() {
		$('div#code-box').show();
		return false;
	}, function() { 
		$('div#code-box').hide();
		return false; 
	});

	/*function mycarousel_initCallback(carousel) {
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	
	$('#mycarousel').jcarousel({
		scroll: 1,
		visible: 3,
		itemFirstInCallback: 1,
		initCallback: mycarousel_initCallback
	});*/
	
	/*$('#home-push').each(function(){
		var slider = $('#mycarousel').bxSlider({
			controls: false,
			//auto: true,
			autoHover: true,
			displaySlideQty: 3,
		    moveSlideQty: 1,
			buildPager: function(){
				$('li#countdown').each(function(){
					$('#countdown_dashboard').countdown({until: targetDay});
				});
			}
		  });
		$('#go-prev').click(function(e){
			e.preventDefault();
			slider.goToPreviousSlide();
		});
	
		$('#go-next').click(function(e){
			e.preventDefault();
			slider.goToNextSlide();
		});
	});*/

	var $tabs = $('#tabs').tabs();

	$tabs.bind('tabsselect', function(event, ui) {
     ui.options // options used to intialize this widget
     ui.index // zero-based index of the selected (clicked) tab
		switch(ui.index) {
			case 0: //Guestrooms & Suites
				$('input#room').attr('value','ROH,ROO,ROOD,ROOK,L0RFW,L0RFK,L0RVW,L0RVK,L0RSW,L0RSK,L1UFKP,L1UVKP,L1UTKP,L1UZKP');
				break;
			case 1: //Villas
				$('input#room').attr('value','V2VV3C,V2VS3C,V3VV4C,V3VS4C,V4VV4C');
				break;
			case 2: //Casitias
				$('input#room').attr('value','C0IFW,C0IFK,C0IVW,C0IVK,C0ISW,C0ISK,C2XF2C,C2XV2C,C2XS2C,C3XFKW,C3XVKW,C3XSKW,C1UFKC,C1UVKC,C1USKC');
				break;
			case 3: //Bungalows
				$('input#room').attr('value','B0RVW,B0RVK,B2XVKW,B1UVKC');
				break;
			case 4: //All
				$('input#room').attr('value','');
				break;

		}
	  
	});


	 $('select#tags').change(function(){
		var url = $(this).val();
		window.location = url;
    });

	$('select#scrapbook-archive').change(function(){
		var url = $(this).val();
		window.location = url;
    });


   //$('#register .hear-about').change(function() {
	//        var val = $(this).val().toLowerCase();
	//        if(val!='other'&&val!='unknown'&&val!='signage/drive-by') {
	//            $(this).parent().next().show().find('.'+val).attr({name: '00N70000001q7fs', id: '00N70000001q7fs'}).show().siblings('select').attr({name: '', id: ''}).val('').hide();
	//            $(this).parent().next().next().hide().find('input').val('');
	//        } else if(val=='other') {
	//            $(this).parent().next().next().show();
	//            $(this).parent().next().hide().find('select').attr({name: '', id: ''}).val('');
	//        } else {
	//            $(this).parent().next().next().hide().find('input').val('');
	//            $(this).parent().next().hide().find('select').attr({name: '', id: ''}).val('');
	//        }
	//    });

	// JQModal 


	// accomodations features
	$('.accom-details a').toggle(function(event) {
		event.preventDefault();
		$(this).closest('.room-block').find('.room-features').slideDown('slow');
		$(this).closest('.room-block').addClass('active');
		$(this).html('Hide Details');
	}, function(event) {
		$(this).closest('.room-block').find('.room-features').slideUp('slow');
		$(this).closest('.room-block').removeClass('active');
		$(this).html('View Details');
	});

	var openFn=function(hash){
		hash.w.show();
		var leftPos = ($(window).width()-$('#map-container').width())/2;
		var topPos = $(window).scrollTop()+10;
		$('#map-container').css({left:leftPos,top:topPos});
		$('#map').msnMap({listView:true});
	};
	var hideMapFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$('#map-container').each(function(){ $(this).jqm({trigger:'a#msn-map-link', onShow: openFn, onHide: hideMapFn});});



	var openFnResortMap=function(hash){	
		hash.w.show();
		$('#resort-map-modal').css({left:($(window).width()-$('#resort-map-modal').width())/2,top:$(window).scrollTop()+10});				
	};
	var openFnMeetingMap=function(hash){	
		hash.w.show();
		$('#meeting-map-modal').css({left:($(window).width()-$('#meeting-map-modal').width())/2,top:$(window).scrollTop()+10});				
	};
    var openFnPhotoVideo=function(hash){ 
        hash.w.show();
        $('#photo-gallery-modal').css({left:($(window).width()-$('#photo-gallery-modal').width())/2,top:$(window).scrollTop()+10});
    };

	
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
	};
				
	$('#resort-map-modal').jqm({ajax:'../includes/resort-map.php', trigger: 'a#resort-map-link', onShow: openFnResortMap, onHide: hideFn, target:'div#resort-map-content'});
	$('#meeting-map-modal').jqm({ajax:'../includes/meeting-map.php', trigger: 'a#meeting-map-link', onShow: openFnMeetingMap, onHide: hideFn, target:'div#meeting-map-content'});
    $('#photo-gallery-modal').jqm({trigger: 'a.sidebar-photo-gallery', onShow: openFnPhotoVideo, onHide: hideFn});
    $('#photo-gallery-modal').jqmAddTrigger('a.photo-gallery-btn');
    $('#photo-gallery-modal').jqmAddTrigger('a.thumb-photo-gallery');	 
    $('#photo-gallery-modal').jqmAddTrigger('#secondary-real-gallery a');	 
    $('#photo-gallery-modal').jqmAddTrigger('a.push-view-gallery');	 

	$(".article-wrapper").each(function(){
		$('.article-long').hide();
		var x = $(this);
      $("a.read-more",x).toggle(function(){
           $(".article-long",x).slideDown();
           $(this).addClass(" active");
      }, function() {
           $(".article-long",x).slideUp();
           $(this).removeClass(" active");
      });
	});
	
	if ($('body').is('.newsletter')){
		var contents = '<ul>';
		$('div.article-wrapper').each(function(i){
			$(this).attr('id','article-'+(i+1));
			contents+='<li><a href="#article-'+(i+1)+'">'+$(this).find('div.article-title').text()+'</a><br />'+$(this).find('div.article-short p:eq(0)').text()+'</li>';
		});
		contents+='</ul>';
		$('div.inner-articles-listing').append(contents);
	}
	
	
	//Meetings Section Holiday Lightbox
	$('#holiday-lightbox').jqm();
	$('#holiday-lightbox').jqmShow();
	
	//Accommodations Page Holiday Lightbox
	$('#ext-holiday-lightbox').jqm();
	$('#ext-holiday-lightbox').jqmShow();
	
	//Meetings Section Lightbox
	//$('#meetings-lightbox').jqm();
	//$('#meetings-lightbox').jqmShow();
	
	// ==============================
	//Weddings Video Lightbox START
	//Center modal function
	var showWedVid=function(hash){
		hash.w.show();
		$('#wedding-vid').html('<object type="application/x-shockwave-flash" style="width:639px; height:360px;" data="http://vimeo.com/moogaloop.swf?clip_id=19159627&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1&amp;autoplay=1"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=19159627&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1&amp;autoplay=1" /></object>');
		pageTracker._trackEvent('video', 'play', 'weddings-video');
	};
	//Clear html after close of popup
	var hideWedVid=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('#wedding-vid').html('');
	};

	$('#weddings-video-lightbox').jqm({onShow:showWedVid,onHide:hideWedVid});
	//Weddings Video Lightbox END
	// ===============================

	
 				// choose text for the show/hide link
				var showText="Read More";
				var hideText="Read Less";
				
				// create the toggle link
				$("#hide_this").after("<p><a href='#' id='toggle_link'>"+showText+"</a>");
				$("#hide-lindsay-bio").after("<p><a href='#' id='toggle_link-lindsay'>"+showText+"</a>");
				$("#hide-kelly-bio").after("<p><a href='#' id='toggle_link-kelly'>"+showText+"</a>");
				// hide the content
				$('#hide_this').hide();
				$('#hide-lindsay-bio').hide();
				$('#hide-kelly-bio').hide();
				
				// capture clicks on the newly created link
				$('a#toggle_link').click(function() {
				
				// change the link text
				if ($('a#toggle_link').text()==showText) {
				$('a#toggle_link').text(hideText);
				}
				else {
				$('a#toggle_link').text(showText);
				}
				
				// toggle the display
 
				if ($('#hide_this').is(':hidden')) {
            		$('#hide_this').slideDown('200');
              
        		} else {
           		  		$('#hide_this').slideUp('200');
             
       			 }
				
				
				
				// $('#hide_this').toggle('fast');
				
				// return false so any link destination is not followed
				return false;
				});
				
				// capture clicks on the newly created link
				$('a#toggle_link-lindsay').click(function() {
				
				// change the link text
				if ($('a#toggle_link-lindsay').text()==showText) {
				$('a#toggle_link-lindsay').text(hideText);
				}
				else {
				$('a#toggle_link-lindsay').text(showText);
				}
				
				// toggle the display
 
				if ($('#hide-lindsay-bio').is(':hidden')) {
            		$('#hide-lindsay-bio').slideDown('200');
              
        		} else {
           		  		$('#hide-lindsay-bio').slideUp('200');
             
       			 }
				
				
				
				// $('#hide_this').toggle('fast');
				
				// return false so any link destination is not followed
				return false;
				});
				
				// capture clicks on the newly created link
				$('a#toggle_link-kelly').click(function() {
				
				// change the link text
				if ($('a#toggle_link-kelly').text()==showText) {
				$('a#toggle_link-kelly').text(hideText);
				}
				else {
				$('a#toggle_link-kelly').text(showText);
				}
				
				// toggle the display
 
				if ($('#hide-kelly-bio').is(':hidden')) {
            		$('#hide-kelly-bio').slideDown('200');
              
        		} else {
           		  		$('#hide-kelly-bio').slideUp('200');
             
       			 }
				
				
				
				// $('#hide_this').toggle('fast');
				
				// return false so any link destination is not followed
				return false;
				});
	
	
	$("#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();
	});
	
	$('a#btn-sign-up-offers').click(function() { 
		$(this).parent().addClass('open').removeClass('closed');
		$(this).parent().children('#sign-up-form-wrapper').show();
		return false;									   
	});
	
	$('a#popup-signup-close').click(function() { 
		$(this).parent().addClass('closed').removeClass('open');
		$(this).parent('#sign-up-form-wrapper').hide();
		return false;									   
	});
	
	
	if($('body#home').length != 0){
		$("#widgetWrap").css("display", "none");
	}


	$('div#fb-contest-outer-wrapper').each(function(){
		if ($.cookie('facebook-contest') == "clickedme"){
			$('div#fb-contest-outer-wrapper').hide();
		}

		$('div#fb-contest-outer-wrapper a').click(function(e) {
			$("div#fb-contest-outer-wrapper").animate({ bottom: -82 }, 200 );
			$.cookie('facebook-contest', 'clickedme');
			//alert($.cookie('facebook-contest'));
		});
		// IE6 fix for footer banner
		for(var i in $.browser) {
			if ($.browser[i])
				BROWSER = i + (($.browser.msie)?$.browser.version.charAt(0):'');
		}
		if(BROWSER=='msie6') {
			$(window).scroll(function() {
				ieposfix();
			});
			ieposfix();
			$(".fb-contest-inner-wrapper #close-button").click(function(e){
				$("#fb-contest-outer-wrapper").hide();
			});
		}
		function ieposfix() {
			var pos = ($(window).scrollTop() + $(window).height()) - $('#fb-contest-outer-wrapper').height();
			$("#fb-contest-outer-wrapper").css("top", pos + "px").css("position","absolute").css("bottom","auto");
		}
	});

});
