$(document).ready( function() {

	// local.com search interrupt
	$('#businessSearchForm').submit(function(){
		var term = $("#businessSearchField").val();
		if(term.indexOf('hotel') >= 0 || term.indexOf('resort') >= 0 || term.indexOf('motel') >= 0  || term.indexOf('accom') >= 0){
			window.location.href = "/hotels/";
			return false;
		}
		if(term.indexOf('condo') >= 0){
			window.location.href = "/condos/";
			return false;
		}
		if(term.indexOf('attraction') >= 0 || term.indexOf('to do') >= 0 || term.indexOf('amuse') >= 0){
			window.location.href = "/listings/myrtle-beach-things-to-do/";
			return false;
		}
	});

	$.datePicker.setDateFormat('mdy', '/');
	
	// initalize
	$('input.date-picker').datePicker();
	$('input#arrivalDate').datePicker();
	$('input#departureDate').datePicker();
	// tee time form
	$('input#teedate').datePicker();
	
	$('#keywords').focus(function() {
		$(this).attr('value','').removeClass('show-site-search');
	});
	
	$('.email-address-input').focus(function() {
		if($(this).attr('value') == "Enter your email address") { $(this).attr('value',''); }
	});
	$('.email-address-input').blur(function() {
		if($(this).attr('value') == "") { $(this).attr('value','Enter your email address'); }
	});
	
	$('.email-address-input2').focus(function() {
		if($(this).attr('value') == "Email address") { $(this).attr('value',''); }
	});
	$('.email-address-input2').blur(function() {
		if($(this).attr('value') == "") { $(this).attr('value','Email address'); }
	});
	
	// set/check the curtain ad display cookie for the dropdown
	if($.cookie("mb-visited") == null){
		$('#curtain-media div').slideDown('normal');
		// set cookie for 8 hours
		$.cookie("mb-visited", "yes", { expires: 8 });
	}
	
	// make links open in a new window
	$('a[rel~="external"]').attr('target', '_blank');
	
	$('#hp-slideshow').cycle({timeout:6000,speed:500});
	$('#blog-slideshow').cycle({timeout:6000,speed:500,prev:'#prev',next:'#next'});
	$('#post-slideshow').cycle();
	$('#vg-photos').cycle();
	
	// curtain ad
	$('#curtain-toggle').click(function(){
		if($('#curtain-media div').is(':visible')){
			hideCurtain();
		} else {
			$('#curtain-media div').slideDown('slow');
			$(this).html('close');
			s=s_gi(s_account);
			s.linkTrackVars = 'events';
			s.linkTrackEvents = 'event21';
			s.events = 'event21';
			s.tl(this, 'o', 'Curtain Deals Open Click');
		}
		return false;
	});
	
	// video section tabs
	$(".video-list-tabs li a").click(function(){
		$(".video-list-tabs li a").removeClass('selected'); // kill selected tab state
		$("ul.video-list").hide(); // hide all video thumbs
		$(this).addClass('selected'); // highlight current tab
		var current_video_section = $(this).attr('href'); // grab the section to show
		$("ul#"+current_video_section).fadeIn('fast'); // show the current section
		return false;
	});
	
	//new events search methods
	// event category select
	$("#eventForm").submit(function(){
		var sDate = $('input#sDate').attr('value');
		var eDate = $('input#eDate').attr('value');
		var cat = $("#eventCategories option:selected").val();
		if(cat != '') {
			cat = 'category/'+cat;
		}
		if(sDate == '') {
			sDate = '2010-01-01';
		} else {
			sDateA = sDate.split("/");
			sDate = sDateA[2]+'-'+sDateA[0]+'-'+sDateA[1];
		}
		if(eDate == '') {
			eDate = '2020-01-01';
		} else {
			eDateA = eDate.split("/");
			eDate = eDateA[2]+'-'+eDateA[0]+'-'+eDateA[1];
		}

		window.location.href = '/myrtle-beach-events/date/'+sDate+'/'+eDate+'/'+cat;
		return false;
	});
	
	$("#eventSearchForm").submit(function() {
		var kw = $('input#keyword').attr('value');
		window.location.href = '/myrtle-beach-events/search/'+kw;
		return false;
	})
	
	// event month select
	$("#event-month").change(function(){
		var url = $("#event-month option:selected").val();
		window.location.href = url;
	});
	// event category select
	$("#event-categories").change(function(){
		var url = $("#event-categories option:selected").val();
		window.location.href = url;
	});
	// weather faq slide down
	$('.weather-faq h3').click(function(){
		$(this).siblings('p').slideToggle('fast');
	});
	
	$('#facebookFooter').html('<iframe src="http://www.facebook.com/plugins/likebox.php?id=373445137499&amp;width=200&amp;connections=0&amp;stream=false&amp;header=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:80px;" allowTransparency="true"></iframe>');
	
	$('#facebookInsert').html('<iframe src="http://www.facebook.com/plugins/likebox.php?id=373445137499&amp;width=360&amp;connections=0&amp;stream=false&amp;header=false&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:360px; height:65px;" allowTransparency="true"></iframe>');
	
	$('#facebookIndexLike').delay(500).html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.myrtlebeach.com%2F&amp;layout=standard&amp;show_faces=false&amp;width=500&amp;action=like&amp;colorscheme=light&amp;height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:25px;" allowTransparency="true"></iframe>');
	
	$('#facebookIndexStream').html('<iframe src="http://www.facebook.com/plugins/likebox.php?id=373445137499&amp;width=540&amp;connections=10&amp;stream=true&amp;header=true&amp;height=500" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:540px; height:500px;" allowTransparency="true"></iframe>');
	
/*	
var stuff = $('#doubleClickReplace').html()
	$('#saveBig').html(stuff);
*/

});


function trackFilterClicks(){
	_gaq.push(['_trackPageview','/outgoing/ad-click/listing-filter-click/']);
}

function hideCurtain(){
	$('#curtain-media div').slideUp('slow');
	$('#curtain-toggle').html('expand');
}

$(function () {
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	
	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	$('#accomodationsSearchSubmit').click(function(){
		if($('.subcat').val() == ''){
		alert("Please select a type");
		return false;
		}
	});
	
	//myrtle beach events	
	jQuery(".cShow").live('click', function() {
		
		var showThis = jQuery(this).attr('rel');
		jQuery("#"+showThis).siblings().slideUp(function() {
			jQuery("#"+showThis).slideDown();
			jQuery("#closeSlide").slideDown();
		});
		return false;
	});
	
	jQuery("#closeSlideA").live('click', function() {
		jQuery("#closeSlide").slideUp();
		jQuery("#closeSlide").siblings().slideUp();
		return false;
	});
	
	jQuery("#recurBtn").live('click', function() {
		var action = jQuery(this).attr('rel');		;
		if (action == 'Show') {
			jQuery(this).attr('rel', 'Hide')
			jQuery(this).html("Hide all dates for this event")
		} else {
			jQuery(this).attr('rel', 'Show')
			jQuery(this).html("Show all dates for this event")
		}
		jQuery(".recur").toggle();	
		return false;
	});

});
