$().ready(function() {
	var version = $.browser.versionNumber;
	if ($.browser.name == 'msie') {
		var $panels = $("#tabContent .panel");
		$($panels).each(function() {
			if ($(this).hasClass('main')) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
	} else {
		$("#aboveTheFold #tabContent .main h2, #aboveTheFold #tabContent .renovated h2, #aboveTheFold #tabContent .things h2, #aboveTheFold #tabContent .weddings h2, #aboveTheFold #tabContent .beachfront h2").css({'opacity':0});
		var currentState = 'main';
		loadContent(currentState);
	}
	$("#subnav li#newlyRenovated a, #subnav li#thingsToDo a, #subnav li#fullService a, #subnav li#location a").hoverIntent(
		function() {
			if ($.browser.name == 'msie') {
				$(this).addClass('active');
			} else {
				$(this).find('span.overlay').fadeIn(400);
			}		
		},
		function() {
			if ($.browser.name == 'msie') {
				$(this).removeClass('active');
			} else {
				$(this).find('span.overlay').fadeOut(400);
			}	
		}
	);
	$('#contentTriggerAmenities, #contentTriggerWeddings, #contentTriggerLocation').hoverIntent(
		function() {
			var relId = $(this).attr('rel');
			$("#"+relId).find('span.overlay').fadeIn(400);
		},		
		function() {
			var relId = $(this).attr('rel');
			$("#"+relId).find('span.overlay').fadeOut(400);
		}
	);
	$("#subnav #newlyRenovated a").click(function() {
		if ($.browser.name == 'msie') {
			var $panels = $("#tabContent .panel");
			$($panels).each(function() {
				if ($(this).hasClass('renovated')) {
					$(this).show();
				} else {
					$(this).hide();
				}
			});
		} else {
			$.scrollTo(0, 300);
			emptyTabContent(currentState);
			currentState = 'renovated';
			resetActivePanels();
			$("#subnav #newlyRenovated a").addClass('active');
			setTimeout(function() { 
				loadContent(currentState);
			}, 1000);
		}
	});
	$("#subnav #thingsToDo a, #contentTriggerAmenities").click(function() {
		if ($.browser.name == 'msie') {
			var $panels = $("#tabContent .panel");
			$($panels).each(function() {
				if ($(this).hasClass('things')) {
					$(this).show();
				} else {
					$(this).hide();
				}
			});
		} else {
			$.scrollTo(0, 300);
			emptyTabContent(currentState);
			currentState = 'things';
			resetActivePanels();
			$("#subnav #thingsToDo a").addClass('active');
			setTimeout(function() { 
				loadContent(currentState);
			}, 1000);
		}
	});
	$("#subnav #fullService a, #contentTriggerWeddings").click(function() {
		if ($.browser.name == 'msie') {
			var $panels = $("#tabContent .panel");
			$($panels).each(function() {
				if ($(this).hasClass('weddings')) {
					$(this).show();
				} else {
					$(this).hide();
				}
			});
		} else {
			$.scrollTo(0, 300);
			emptyTabContent(currentState);
			currentState = 'weddings';
			resetActivePanels();
			$("#subnav #fullService a").addClass('active');
			setTimeout(function() { 
				loadContent(currentState);
			}, 1000);
		}
	});
	$("#subnav #location a, #contentTriggerLocation").click(function() {
		if ($.browser.name == 'msie') {
			var $panels = $("#tabContent .panel");
			$($panels).each(function() {
				if ($(this).hasClass('beachfront')) {
					$(this).show();
				} else {
					$(this).hide();
				}
			});
		} else {
			$.scrollTo(0, 300);
			emptyTabContent(currentState);
			currentState = 'beachfront';
			resetActivePanels();
			$("#subnav #location a").addClass('active');
			setTimeout(function() { 
				loadContent(currentState);
			}, 1000);
		}
	});
});
function resetActivePanels() {
	var $kids = $("#subnav li a");
	$($kids).each(function() {
		if ($(this).hasClass('active')) {
			$(this).find('.overlay').show();
			$(this).removeClass('active').find('.overlay').fadeOut(500);
		}
	});
};
function resetPanelLocation(panel) {
	$("#tabContent ."+panel+".panel").css({'left':'0px'});
	$("#tabContent ."+panel+" .el").css({'top':'2000px'});
	$("#tabContent ."+panel+" .bg").css({'opacity':'0'});
};
function loadContent(panel) {
	resetPanelLocation(panel);
	setTimeout(function() { 
		$("#loader").fadeOut(500);
		$("."+panel+" .bg").animate({opacity: 0.9999}, 2000);
		$("."+panel+" h2").animate({opacity: 0.9999}, 2000);
	}, 1500);
	setTimeout(function() { 
		if (panel == 'main') {
			$(".main .el").animate({'top':203}, 1500).animate({'top':233}, 250);
			var currentState = 'main';
		} else if (panel == 'renovated') {
			$(".renovated .el").animate({'top':313}, 1500).animate({'top':323}, 250);
			var currentState = 'renovated';
		} else if (panel == 'things') {
			$(".things .el").animate({'top':265}, 1500).animate({'top':275}, 250);
			var currentState = 'things';
		} else if (panel == 'weddings') {
			$(".weddings .el").animate({'top':243}, 1500).animate({'top':253}, 250);
			var currentState = 'weddings';
		} else if (panel == 'beachfront') {
			$(".beachfront .el").animate({'top':310}, 1500).animate({'top':320}, 250);
			var currentState = 'beachfront';
		}
	}, 1500);
};
function emptyTabContent(currentState) {
	if (currentState == 'main') {
		$(".main .el").animate({'top':2000},500);
		$(".main .bg, .main h2").animate({opacity:0}, 500, 
			function() { 
				$("#tabContent .main").css({'left':'-9999px'}); 
				$("#loader").fadeIn(500);
			}
		);
	} else if (currentState == 'renovated') {
		$(".renovated .el").animate({'top':2000},500);
		$(".renovated .bg, .renovated h2").animate({opacity:0}, 500, 
			function() { 
				$("#tabContent .renovated").css({'left':'-9999px'}); 
				$("#loader").fadeIn(500);
			}
		);
	} else if (currentState == 'things') {
		$(".things .el").animate({'top':'2000'},500);
		$(".things .bg, .things h2").animate({opacity:0}, 500, 
			function() { 
				$("#tabContent .things").css({'left':'-9999px'}); 
				$("#loader").fadeIn(500);
			}
		);
	} else if (currentState == 'weddings') {
		$(".weddings .el").animate({'top':2000},500);
		$(".weddings .bg, .weddings h2").animate({opacity:0}, 500, 
			function() { 
				$("#tabContent .weddings").css({'left':'-9999px'}); 
				$("#loader").fadeIn(500);
			}
		);
	} else if (currentState == 'beachfront') {
		$(".beachfront .el").animate({'top':2000},500);
		$(".beachfront .bg, .beachfront h2").animate({opacity:0}, 500, 
			function() { 
				$("#tabContent .beachfront").css({'left':'-9999px'}); 
				$("#loader").fadeIn(500);
			}
		);
	}
};