$(function() {
	//Documentation located in special.docs.js
	
	// Home push cycle
	$('div#jcycle-home-push').each(function(){ $(this).cycle({ 
		fx: 'fade',
        //delay: 950,
		speed:  'fast', 
		timeout: 0, 
		next:   '#next-push',
		cleartype: true, 
		cleartypeNoBg: true,
		filter:''
		});
	});	
	
	
	//Booking Console Homepage Tabs -- UNCOMMENT WHEN CONDOS/HOMES TAB GOES LIVE
	/*var tabContainers = $('div#res-console > div');
	tabContainers.hide().filter(':first').show();
			
	$('div#res-console ul.res-nav a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#res-console ul.res-nav a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	*/
	
	var tabContainers = $('div#res-console-int > div');
	tabContainers.hide().filter(':first').show();
			
	$('div#res-console-int ul.res-nav-int-beta a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#res-console-int ul.res-nav-int-beta a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	
	//Home booking console
	var homeTabContainers = $('div#res-console-inner > div');
	homeTabContainers.hide().filter(':first').show();
			
	$('div#res-console-inner ul.res-nav a').click(function () {
		homeTabContainers.hide();
		homeTabContainers.filter(this.hash).show();
		$('div#res-console-inner ul.res-nav a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	
	//Booking Console Slide Up
	$('body.homepage .arrival-wrapper, body.homepage .arrival-wrapper img').click(function() {
		$('#home-push-wrapper').css('z-index','20');
		$('#res-console-inner').slideDown("slow",function() {
			$('#res-console-inner').addClass('rez-expanded');
		});
	});
	
	
	//Interior Booking Console Promo Code
	$("form#reservations-console-interior").each(function(){
		var x = $(this);
		$("a#promo-click", x).click(function(){
			$("#promo-fields",x).show();
			$("a#promo-click",x).addClass('promo-open');
			return false;
		});
		$("#extra-fields-close").click(function() {
			$("#promo-fields",x).hide();
			$("a#promo-click",x).removeClass('promo-open');
			return false;
		});
	});
	
	$("div#promo-submit a").click(function(){
		$("#promo-fields").hide();
		$("a#promo-click").removeClass('promo-open');
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$("#promo-click").addClass("selected-promo-click");
		} else {
			$("#promo-click").removeClass("selected-promo-click");
		}
		return false;
	});
	
	//Condo Booking Console
	$("a#clear-link").live("click", function(e){
		e.preventDefault();
		$("#form-synxis-wrapper .hasDatepicker").each(function(){
			$(this).val('');
			$(this).datepicker({ defaultDate: null});
		});
	});
	
	$('a.property-details').hover(function(e) {
		e.preventDefault();
		$(this).parents('li.rental-listing').children('div.property-details-popup-thing').show();
	}, function(e){
		$(this).parents('li.rental-listing').children('div.property-details-popup-thing').hide();
	});
	
	
	//MSN-Bing Map
	var openFn=function(hash){
		hash.w.show();
		var difference = $(window).width() - $('#map-jqmodal').width();
		difference = difference / 2;
		$('#map-jqmodal').css({left:difference+500,top:$(window).scrollTop()+10});
		$('#map').msnMap({listView:true, hotelOnly: true});
		$("#cat-main:first").remove();
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
	};
	$('#map-jqmodal').jqm({trigger:'#btn-msnmap', onShow: openFn, onHide: hideFn});
	
	
	//Blog Post Flickr Image Help Toggle
	$('a.help-link').click(function(e){
		e.preventDefault();
		$('div.form-help').toggle('slow');
	});
	
	
	//Blog Toggles
	$("div.post-comments a").click(function(event){
		event.preventDefault();
		$(this).parent().toggleClass("comenting").parents('.comment-wrapper').siblings('form#blog-comment').toggle();
	
	});
	
	$("div.post-details a").click(function(event) {
		event.preventDefault();
		$(this).parent().toggleClass("read-less").parents(".post-nav").siblings(".post-description").toggle();
	});
	
	
	//Spa Treatment Toggle
	$("a.treatment-details").click(function(event) {
		event.preventDefault();
		$(this).toggleClass("read-less").parents(".package-links").siblings(".package-interior-wrap").children().children('.treatments-long').toggle();
	});
	
	
	//Form Toggles
	$('select#special-event').click(function() {
		var value= $('select#special-event option:selected').val();
		//alert(this);
		
		if (value =='yes') {
		$('span#event-yes').show();
		} else {
			$('span#event-yes').hide();
		}
		
	});
	
	//Wedding Cake Galleries
	if ( $.fn.fancybox ) {
        $("#silver-gallery").click(function() {
            $.fancybox([
                '/images/cake-gallery/silver-01.jpg',
                '/images/cake-gallery/silver-02.jpg'
            ], {
                'padding'			: 5,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0,
                'cyclic'			: 'true'
            });
            return false;
        });

        $("#gold-gallery").click(function() {
            $.fancybox([
                '/images/cake-gallery/gold-01.jpg',
                '/images/cake-gallery/gold-02.jpg'
            ], {
                'padding'			: 5,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0,
                'cyclic'			: 'true'
            });
            return false;
        });
            
        $("#platinum-gallery").click(function() {
            $.fancybox([
                '/images/cake-gallery/platinum-01.jpg',
                '/images/cake-gallery/platinum-02.jpg'
            ], {
                'padding'			: 5,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0,
                'cyclic'			: 'true'
            });
            return false;
        });
    }
	
	//wedding venues
	if ( $.fn.fancybox ) {
        $(".zoom-in").fancybox();
    }
	
	
	//expand-collapse - personal trainers
	$('.expand-item-wrapper').expand({openText: 'View Full Bio', closeText: 'Hide Full Bio', longClass: '.expand-item-detail'});

	$('#ppc-items .package-details').toggle(function(e) {
		e.preventDefault();
		$(this).closest('.package-interior-wrap').find('.package-long').slideDown('slow');
		$(this).closest('.package-interior-wrap').addClass('active');
	},function(e) { 
		e.preventDefault();
		$(this).closest('.package-interior-wrap').find('.package-long').slideUp('slow');
		$(this).closest('.package-interior-wrap').find('.package-long').removeClass('active');
	});

});
