$(function(){
	
	$("#ping").after($('<input>').attr({'name':'pong','value':$("#ping").val(),'class':'hide'}));
	
	$('a[rel="external"], form.form-external').attr({'target':'_blank'});
	if ($('#fx img').length > 1) {
		$('#fx img').hide();
		$('#fx').nivoSlider({
			effect: 'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
			slices: 5,
			animSpeed: 500, //Slide transition speed
			pauseTime: 5000,
			startSlide: 0, //Set starting Slide (0 index)
			directionNav: true, //Next & Prev
			directionNavHide: false, //Only show on hover
			controlNav: false, //1,2,3...
			keyboardNav: false, //Use left & right arrows
			pauseOnHover: false, //Stop animation while hovering
			manualAdvance: false, //Force manual transitions
			captionOpacity: 0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){}, //Triggers after all slides have been shown
			lastSlide: function(){}, //Triggers when last slide is shown
			afterLoad: function(){} //Triggers when slider has loaded
		});
	}
	
	var HeBS_Link_Checkin_Checkout_Inputs = function HeBS_Link_Checkin_Checkout_Inputs_function(checkin_selector, checkout_selector) {
		Date.format = 'mm/dd/yyyy';

		
		
		$(checkin_selector).bind('dateSelected', function(e, selectedDate, $td, state) {
			var t = new Date(selectedDate);
			var dt = new Date.fromString($(checkin_selector).val());		
		    var edate = new Date.fromString($(checkout_selector).val());			
		    var one_day=1000*60*60*24;
		    var days_diff = Math.ceil((edate.getTime() - dt.getTime())/(one_day));
		    
		    if(edate.getTime() <= dt.getTime()) {
		        $(checkout_selector).val(t.addDays(1).asString());
		    }
		});
		
		$(checkout_selector).bind('dateSelected', function(e, selectedDate, $td, state) {
			var t = new Date(selectedDate);
			var dt = new Date.fromString($(checkin_selector).val());	
		    var edate = new Date.fromString($(checkout_selector).val());				
		    var one_day=1000*60*60*24;
		    var days_diff = Math.ceil((edate.getTime() - dt.getTime())/(one_day));
		    
		    var edate = new Date.fromString($(checkout_selector).val());			
		    if(edate.getTime() <= dt.getTime()) {
		        $(checkin_selector).val(t.addDays(-1).asString());
		    }		
		});
		
		var today = new Date();
		$(checkin_selector).val(today.asString());
		$(checkout_selector).val(today.addDays(1).asString());
		
	    $(checkout_selector).dpSetStartDate(today.asString());
	};
		
	$('#arrival, #departure, .date-pick').datePicker({'clickInput' : true });
	
	HeBS_Link_Checkin_Checkout_Inputs('#arrival', '#departure');
	HeBS_Link_Checkin_Checkout_Inputs('#arrival_date', '#departure_date');
	
	$('#booking-and-specials select').sSelect();
	
	$(".button").hover(
		 function () {
			$(this).addClass('hover');
		 }, 
		 function () {
			$(this).removeClass('hover');
		 }
	);
	
	if($("#googlemap").length) {
	
		$("#googlemap").mapfu({
	    latitude: 34.044365,
	    longitude: -118.264292,
			scrollwheel: false,
			data: [{
			    "hotel": {
			      "id":1,
			      "name":"Luxe City Center Hotel",
			      "address":"1020 S. Figueroa Street",
			      "city":"Los Angeles",
			      "state":"CA",
			      "zip_code":"90015",
			      "country":"US",
			      "lat":34.044365,
			      "lng":-118.264292,
			      "phone_number":"(213) 748-1291"
			    }
			  }],
			zoom: 15,
			mapType: "roadmap",
			icon: {
	      image: "images/pointer.png",
				shadow: "images/pointer-shadow.png"
	    },
	    title: function(item) {
	      return "" + item.name + "";
	    },
	    html: function(item) {
	      return "<h3>" + item.name + "</h3><p> " + item.address + "<br>" + item.city + ", " + item.state + " " + item.zip_code + "<br> Phone: " + item.phone_number + "</p>";
	    }
	  });
	}
	
	if($(".fancybox").length) {
		$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'	 :	600, 
		'speedOut'	 :	200,
		'cyclic' : true,
		'centerOnScroll' : true,
		'overlayOpacity' : 0.8,
		'overlayColor' : '#000',
		'overlayShow'	:	true
		});
	}
	
	$('#header .main-menu li a, #header .main-menu ul').hover(function() {
		$(this).parent().addClass('hover');
	}, function() {
		$(this).parent().removeClass('hover');
	});
	
	var current_url = $('#fb-index').attr("title");
	if (!current_url) {	current_url = window.location.protocol + "//" + window.location.hostname + window.location.pathname; }
	$('#fb-index').html('<iframe src="http://www.facebook.com/plugins/like.php?href=' +current_url+ '&amp;layout=button_count&amp;show_faces=true&amp;width=90&amp;action=like&amp;colorscheme=dark&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" class="facebook-like"></iframe>');
	

});
