$(function(){
	
	if($("#message").length)
	{
		setTimeout(function(){
			$("#message").fadeOut();
		}, 4000)
	}
	
	/**
	 *  Retrieve unavailable dates and initialize datepicker
	 */
	if(PAGE == 'booking')
	{
		$.get(BASE_URL + "ajax/booked_dates", function(response){
			var booked_dates = $.parseJSON(response);
			$("#booking-form .date").datepicker({
				beforeShowDay: function(date){
					var ap = $("select[name=apartment_id]").val();
					if(ap && booked_dates['dates'][ap][(date.getTime()/1000)])
					{
						return [0, 'unavailable'];
					}
					return [1,''];
				},
				dateFormat: 'dd.mm.yy',
				minDate: new Date(),
				showAnim: '',
				numberOfMonths: 2
			});
		});
	}
	
	/**
	 * Fancybox
	 */
	if($.fancybox)
	{
		$(".fancybox").fancybox({
			titlePosition: 'over'
		});
	}
	
	/**
	 * Header slideshow
	 */
	$("#header-gallery-images").cycle({
		speed: 1500,
		timeout: 5000,
		fx: 'fade'
	});
	
	/**
	 * Weather widget
	 */
	$("#weather-widget").cycle({
		speed: 800,
		timeout: 4000
	});
});
