/******************************************************************************
 *   Following code is written for use with jQuery >> http://www.jquery.com   *
 ******************************************************************************/

$(document).ready(function() {
	$("img").attr("title", function() {
		return $(this).attr("title") || $(this).attr("alt") || null; });
	$("a").attr("title", function() {
		return $(this).attr("title") || $(this).children("img").slice(0,1).attr("title") || null; });
	
	try {
		function customRange(input) {
			return {
				minDate: (input.id == 'Departure' ? $('#Arrival').datepick('getDate') || 0 : 0),
				maxDate: (input.id == 'Arrival' ? $('#Departure').datepick('getDate') : '+5Y') }
		}
		$("#content.contact #Arrival, #content.contact #Departure").datepick({
			beforeShow: customRange, dateFormat: 'dd.mm.yy',
			firstDay: 1, numberOfMonths: 2, showStatus: true });
	} catch(e) { };
	
	try {
		$(".ad-gallery").adGallery({
			width: 850,
			height: 450,
			effect: 'fade',
			loader_image: '/include/loader.gif',
			slideshow: { enable: false },
			callbacks: {
				afterImageVisible: function() {
					var _this = this;
					var next_index = _this.current_index + 1;
					if (_this.current_index == _this.images.length - 1)
						next_index--;
					_this.preloadImage( next_index, function() { _this.loading(false); } );
				},
				beforeImageVisible: function() {
					var _this = this;
					if (_this.images[_this.current_index].image != $('.ad-image img').attr('src')) {
						if (_this.images[_this.current_index].preloaded == false)
							_this.loading(true);
						_this.settings.effect = 'slide-hori';
					} else _this.settings.effect = 'fade';
				}
			}
		});
	} catch(e) { };
	
	$(".boxgrid.captionfull").hover(
		function() {
			$(".cover", this).stop().animate(
				{ bottom: '0px' },
				{ queue: false, duration: 300 }); },
		function() {
			var divH = $(".cover", this).height();
			$(".cover", this).stop().animate(
				{ bottom: parseInt( - $(this).height() ) + 'px' },
				{ queue: false, duration: 300 }); }
	).each(
		function() {
			var _img = $("img", this)[0];
			var imgH = _img.clientHeight || $(this).height();
			var imgW = _img.clientWidth || $(this).height();
			$(this).css({ height: imgH, width: imgW });
			$(".boxcaption", this).css(
				{ bottom: parseInt( - $(this).height() ) + 'px' });
		}
	);
});
