$(function() {
	$('div.ratings-tabs-wrapper  ul.ratings-tabs ').tabs(1);

	// Nav Stuff
	$('#meetings').css({ position: 'absolute', cssFloat: 'none' });
	$('#leisure').css({ position: 'absolute', cssFloat: 'none' });

	if( $('.current').attr("id") == 'leisure'){
		var lowerNavOffset = document.getElementById('leisure').offsetHeight + 10;
		$('#leisure').css('top',0);
		$('#meetings').css('top',lowerNavOffset);
	}
	else {
		var lowerNavOffset = document.getElementById('meetings').offsetHeight + 10;
		$('#meetings').css('top',0);
		$('#leisure').css('top',lowerNavOffset);
	}
	
	var $console = $('#booking-console-wd form'), $type = $('#booking-console-wd #property_type')
	    .change(function(e) {
		e.preventDefault()
		if ( $(this).val() == 'search' ) {
		    $('.field-gc', $console).addClass('hide-field');
		    $('.field-search', $console).addClass('show-field').removeClass('hide-field');
		    $console.attr('action', $console.attr('other'));
		} else {
		    $('.field-gc', $console).addClass('show-field').removeClass('hide-field');
		    $('.field-search', $console).addClass('hide-field');
		    $console.attr('action', $console.attr('origin'));
		}
	    });

	$('#promo-code-trigger').click(function(e) {
	    $('#booking-console-wd').css({'z-index':20});
	    e.preventDefault()
	    $('#promo-console').show()
	});

	$('#close-promo').click(function(e){
	    e.preventDefault()
	    $('#booking-console-wd').css({'z-index':'auto'});
	    $('#promo-console').hide()
	});

	$('#done-promo').click(function(e) {
	    e.preventDefault()
	    $(this).closest('form').trigger('submit');
	});

	$('#rates-rentals .view-map, body.details-beta .view-map').live('click', function(e) {
	    e.preventDefault()
	    var w = window.open( $(this).attr('href'), 'Map', 'width=775,height=475');
	    w.focus();
	});

	$('#rates-rentals .ratings-modal').click(function(e) {
	    e.preventDefault();
	    var $modal = $($(this).attr('href')), offset = $(this).offset();
	    if ( $modal.length ) {
		$modal.show().css({
		    'top':(offset.top-30)
		})
	    }
	    $modal.siblings().hide()
	});

	$('#modal-wrapper .close').click(function(e) {
	    e.preventDefault()
	    $('#modal-wrapper div:visible').hide();
	});

	var navprimaryheight = (document.getElementById('leisure').offsetHeight + 10) + (document.getElementById('meetings').offsetHeight + 10);
	$('#nav-primary').css('height', navprimaryheight)

	if($('body').is('.home')) {	
		var qsParms = new Array();
		var querystring = window.location.search.substring(1);
		var parms = querystring.split('&');
		for (var i=0; i<parms.length; i++) {
			var pos = parms[i].indexOf('=');
			if (pos > 0) {
				var key = parms[i].substring(0,pos);
				var val = parms[i].substring(pos+1);
				qsParms[key] = val;
			}
		}

		if (qsParms['sec'] == 'meetings' || sec == 'meetings') {
			talkToFlash2();
			$('div#leisure-content').hide();
			$('div#meeting-content').show();
			$('div#leisure-push').hide();
			$('div#meetings-push').show();	

		}
		
		$('.nav-head').children('a').click( function() { 
			if ($('body').attr("class") == "home" ) {
				if ($(this).parent().attr("id") == "meetings" ) {
					talkToFlash2();
					$('div#leisure-content').hide();
					$('div#meeting-content').show();
					$('div#leisure-push').hide();
					$('div#meetings-push').show();	
				} else {
					talkToFlash1();
					$('div#meeting-content').hide();
					$('div#leisure-content').show();
					$('div#leisure-push').show();
					$('div#meetings-push').hide();	
				}
			}
			var currentlyClicked= $(this).parent().attr('id');
			var notClicked = $(this).parent().siblings('li').attr('id');
	
			var el = $('#'+currentlyClicked);
			var el2 = $('#'+notClicked);
	
			if(parseInt(el.css('top')) != 0) {
				el.css('zIndex', -1);
				el2.css('zIndex', -1);
				el2.fadeOut('slow');
				el2.children('ul').hide();
				el.children('ul').show();
				if(currentlyClicked=='leisure')
					lowerNavOffset = document.getElementById('leisure').offsetHeight + 10;
				else
					lowerNavOffset = document.getElementById('meetings').offsetHeight + 10;
				el.animate({top: 0, zIndex:100}, 600, 'easein', function() {
					el2.animate({zIndex: 0, opacity: 'show'}, 800);
					el2.css('top', lowerNavOffset);
				});
			}
			if ( $(this).parent().attr("class") == 'nav-head' || $(this).parent().attr("class") == 'current nav-head' )
				return false;	
		});
	}

	//Hides and displays RFP forms on pages.  
	$('#rfp-field').hide();
	$('a#form-show').click( function() { $('#rfp-field').show(); 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;
	});
	
	$('div.prop-list-body').hide();
	$('a.prop-toggle').toggle(function(){ 
		$(this).children('img').attr('src', 'images/layout/btn-hide-listings.gif');	
		$(this).parent().next().slideDown("slow");
		return false;
	},function(){ 
		$(this).children('img').attr('src', 'images/layout/btn-view-listings.gif');
	   $(this).parent().next().slideUp("slow");
	  	return false;
	});
	
	$('a.pop-up').click( function () {
		var pLink = this.href;
		window.open( pLink,'PopUp','width=610,height=510, scrollbars=no')
		return false;
		});

	// Sifr
	$('body:not(".blog") div#content h2').sifr({ strSWF: 'flash/zapf-humanist-bt.swf', strColor: '#56522c', strWmode: 'transparent' }, { expressInstall: true });
	$('body:not(".blog") div#content h3:not("#eclub-special")').sifr({ strSWF: 'flash/zapf-humanist-bt.swf', strColor: '#56522c', strWmode: 'transparent' }, { expressInstall: true });
	$('a.wedding-link').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#56522c', strLinkColor: '#56522c', strWmode: 'transparent', strFlashVars: 'textalign=center&' }, { expressInstall: true });
	$('a.venue-link').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#56522c', strLinkColor: '#56522c', strWmode: 'transparent', strFlashVars: 'textalign=center&' }, { expressInstall: true });
	$('div#content div.accomm-search-wrapper h4').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#191918', strWmode: 'transparent' }, { expressInstall: true });	
	$('div#content h6#summer-promo').sifr({ strSWF: 'flash/zapf-humanist-bt.swf', strColor: '#47828a', strWmode: 'transparent' }, { expressInstall: true });
	
	if( BrowserDetect.browser != 'Camino' ) { 
		$('div#content div#search-results-wrapper h4').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#191918', strWmode: 'transparent' }, { expressInstall: true });	
		$('div#content div#search-results-wrapper h5').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#191918', strWmode: 'transparent' }, { expressInstall: true });	
	} else {
		$('div#content div#search-results-wrapper h4').addClass("sifr-alt");
		$('div#content div#search-results-wrapper h45').addClass("sifr-alt");
	}
	
	if (!$('body').hasClass("blog") && !$('body').hasClass("videogal"))
		$('body:not(.destination-earth,.subscribe) div#content h4').sifr({ strSWF: 'flash/futura-light.swf', strColor: '#4b461e', strWmode: 'transparent' }, { expressInstall: true });
	
	
	$("div#harbor-course").flash(
		{src:"flash/harbor_course_golf_map.swf",
		 width:715,
		 height:400,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	
	$("div#links-course").flash(
		{src:"flash/links_course_golf_map.swf",
		 width:715,
		 height:400,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	
	$("div#dhr-flash").flash(
		{src:"http://www.destinationhotels.com/flash/branding/flash_logoDhr-white.swf?link=wilddunes",
		 width:250,
		 height:25,
		 wmode:"transparent",
		 allowScriptAccess:"always",
		 quality:"high"},
		 {version:"7"});

	$("div#interactive-map").flash(
		{src:"flash/interactive_map.swf",
		 width:760,
		 height:450,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
    
    $('div#unit-floorplan-flash').each(function(){
        var xmlPath = $(this).attr("title");
        $(this).flash(
            {    src:"flash/flash-floorplan.swf",
                width:616,
                height:440,
                wmode:"transparent",
                quality:"high"},
            {version:"10"},
            function(htmlOptions) {
                htmlOptions.flashvars.xmlPath = xmlPath;
                $(this).before($.fn.flash.transform(htmlOptions));                        
            }
        );
    }); 
		
	$("div.gallery").each(function() {
		var file = $(this).attr("id");
		$(this).flash(
			{	src:"flash/gallery.swf",
				width:700,
				height:420,
				wmode:"transparent",
				quality:"high"},
			{version:"7"},
			function(htmlOptions) {
				htmlOptions.flashvars.xmlfile = "xml/" + file + ".xml";
				$(this).before($.fn.flash.transform(htmlOptions));						
			}
		);
	});
    
    // New accommodation search page
    $('select#property_type').change(function(){
       //alert($(this).val());
       //alert($(this).find('option').filter(':selected').attr('id'));
       var e = $(this);
       var id = e.find('option').filter(':selected').attr('id');
       var val = e.val();
       var search_form = $('div.search-form-wrapper');
       var booking_form = $('div.booking-form-wrapper');
       
       if(search_form.css('display') != 'none'){
            if(val!='search'){
                search_form.slideUp('slow', function(){
                    showItems();   
                });
            }
       }else if(booking_form.css('display') != 'none'){
            if(val!='booking'){ 
                booking_form.slideUp('slow', function(){
                    showItems();   
                });
            }
       }else{
            showItems();
       }
       
       function showItems(){
           if(val=='search'){ 
                search_form.slideDown(); 
           }else if(val=='booking'){
                booking_form.slideDown();     
           }
       }
       $('input#property_type').val(id);
    });
    
	$('.share-link').initializeSharing();
	
	//Help text
	$(".form-help").hide();
	$(".help-text").each( function() {
		var x = $(this);
		$("a.help-link", x).toggle( function() {
			$(".form-help", x).slideDown("slow");
		}, function () {
			$(".form-help", x).slideUp("slow");
		});
	}); 
	
	$('div#tabs-wrapper').tabs();
	$('div#video-tabs-wrapper').tabs();
	
	$('#video-tabs li a ').click(function() { 
		$('body').find('div.video-wrapper').children('div').html('');
		switch($(this).parent().attr('id')){
			case 'tab-golf':
				$('#golf-content').find('div.video-wrapper').children('div').flash({src:"flash/golfing-wild-dunes-courses.swf", width:490, height:325, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'tab-tennis':
				$('#tennis-content').find('div.video-wrapper').children('div').flash({src:"flash/service-toss-tennis-tips.swf",width:421, height:319, wmode:"transparent", quality:"high"},{version:"8"});
				break;
			case 'tab-resort':
				$('#resort-content').find('div.video-wrapper').children('div').flash({src:"flash/wild-dunes-wedding-specialist.swf", width:490, height:321, wmode:"transparent",quality:"high"},{version:"9"});
				break;
				case 'tab-podcasts':
				$('#podcasts-content').find('div.video-wrapper').children('div').flash({src:"flash/golfing-wild-dunes-courses.swf", width:490, height:325, wmode:"transparent",quality:"high"},{version:"9"});
				break;
			
		}							  										  										  
	});
	
	
	
	$("div#main-vid-golf1").flash({src:"flash/sc-golf-swing-tips.swf", width:424, height:352, wmode:"transparent", quality:"high"}, {version:"8"});
	
	$("div#vid-golf1").flash({src:"flash/sc-golf-swing-tips.swf", width:391, height:319, wmode:"transparent", quality:"high"}, {version:"8"});
	$("div#vid-golf2").flash({src:"flash/golf-18th-hole-video.swf", width:491, height:319, wmode:"transparent", quality:"high"}, {version:"8"});		
	$("div#vid-tennis1").flash({src:"flash/service-toss-tennis-tips.swf",width:421, height:319, wmode:"transparent", quality:"high"},{version:"8"});
	$("div#vid-tennis2").flash({src:"flash/doubles-tennis-tips.swf", width:386, height:319, wmode:"transparent", quality:"high"}, {version:"8"});
	$("div#vid-beach1").flash({src:"flash/beach-erosion-restoration-process.swf", width:386, height:319, wmode:"transparent",quality:"high"},{version:"9"});
	$("div#vid-podcast1").flash({src:"flash/golfing-wild-dunes-courses.swf", width:490, height:325, wmode:"transparent",quality:"high"},{version:"9"});
	$("div#vid-podcast2").flash({src:"flash/golfing-wild-dunes-courses.swf", width:421, height:325, wmode:"transparent",quality:"high"},{version:"9"});
	$("div#vid-wedding1").flash({src:"flash/wild-dunes-wedding-specialist.swf", width:490, height:321, wmode:"transparent",quality:"high"},{version:"9"});
	$("div#vid-wedding2").flash({src:"flash/wild-dunes-wedding-specialist.swf", width:424, height:321, wmode:"transparent",quality:"high"},{version:"9"});

	$('a.main-thumb-link').click(function() { 
		$(this).parent().parent().parent().find('div.video-wrapper').children('div').html('');
		var linkid = $(this).attr('id');		
		linkid = 'vid-'+linkid;
		switch(linkid){
			case 'vid-podcast2':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/golfing-wild-dunes-courses.swf", width:421, height:325, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'vid-golf1':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/sc-golf-swing-tips.swf", width:424, height:352, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'vid-tennis1':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/service-toss-tennis-tips.swf",width:424, height:352, wmode:"transparent", quality:"high"},{version:"8"});
				break;
			case 'vid-beach1':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/beach-erosion-restoration-process.swf", width:424, height:352, wmode:"transparent",quality:"high"},{version:"9"});
				break;
				case 'vid-wedding1':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/wild-dunes-wedding-specialist.swf", width:490, height:321, wmode:"transparent",quality:"high"},{version:"9"});
				break;
				case 'vid-wedding2':
				$(this).parent().parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/wild-dunes-wedding-specialist.swf", width:424, height:321, wmode:"transparent",quality:"high"},{version:"9"});
				break;
			
		}
		return false;
		
	});
	
	$('a.thumb-link').click(function() { 
		$(this).parent().parent().find('div.video-wrapper').children('div').html('');
		var textheader = $(this).parent().find('.video-thumb-content').children('h5').html();
		var textcopy = $(this).parent().find('.video-thumb-content').children('p').html();
		
		var linkid = $(this).attr('id');		
		linkid = 'vid-'+linkid;
		switch(linkid){
			case 'vid-golf1':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/sc-golf-swing-tips.swf", width:391, height:319, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'vid-golf2':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/golf-18th-hole-video.swf", width:491, height:319, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'vid-tennis1':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/service-toss-tennis-tips.swf",width:421, height:319, wmode:"transparent", quality:"high"},{version:"8"});
				break;
			case 'vid-tennis2':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/doubles-tennis-tips.swf", width:386, height:319, wmode:"transparent", quality:"high"}, {version:"8"});
				break;
			case 'vid-beach1':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/beach-erosion-restoration-process.swf", width:386, height:319, wmode:"transparent",quality:"high"},{version:"9"});
				break;
			case 'vid-podcast1':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/golfing-wild-dunes-courses.swf", width:490, height:325, wmode:"transparent",quality:"high"},{version:"9"});
				break;
			case 'vid-wedding1':
				$(this).parent().parent().find('div.video-wrapper').children('div').flash({src:"flash/wild-dunes-wedding-specialist.swf", width:490, height:321, wmode:"transparent",quality:"high"},{version:"9"});
				break;	
			
		}
		
		$(this).parent().parent().find('div.video-large').children('h4.video-header').html(textheader);
		$(this).parent().parent().find('div.video-large').children('p.video-text').html(textcopy);
			
		return false;
		
	});
	
	$('div#guest-photos').flash({ src:"flash/sm-photo-gallery.swf", width:476, height:353, wmode:"transparent", quality:"high"},{version:"10"},
    	function(htmlOptions) {
        	htmlOptions.flashvars.xmlFile = '/flash/xml/photo_gallery_images_guest.xml';
            $(this).before($.fn.flash.transform(htmlOptions));                        
        }
   	);
	$('div#resort-photos').flash({ src:"flash/sm-photo-gallery.swf", width:476, height:353, wmode:"transparent", quality:"high"},{version:"10"},
    	function(htmlOptions) {
        	htmlOptions.flashvars.xmlFile = '/flash/xml/photo_gallery_images.xml';
            $(this).before($.fn.flash.transform(htmlOptions));                        
        }
   	);
    
    // Isle of Palms Rental Program form
    $('a#iop-add').click(function(){
        var wrap = $('div#iop-wrapper');
        var item = $('div#iop-wrapper div:first-child').clone();
        var count = $('div#iop-wrapper div').size();
        item.children('input').attr('id','iop-'+count);
        item.children('input').attr('value','');
        item.children('input').attr('class','textfield');
        item.children('a').attr('rel',count);
        
        item.children('a').click(function(){
            count1 = $('div#iop-wrapper div').size();
            if(count1>1){
                item.remove();
            }else{
                alert('You must have atleast one rental address');
            }   
            return false;
        });
        
        wrap.append(item);
        return false;
        
    });
    
    $('a#iop-remove').each(function(){
        $(this).click(function(){
            var wrap = $('div#iop-wrapper');
            var count = $('div#iop-wrapper div').size();
            var item = $(this).parent();
            if(count>1){
                item.remove();
            }else{
                alert('You must have atleast one rental address');
            } 
            return false;
        });  
    });
    
    $('div#iop-wrapper div:first-child').children('input').attr('class','textfield required');
    
    
    
    ////////////////////////////////////////

// Sample usage of jquery.flash plugin - remove if not needed
	/*	If given the following markup:

	<div id="masthead">
		<img src="images/mastheads/flash-alt.jpg" alt="" /><br />
	</div>
	
	you would use the following to replace the alternate content:

	$("div#masthead").flash(
		{src:"flash/home.swf",
		 width:600,
		 height:300,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	*/
});

(function($) {		  

	$.fn.initializeSharing = function() {
		return this.each(function() {
			$('.share-link').live('click',function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				$(this).parents('.rss-item').find('.share-panel').css('display','inline');
			});
			$('.share-close').live('click',function(event){
				event.preventDefault();
				$(this).parents('.rss-item').find('.share-panel').slideUp('fast');
			});
		});
	};


})(jQuery);

/*Beach Nourishment Photo Gallery JS */

$(function() {
    $("li#bn-photo a").click ( function() {
	$('#popupborder > div.tb-photo').each(function(i,p) {
	    if ( i !== 0 ) {
		$(p).hide()

		$('a.bn-prev', this)
		    .text('<Previous ')
		    .prependTo( $('.bn-image-menu', p) )
	    } else {
		$(p).show()
	    }

	    $('a.bn-next', this).click(function() {
		$(p)
		    .hide()
		    .next().show()
	    });

	    $('a.bn-prev', this).click(function() {
		$(p)
		    .hide()
		    .prev().show()
	    });

	    if ( ! $(p).next().length ) {
		$('a.bn-next', p).hide();
	    }

	});
    });
});


/*
$(function() {
    $("li#bn-photo a").click ( function() {
	$('#popupborder > div#photo').each(function(i,p) {
	    if ( i !== 0 ) {
		$(p).hide()

		$('a.bn-prev', this)
		    .text('<Previous ')
		    .prependTo( $('.bn-image-menu', p) )
	    } else {
		$(p).show()
	    }

	    $('a.bn-next', this).click(function() {
		$(p)
		    .hide()
		    .next().show()
	    });

	    $('a.bn-prev', this).click(function() {
		$(p)
		    .hide()
		    .prev().show()
	    });

	    if ( ! $(p).next().length ) {
		$('a.bn-next', p).hide();
	    }

	});
    });
});
*/
