/**
 * @version: $Id: functions.js 17897 2011-02-22 17:55:17Z john $
 */

// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images

// mit license. paul irish. 2010.
// webkit fix from Oren Solomianik. thx!

// callback function is passed the last image to load
// as an argument, and the collection as `this`


$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'),
      len = elems.length;
      
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,this); }
  }).each(function(){
     // cached images don't fire load sometimes, so we reset src.
     if (this.complete || this.complete === undefined){
        var src = this.src;
        // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
        // data uri bypasses webkit log warning (thx doug jones)
        this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
        this.src = src;
     }
  });

  return this;
};

$(document).ready(function() {

	$(".datepicker").datepicker({
		dateFormat: 'dd/mm/yy',
		showWeek: true,
		firstDay: 1,
		minDate: '+1d',
		changeMonth: true,
		changeYear: true,
		navigationAsDateFormat: true,
		gotoCurrent: true,
		showOtherMonths: true,
		selectOtherMonths: true
	});

	$(".datepickerDOB").datepicker({
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		minDate: '-18y',
		maxDate: '-1d',
		changeMonth: true,
		changeYear: true,
		navigationAsDateFormat: true,
		gotoCurrent: true,
		showOtherMonths: true,
		selectOtherMonths: true
	});
	
	$(".stars-wrapper").stars({
		inputType: "select",
		cancelValue: "Any"
	});
	
	$('.banner-slide').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:800, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //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
	});
	
	$('#content h2:empty').hide();

	$('.lightboxPic').fancybox();
	
	$('#thumbs img', this).imagesLoaded(function() {
		$('#thumbs ul').jcarousel({
			wrap: "both",
			scroll: 1
		});
	});

	$("#thumbs ul a").hover(function() {
		$("#accom-img-main a")
			.attr({
				href: $(this).attr('href'),
				title: $(this).attr('title')
			})
			.find('img')
				.attr({
					src: $(this).attr('href'),
					alt: $(this).find('img').attr('alt')
				});
		return false;
	});
	
	$('div.tabs > div').each(function() {
		var tabTitle = $(this).attr('title');
		var tabID = $(this).attr('id');
		$(this).parent().find('ul.tabNavigation').append('<li><a href="#'+tabID+'">'+tabTitle+'</a></li>');
		$(this).attr('title', '');
	});

	$('div.tabs').each(function() {
	    var tabContainers = $(this).find('div.tabcont');
	    
	    $(this).find('ul.tabNavigation a').click(function () {
	        tabContainers.hide().filter(this.hash).show();
	        
	        $(this).parent().parent().find('li').removeClass('selected');
	        $(this).parent().addClass('selected');
	        
	        return false;
	    });

	    var to_match = this.hash;
	    
		var found = false;
		tabContainers.each(function () {
			if ($(this).hasClass('selected')) {
				$('div.tabs ul.tabNavigation a[href$=#' + $(this).attr('id') + ']').click();
				found = true;
			}
			if ($(this).hasClass('prices')) {
				$('div.tabs ul.tabNavigation a[href$=#' + $(this).attr('id') + ']').parent().addClass('prices');
			}
		});

		if (!found) $(this).find('ul.tabNavigation a').filter(':first').click();
	});

});

function setSpamSecure(){
    var secure_id = '<?= md5("chams3rv3") ?>';
    document.getElementById("spam_secure").value = secure_id;
}
