// CUSTOM JQ
$(document).ready(function(){

$(function() {
	
	$(".date_ui").datepicker();
	
	//$(".quote-thank-you-bg").fadeIn(10);
	$(".quote-thank-you").fadeIn(2000);

		$(".v-invalid").live('click', function(){ $(this).removeClass("v-invalid"); });
		$(".l-invalid").live('click', function(){ $(this).removeClass("l-invalid"); });
	
	$("#submit").click(function() {
		
	//required fields
	if ($("#rq_surname").val()==""){
		$("#rq_surname").addClass("v-invalid");
		return false;
	}
	
	else if ($("#rq_daytime_no").val()==""){
		$("#rq_daytime_no").addClass("v-invalid");
		return false;
	}
	
	else if ($("#rq_country").val()==""){
		$("#rq_country").addClass("v-invalid");
		return false;
	}
	
	else if ($("#rq_earl_dep").val()==""){
		$("#rq_earl_dep").addClass("v-invalid");
		return false;
	}
	
	else if ($("#rq_late_dep").val()==""){
		$("#rq_late_dep").addClass("v-invalid");
		return false;
	}
	
	else if ($("#rq_duration").val()==""){
		$("#rq_duration").addClass("v-invalid");
		return false;
	}
	//end required
	
				//lengths for all fields
				
				else if ($("#rq_surname").val().length > 28){
					$("#rq_surname").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_daytime_no").val().length > 28){
					$("#rq_daytime_no").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_country").val().length > 28){
					$("#rq_country").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_earl_dep").val().length > 28){
					$("#rq_earl_dep").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_late_dep").val().length > 28){
					$("#rq_late_dep").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_duration").val().length > 28){
					$("#rq_duration").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_title").val().length > 8){
					$("#rq_title").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_first_name").val().length > 25){
					$("#rq_first_name").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_email").val().length > 100){
					$("#rq_email").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_hotel").val().length > 50){
					$("#rq_hotel").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_flyingfrom").val().length > 20){
					$("#rq_flyingfrom").addClass("l-invalid");
					return false;
				}
				
				else if ($("#rq_no_pax_adult").val().length > 3){
					$("#rq_no_pax_adult").addClass("l-invalid");
					return false;
				}
				
				//else if ($("#rq_wedding_package").val().length > 1){
				//	$("#rq_wedding_package").addClass("l-invalid");
				//	return false;
				//}
				
				else if ($(".previous").val().length > 1){
					$(".previous").addClass("l-invalid");
					return false;
				}
				
				else if ($(".source").val().length > 1){
					$(".source").addClass("l-invalid");
					return false;
				}
				//end lengths
	
	
	var rq_title = $("select#rq_title").val();
	var rq_first_name = $("input#rq_first_name").val();
	var rq_surname = $("input#rq_surname").val();
	var rq_daytime_no = $("input#rq_daytime_no").val();
	var rq_email = $("input#rq_email").val();
	
	var rq_country = $("select#rq_country").val();
	var rq_hotel = $("select#rq_hotel").val();
	var rq_earl_dep = $("input#rq_earl_dep").val();
	var rq_late_dep = $("input#rq_late_dep").val();
	var rq_duration = $("input#rq_duration").val();	
	var rq_roomtype = $("input#rq_roomtype").val();
	var	rq_flyingfrom = $("input#rq_flyingfrom").val();
	
	var rq_no_pax_adult = $("input#rq_no_pax_adult").val();
	//var rq_wedding_package = $("input#rq_wedding_package").val();
	
	var previous = $("input.previous").val();	
	var source = $("input.source").val();
	
		
	var dataString = 'rq_title='+rq_title+'&rq_first_name='+rq_first_name+'&rq_surname='+rq_surname+'&rq_daytime_no='+rq_daytime_no+'&rq_email='+rq_email+'&rq_country='+rq_country+'&rq_hotel='+rq_hotel+'&rq_earl_dep='+rq_earl_dep+'&rq_late_dep='+ rq_late_dep +'&rq_duration='+rq_duration+'&rq_roomtype='+rq_roomtype+'&rq_flyingfrom='+rq_flyingfrom+'&rq_no_pax_adult='+rq_no_pax_adult+'&previous='+previous+'&source='+source;
	
	//alert (dataString);return false;
					
	$.ajax({
	type: "POST",
	url: "http://bbtsrv02/ultimatecaribbean.co.uk/secrets/incs/ui/quote-s.php",
	data: dataString,
	success: function() {
	
		$("#request-a-quote").fadeOut(500);
		
		 $(".req_bg").fadeIn(750, function(){
										   
									   		 setTimeout(function(){
																 
																$(".req_bg").stop().slideUp();
																
																 }, 3000);
										   
										   });
		 


	}
	
	});	

	return false;

});
	
});

		
	
	
//End
	//

// SCROLL
	//

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inarray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

				if (window.location.href.indexOf('quote') != -1){

				$("#request-a-quote").stop().animate({height : 315},1000);
				$("#form-wrap").show(100);

				}

	//Request a Quote Toggle
	$("#req-quote").toggle(
			function() {
				$("#request-a-quote").stop().animate({height : 315},1000);
				$("#form-wrap").show(100);
			},
			function() {
				$("#request-a-quote").stop().animate({height : 0},1000);
				$("#form-wrap").hide(100);
			}
		);
	
	//End
		
		// FADE IN OVERLAY CONTENT AFTER HALF A SECOND
		//$('#img-cont-ovrl').delay(500).fadeIn(1000);
		//$('.shadow-top, .shadow-btm').delay(250).fadeIn(750);
		
		if ( $('.slideshow img').size() <= 1 ) {
			
		}
		else {
			$(function() {
				setInterval( "slideSwitch()", 5000 );
				setInterval( "textSwitch()", 5000 );
			});
		}
		
		
		$('#navigation ul li').hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none');}
			);
		$('#navigation ul li').click(
			function() { $('ul', this).css('display', 'none');}
			);
		
		
	$('#totop').click(function(e) { 
		e.preventDefault();
		$.scrollTo(0,400); 
	});

		
});

//
// SLIDES
//
	

		function slideSwitch() {

			var $active = $('.slideshow img.active');
			if ( $active.length == 0 ) $active = $('.slideshow img:last');
			var $next =  $active.next().length ? $active.next()
				: $('.slideshow img:first');
			$active.addClass('last-active');
			$next.css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, 1500, function() {
					$active.removeClass('active last-active');
				});
		}
		
		function textSwitch() {
			var $active = $('#img-cont-ovrl div.txt.active');
			if ( $active.length == 0 ) $active = $('#img-cont-ovrl div.txt:last');
			var $next =  $active.next().length ? $active.next()
				: $('#img-cont-ovrl div.txt:first');
			$active.addClass('last-active');
			$next.fadeOut()
				.addClass('active')
				.fadeIn(1500, function() {
					$active.removeClass('active last-active');
				});
							
		}
//End
	$(document).ready(function(){

			 $(".open_cw").fancybox({
				 
				 
        		'autoDimensions'	: false,
				'width'         		: 1000,
				'height'        		: 600
				  
				  
				  });
					
					function formatTitle(title, currentArray, currentIndex, currentOpts) {
        	    	return '' + (title && title.length ? '<b>' + title + '</b> - ' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '';
		        	}	
					
				  $("a.zoom").fancybox({
				  "hideOnContentClick": false,
				  "overlayShow" : true,
				  'titleFormat' : formatTitle,
				  'centerOnScroll' : true
				  
				  });




							   });




