$(function(){
	//HEADER
	$("div.header div.carousel").jCarouselLite({
       btnPrev: "div.header .previous",
       btnNext: "div.header .next",
	   auto: 7500,
	   speed: 500
    });
	
	//PHOTO GALLERY
	$("div.photoGallery").jCarouselLite({
		btnPrev: "div.photoGalleryWrapper .previous",
		btnNext: "div.photoGalleryWrapper .next",
		speed: 500,
		visible: 6,
		circular: false
	});
	$("div.fullPhotoGallery li a,div.photoGalleryWrapper li a").lightBox({
		fixedNavigation:true,
		overlayOpacity: 0.6,
		imageLoading: '/lib/jquery/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: '/lib/jquery/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: '/lib/jquery/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: '/lib/jquery/lightbox/images/lightbox-btn-next.gif'
	});
	
	//AUTO ENLARGE IMAGES
	$("a.magnify").lightBox({
		fixedNavigation:true,
		overlayOpacity: 0.6,
		imageLoading: '/lib/jquery/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: '/lib/jquery/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: '/lib/jquery/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: '/lib/jquery/lightbox/images/lightbox-btn-next.gif'
	});

	//FIX BOTTOM BORDERS
	var maxHeight = 0;
	$("ul.footerMenu > li").each(function(){
		if( $(this).height() > maxHeight ) maxHeight = $(this).height(); 		
	}).css("height",maxHeight+"px");

	$(".datepicker").datepicker({dateFormat:'dd M yy','minDate':'0'}).parent().parent().click(function(){
		$(this).find(".datepicker").focus();
	});
	
	

	var currency = $("[name=currency]");
	currency.autocomplete({
		source: ["Australia Dollars (AUD)","Euro (EUR)","Japan Yen (JPY)","United Kingdom Pounds (GBP)","United States Dollars (USD)","Argentina Pesos (ARS)","Canada Dollars (CAD)","Denmark Kroner (DKK)","Fiji Dollars (FJD)","Hong Kong Dollars (HKD)","Malaysia Ringgits (MYR)","New Zealand Dollars (NZD)","Philippines Pesos (PHP)","Russia Rubles (RUB)","Samoa Tala (WST)","Singapore Dollars (SGD)","Sweden Kronor (SEK)","Taiwan New Dollars (TWD)","Thailand Baht (THB)","Vanuatu Vatu (VUV)"],
		minLength: 0,
		delay: 0,
		open: function(e,ui){
			currency.autocomplete("widget").css("top",(parseInt(currency.autocomplete("widget").css("top").replace(/\D/g,""))+5)+"px");
			currency.autocomplete("widget").css("left",(parseInt(currency.autocomplete("widget").css("left").replace(/\D/g,""))-5)+"px");
			currency.autocomplete("widget").css("width","155px");
		}
	}).parent().click(function(){
		if (currency.autocomplete("widget").is(":visible")) {
			currency.autocomplete("close");
			return;
		}
		// pass empty string as value to search for, displaying all results
		currency.autocomplete("search", "");
	});

	var adults = $("[name=adults]");
	adults.autocomplete({
		source: ["1","2","3","4","5","6"],
		minLength: 0,
		delay: 0,
		open: function(e,ui){
			adults.autocomplete("widget").css("top",(parseInt(adults.autocomplete("widget").css("top").replace(/\D/g,""))+5)+"px");
			adults.autocomplete("widget").css("left",(parseInt(adults.autocomplete("widget").css("left").replace(/\D/g,""))-5)+"px");
			adults.autocomplete("widget").css("width","65px");
		}
	}).click(function(){
		if (adults.autocomplete("widget").is(":visible")) {
			adults.autocomplete("close");
			return;
		}
		// pass empty string as value to search for, displaying all results
		adults.autocomplete("search", "");
		adults.focus();
	});

	$("#bookButton").click(function(){
		var url = "/redirect.php?noa=true&";
		url += "currency="+$("[name=currency]").val().substr($("[name=currency]").val().indexOf("(")+1,3);
		url += "&start_date="+$("[name=date1]").val();
		window.open(url);
	});
});
