	
	var intval = "";
	var hideDelay = 100;
	var hideDelayTimer = null;
	
	function slideimagenext(){
		var $active = $('div.imagegallery img.active');
		if($active.length == 0)
			$active = $('div.imagegallery img:last');
		var $next = $active.next().length ? $active.next() : $('div.imagegallery img:first');
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function(){
			$active.removeClass('active last-active');
		})
	}

	
	function slideswitchnext(){
		var $active = $('div.gallery img.active');
		if($active.length == 0)
			$active = $('div.gallery img:last');
		var $next = $active.next().length ? $active.next() : $('div.gallery img:first');
		$active.addClass('last-active');
		$(".title span").fadeOut(100, function(){
			$(this).html( $active.next().length ?  $active.next().attr("title") : $('div.gallery img:first').attr("title")).fadeIn(500)							   
	     });
		$(".booknow1 a").attr("href", $active.next().length ?  $active.next().attr("alt") : $('div.gallery img:first').attr("alt"));
		$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function(){
			$active.removeClass('active last-active');
		})
	}
	
	function slideswitchprev(){
		var $active = $('div.gallery img.active');
		if($active.length == 0)
			$active = $('div.gallery img:first');
		var $prev = $active.prev().length ? $active.prev() : $('div.gallery img:last');
		$active.addClass('prev-active');
		$(".title span").fadeOut(100, function(){
			$(this).html( $active.prev().length ? $active.prev().attr("title") : $('div.gallery img:last').attr("title")).fadeIn(500)							   
	     });
		$(".booknow1 a").attr("href", $active.prev().length ?  $active.prev().attr("alt") : $('div.gallery img:last').attr("alt"));
		$prev.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function(){
			$active.removeClass('active prev-active');
		})
	}

	function imgSwap(oImg, type)
	{
	   var strOver  = "_o."+type;    // image to be used with mouse over
	   var strOff = "."+type;    // normal image
	   var strImg = oImg.src
	   if (strImg.indexOf(strOver) != -1) 
		  oImg.src = strImg.replace(strOver,strOff)
	   else
		  oImg.src = strImg.replace(strOff,strOver)
	}

	/*$(window).load(function(){ // after all the images are loaded
		if ($.browser.msie && parseInt($.browser.version.substr(0, 1)) < 7) { // ie6 or 5
			$("img.png").each(function(){
				$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $(this).attr('src') + "', sizingMethod='scale')").attr("src", "images/blank.gif");
			});
			$("div.png").each(function(){
				var bg = $(this).css("backgroundImage");
				bg.match(/^url[("']+(.*\.png)[)"']+$/i);
				bg = RegExp.$1;
				$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg + "', sizingMethod='crop')").css("backgroundImage", "none");
			});
		}
	});*/

$(document).ready(function(){
	intval = window.setInterval("slideswitchnext()", 4000);
	$(".title span").html($('div.gallery img.active').attr("title"))
	$(".nextbtn1 a").click(function(){
		window.clearInterval(intval);
		slideswitchnext();
		intval= window.setInterval("slideswitchnext()", 4000);
	});
	$(".prevbtn1 a").click(function(){
		window.clearInterval(intval);
		slideswitchprev();
		intval= window.setInterval("slideswitchnext()", 4000);
	});

	//### Major image on Show Detail page
	intval2 = window.setInterval("slideimagenext()", 4000);

	$("div#navi a").each(function(){
		if($(this).is(".active"))
		{
			$("div.activecorner").css({
				display: "block",
				left: $("div#navi a.active").position().left+120,
				width: $("div#navi a.active").width()+8
				}
			)
		}
	});
	
	$("div#navi a").mouseover(function(){
		$("div.activecorner").stop().animate({
			left: $(this).position().left+120,
			width: $(this).width()+8
			}
		)							   
	}).mouseout(function(){
		$("div.activecorner").stop().animate({
			left: $("div#navi a.active").position().left+120,
			width: $("div#navi a.active").width()+8
			}
		)							   
	});
	
	$('.gradient1').css("opacity",0.9);
	$('.selection > ul > li:first').click(function(){		
		$("ul", this).slideDown();
		$('.selection > ul > li:last > ul').slideUp();
	})
	
	$('.selection > ul > li:last').click(function(){				
		$("ul", this).slideDown();
		$('.selection > ul > li:first > ul').slideUp();
	})
	
	$('.selection').mouseleave(function(){	
		if (hideDelayTimer)
			clearTimeout(hideDelayTimer);
		hideDelayTimer = setTimeout(function () {
			hideDelayTimer = null;
			$('.selection ul ul').slideUp();				
		}, hideDelay);
	})
	
	
	//### MailingList
	var mailinglist_name = $("#mailinglist_name"),
	mailinglist_email = $("#mailinglist_email"),
	allFields = $([]).add(mailinglist_name).add(mailinglist_email),
	tips = $("#validateTips");
	function updateTips(t) {
		tips.text(t).effect("highlight",{},1500);
	}
	function checkLength(o,n,min,max) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass('ui-state-error');
			updateTips("Length of " + n + " must be between "+min+" and "+max+" characters.");
			return false;
		} else {
			return true;
		}
	}

	function checkEmail(o,n) {
		var pattern = new RegExp(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/i);
		if ( !( pattern.test( o.val() ) ) ) {
			o.addClass('ui-state-error');
			updateTips(n);
			return false;
		} else {
			return true;
		}
	}

	$("#mailinglist_dialog").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 250,
		modal: true,
		buttons: {
			'Sign Up': function() {
				var bValid = true;
				allFields.removeClass('ui-state-error');

				bValid = bValid && checkLength(mailinglist_name,"Name",2,48);
				bValid = bValid && checkEmail(mailinglist_email,"Please provide a valid e-mail address");

				if (bValid) {
					$.get("mailinglist_add.php", { name: mailinglist_name.val(), email: mailinglist_email.val() }, function(data){$('#signupform_email').val("Thank You");}, "html")
					$(this).dialog('close');
				}

			},
			'Skip this Step': function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			allFields.val('').removeClass('ui-state-error');
		}
	});
		
		
		
	$('#signupform_button').click(function() {
		$('#mailinglist_email').val($('#signupform_email').val());
		$('#mailinglist_dialog').dialog('open');
		return false;
	});

	
});
