$(document).ready(function(){
						   
/*******************************************************
LEAVE ALL THESE ALONE - THEY ARE STANDARD
*******************************************************/
	// fixes png images for ie6.
	$(document).pngFix();	
	
	$('#checkIn').datepicker({ 
		minDate: 0,             
       	dateFormat: 'mm/dd/yy'
	});
	
	
	
	$('#checkOut').datepicker({ 
		dateFormat: 'mm/dd/yy',
		defaultDate: +2
	});
	


	// opens anything pdf link to a new page.
	$("a[href*=.pdf]").click(function()	{
		window.open( $(this).attr('href') );
        return false;
	});
	
	// opens a link to a new page
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	// DEAL WITH ALL FORMS
	$('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input[type="text"]').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('input[type="password"]').addClass("idleField");
	$('input[type="password"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input[type="password"]').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	
	
	


$(".sNavWrap").corner("top 10px").css({opacity: 0.5});
$(".photoBoxNav").corner("top 10px").css({opacity: 0.5});	
	



	// ROTATING AD
	//mainRotatingAd
	$("#mainRotatingAd").everyTime(10000,function(i){
		$.ajax({
		  url: "/inc/rotating-ad.php",
		  cache: false,
		  success: function(html){
			$("#mainRotatingAd").html(html);
		  }
		})
	})












	
/*******************************************************
FOR PHOTO GALLERY AND VIDEO GALLERY TO USE FANCYBOX
*******************************************************/
$("a[rel=galleryOne]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titleShow'           : true,
	'padding'			: '0'
});



$("a[rel=videoClickBox]").fancybox({
	'width'				: '560',
	'height'			: '340',
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titleShow'           : true,
	'padding'			: '0'
});
	
/*******************************************************
FOR THIS WEBSITE.
*******************************************************/

	// 	EQUAL COLUMN HEIGHTS
	$("#e_right, #e_left").equalizeCols();








	// BOOKING FORM
	$("#bookNow").hover(function(){
		$(this).attr("src","/img/btn_bookNow_now.png"); //mouseover
	}, function(){
		$(this).attr("src","/img/btn_bookNow.png");//mouseout
	});
	// FOR SLIDESHOW ON ALL PAGES.
	mainImageFlow();
	
	
	
	
	$(".sSub").each(function(){
		var newWidth = $(this).width();
		$(this).prev().css("width",newWidth); // - 40
		$(this).css("display","none");
		//alert( 400 - $(this).height() );
	});
	// Deal with Sub Nav
	$(".sNavWrap").hover(function(){
		if( $(this).attr("id") == "motorCycleSNav")
		{
			if ($.browser.msie && $.browser.version.substr(0,1)<8){var minusPX = "33";}
			else{var minusPX = "33";}			
		}
		else
		{
			if ($.browser.msie && $.browser.version.substr(0,1)<8){var minusPX = "33";}
			else{var minusPX = "32";}
		}		
		var newHeight = (400 - $(this).children().children(".sSub").height() ) - minusPX +"px";
		//alert(newHeight);
		$(this).animate({
			top: newHeight //-=171px
		}, 500, function() {
			$(this).children().children(".sSub").show();
		}).stop(true, true);
		$(this).children().children(".sSub").slideDown(500);
	},function(){
      	$(this).animate({
			top: '368px' //-=171px
		}, 500, function() {
			$(this).children().children(".sSub").hide();
		}).stop(true, true);
		$(this).children().children(".sSub").slideUp(500);
    });


	//$(".nav li a:first").css("padding-left","0");
	$("#your-desires").css("padding-right","0");
	$(".nav li:first").css("background","none");
	//$(".nav li a:first").css("padding-left",20);	
	$(".customBottomLinks a:last").css("border-right","none")




	$("#slider").easySlider({
		auto: true,
		continuous: true,
		nextId: "slider1next",
		prevId: "slider1prev"
	});


	// validate the contact form
	$("#contactForm").validate({
		rules: {
			contactFirstName: {
				required: true,
				minlength: 1
			},
			contactLastName: {
				required: true,
				minlength: 1
			},
			contactEmailAddress: {
				required: true,
				email: true
			},
			captcha: {
				required: true,
				minlength: 5,
				equalTo: "#captchaImage"
			}			
		},
		messages: {
			contactFirstName: "",
			contactLastName: "",
			contactEmailAddress: ""
			
		}
	});
	
	
	// validate the contact form
	$("#rfpForm").validate({
		rules: {
			rfp_firstName: {
				required: true,
				minlength: 1
			},
			rfp_lastName: {
				required: true,
				minlength: 1
			},
			rfp_emailAddress: {
				required: true,
				email: true
			},
			captcha: {
				required: true,
				minlength: 5,
				equalTo: "#captchaImage"
			}			
		},
		messages: {
			rfp_firstName: "required",
			rfp_lastName: "required",
			rfp_emailAddress: "required"
			
		}
	});
	
	
	
	
	
	
	
	
	
	// ROTATOR ON HOMEPAGE
	$(".sliders").css({opacity: 1.0});	
	// start
	$("#viewer").removeClass("js-disabled");
	//create new container for images
	$("<div>").attr("id", "container").css({ position:"absolute"}).width($(".wrapper").length * 96).height(100).appendTo("div#viewer");
	//add images to container
	$(".wrapper").each(function(){ $(this).appendTo("div#container"); });
	//work out duration of anim based on number of images (1 second for each image)
	var duration = $(".wrapper").length * 3000;
	//store speed for later (distance / time)
	var speed = (parseInt($("div#container").width()) + parseInt($("div#viewer").width())) / duration;
	//set direction
	var direction = "rtl";
	//set initial position and class based on direction
	(direction == "rtl") ? $("div#container").css("left", $("div#viewer").width()).addClass("rtl") : $("div#container").css("left", 0 - $("div#container").width()).addClass("ltr")
	//animator function
	var animator = function(el, time, dir) {
		//which direction to scroll
		if(dir == "rtl") {
		  	//add direction class
			el.removeClass("ltr").addClass("rtl");
			//animate the el
			el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {
			//reset container position
			$(this).css({ left:$("div#imageScroller").width(), right:"" });
			//restart animation
			animator($(this), duration, "rtl");
			//hide controls if visible
			($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null;			
			});
		} else {
			//add direction class
			el.removeClass("rtl").addClass("ltr");
			//animate the el
			el.animate({ left:$("div#viewer").width() + "px" }, time, "linear", function() {
				//reset container position
				$(this).css({ left:0 - $("div#container").width() });
				//restart animation
				animator($(this), duration, "ltr");
				//hide controls if visible
				($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
			});
		}
	}	
	//start anim
	animator($("div#container"), duration, direction);
	//pause on mouseover
	$("a.wrapper").live("mouseover", function() {
		//stop anim
		$("div#container").stop(true);
		//show controls
		($("div#controls").length == 0) ? $("<div>").attr("id", "controls").appendTo("div#outerContainer").css({ opacity:0.7 }).slideDown("slow") : null ;
		($("a#rtl").length == 0) ? $("<a>").attr({ id:"rtl", href:"#", title:"rtl" }).appendTo("#controls") : null ;
		($("a#ltr").length == 0) ? $("<a>").attr({ id:"ltr", href:"#", title:"ltr" }).appendTo("#controls") : null ;
		//variable to hold trigger element
		var title = $(this).attr("title");
		//add p if doesn't exist, update it if it does
		($("p#title").length == 0) ? $("<p>").attr("id", "title").text(title).appendTo("div#controls") : $("p#title").text(title) ;
	});
	//restart on mouseout
	$("a.wrapper").live("mouseout", function(e) {
		//hide controls if not hovering on them
		(e.relatedTarget == null) ? null : (e.relatedTarget.id != "controls") ? $("div#controls").slideUp("slow").remove() : null ;
		//work out total travel distance
		var totalDistance = parseInt($("div#container").width()) + parseInt($("div#viewer").width());
		//work out distance left to travel
		var distanceLeft = ($("div#container").hasClass("ltr")) ? totalDistance - (parseInt($("div#container").css("left")) + parseInt($("div#container").width())) : totalDistance - (parseInt($("div#viewer").width()) - (parseInt($("div#container").css("left")))) ;
		//new duration is distance left / speed)
		var newDuration = distanceLeft / speed;
		//restart anim
		animator($("div#container"), newDuration, $("div#container").attr("class"));
	});
	
	
	
	
	
	
	$(".reservations ul li a").each(function(){
		$(this).css("padding","5px 20px 5px 19px");
	});
	
	$(".nav li ul").each(function(){
		if ($.browser.msie && $.browser.version.substr(0,1)<8){
			$(this).css("padding-top","11px").css("padding-bottom","12px");
		}
		else if ($.browser.msie && $.browser.version.substr(0,1)<9){
			$(this).css("padding-top","14px").css("padding-bottom","13px")
		}
		else{
			$(this).css("padding-top","13px").css("padding-bottom","14px");
		}
		
	});
	
	$(".topSection ul li:last").css("padding","3px 0 0 15px");
	$(".topSection ul li:first").css("padding","3px 0 0 20px");
	

	
	
	
	
	
	
	
function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

	
	
	

	
	
	
	
	
}); // END DOM





function mainImageFlow()
{
	// set the opacity of image(s) to 0 (can't see them)
	$('#mainImageBox img').css({opacity: 0.0});
	// set the first image to be seen
	$('#mainImageBox img:first').css({opacity: 1.0});
	// set the function for 'mainImageGallery' to run every 3 seconds.
	setInterval('mainImageGallery()',3000);
}
function mainImageGallery()
{
	// if the images have no class (class='show') then show the first one anyway
	var current = ($('#mainImageBox img.show')?  $('#mainImageBox img.show') : $('#mainImageBox img:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('sNav'))? $('#mainImageBox img:first') :current.next()) : $('#mainImageBox img:first'));	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	$("#subNavBox").removeClass('show');
}
function openSendFriendPop()
{
	var linkURL = $('a[rel="send_to_friend"]').attr("href");
	window.open(linkURL,"Send to a Friend","menubar=no,width=580,height=240,toolbar=no" );
	return false;
}
function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=580,height=240,left = 350,top = 392');");
}



