function slideSwitchNext() {
	prevIMG = currentIMG;
	$('#slideshow img').eq(prevIMG).addClass('last-active');
	
	if (next==true){
		currentIMG++;
		if(currentIMG > totIMGS) {
			currentIMG = 0;
		}
	}
	
	if (next==false){
		currentIMG--;
		if(currentIMG < 0) {
			currentIMG = totIMGS;
		}
	}

	$("#slideshow .numbers").hide();
	thealt=$('#slideshow img').eq(currentIMG).attr("alt");
	var thetimeout=	setTimeout ( showalt , 500 );

		
	$('#slideshow img').eq(currentIMG).addClass('active').animate({opacity: 1.0}, 1000,function() {
           $('#slideshow img').eq(prevIMG).removeClass('active last-active').css({'opacity': '0.0'});
			newurl=$("#slideshow img.active").parent().attr("href");
			$("li.more_details a").attr("href",newurl);
    });	
}

function showalt(){
	$('#slideshow img').eq(currentIMG).after("<span class='numbers'>"+thealt+"</span>");	
}

$(document).ready(function(){
	pageID = document.location.hash.substring(1);
	pageIDHash = document.location.hash;

	$('.sub_section3').hide();
	
	//------------------------------------------------SLIDE SHOW
	
	$('#slideshow img').css({opacity: 0.0});
	$('#slideshow img').eq(0).css({opacity: 1.0});
	
	totIMGS = $('#slideshow img').length - 1;
	currentIMG = 0;
	next = true;
	pause = false;
	var myInterval = window.setInterval('slideSwitchNext()', 3000 );	


	$('li.pause a').live('click', function(){
		if (pause == false) {
			pause = true;
			alert('pause');
			window.clearInterval(myInterval);
		}
		else {
			pause = false;
			alert('play');
			var myInterval = window.setInterval('slideSwitchNext()', 3000 );				
		}
	});
	
	$('li.next a').live('click', function(){
		next = true;		
		window.clearInterval(myInterval);
		slideSwitchNext();
	});
	
	$('li.prev a').live('click', function(){
		next = false;
		window.clearInterval(myInterval);
		slideSwitchNext();
	});
	
	//------------------------------------------------NIGHTS DROPDOWN
	$('ul#nights a').eq(0).addClass('active');
	
	$('input[type=text].nights').focus(function(){
		offset = $(this).offset();
		$('ul#nights').css({'top': offset.top + 17, 'left': offset.left});
		$('ul#nights').slideDown(200);
	});
	

	$('ul#nights li a').live('click', function(){
		var_nights = $(this).html();
		$('ul#nights li a').removeClass('active');
		$(this).addClass('active');
		$('input[type=text].nights').attr('value', var_nights);
		$('ul#nights').slideUp(200);
		return false;

		
	});
		
	
	if (pageID == ""){
		$('.sub_section3').eq(0).show();
	}
	else {
		$('.'+pageID).show();
		$('ul.subnav3').find('a.'+pageID).addClass('active');
	};
		
	
	$('#signup_type input[type=radio]').click(function(){
		$('#peak_rewards_wrap, #free_slot_play_wrap, #dining_wrap').hide();		
		signupType = $(this).val();
		$('#'+signupType+'_wrap').show();
	});
	
	$('ul.subnav3 li a').click(function(){
		$('ul.subnav3 li a').removeClass('active');	
		sectionID = $(this).attr('href').substring(1);
		sectionIDHash = $(this).attr('href');
		$('.sub_section3').hide();
		$('.'+sectionID).show();	
		$(this).addClass('active');	
	});
	
	$('a.sign_up, a.free_slot_play').click(function(){
		$('ul.subnav3 li a').removeClass('active');	
		$('.sub_section3').hide();
		sectionID = $(this).attr('class');
		$('.'+sectionID).show();	
		});
	
	
	$('ul#hotel_packages a').click(function(){
		details = $(this).parent().find('.details');
		if ($(details).css('display')=='none'){
			$('ul#hotel_packages .details').slideUp();
			$(details).slideDown();
			return false;
		}
		else {
			$(details).slideUp();
			return false;
		}
		
	});
	
	//------------------------------------------------GRAB PAGE URL STRING

	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	
	
	//------------------------------------------------ADMIN ACTIONS
	if ($('form').attr('class') == 'admin'){
		$('ul.subnav3 li a').click(function(){
			$('form.admin').attr('action', sPage + '?u=1' +	$(this).attr('href')); 
		});
	}
		

	/** rotator start **/

	$('ul.subnav3 li a').click(function(){
		theindex=$("ul.subnav3 li a").index(this);
		$("img.center_img").attr("src", rotatorpics[theindex]);
	});
	
	loadedindex=$("ul.subnav3 li").index($("ul.subnav3 li a.active").parent());
	$("img.center_img").attr("src",rotatorpics[loadedindex]);



	//------------------------------------------------REQUIRED FIELD FORM VALIDATION
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
		phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please enter a valid phone number");
	
	$('form#request_wedding_info, form#request_meeting_proposal').validate({
		  rules: {
			  field: {
			  required: true,
			  phoneUS: true
			}
		  }
	});

	$('form#dining_newsletter').validate({
		rules: {
			required: "required",
			email_confirm: {
				required: true,
				equalTo: "#email"
			}
		},
		messages: {
			email_confirm: {
				required: "Please confirm your email",
				equalTo: "Emails do not match"
			}
		}
	});
				
	$('form.emailmenuform').validate();
	$('form.bienreservationform').validate();
	$('form#buildpackageform').validate();
	$('form.privatediningform').validate();
	$('form#wedding_contact_sales').validate();
});
