$(function()
{
	var allowAnim = true;
	
	$("#index #slideshow .slides").cycle();
	
	numSlides = $("#slideshow .slides img").length;
	/*$("#slideshow .slides img").each(function(i)
	{
		$(this).css("z-index", numSlides);
		numSlides--;
	});
	$("#slideshow .thumbs a").click(function(){return false});*/
	
	$("#slideshow .thumbs a").click(function()			
	{	
		index = $("#slideshow .thumbs a").index(this);			
		$("#slideshow .slides img").fadeOut(500)
		$("#slideshow .slides img:eq(" + index + ")").stop().fadeIn(500)
		return false;
	});
	// This code breaks IE6. It centers the subnavs vertically according to their height.
	$(".subnav").each(function(i)
	{
		var top = (parseInt($(this).height()) / 2) - 6;
		$(this).css("top", ("-" + top + "px")).hide();
	});
	$("li.active .subnav").show();
	
	if($("div.modalContentHP img").length>0){	
		loadHomeModal($("div.modalContentHP img").get(0));
	}
	
	$("ul#nav li.active .subnav").addClass("hold");
	$("ul#nav li:not(ul#nav li.active, ul#nav .subnav li)").hover(function()
	{
		if(!$(this).parent().hasClass("hold"))
			$(".hold").hide();
		
		$(this).addClass("active");
		$(".subnav", $(this)).show();
	}, function()
	{
		$(this).removeClass("active");
		$(".subnav", $(this)).hide();
		
		if($(this).parent().attr("id")=="nav")
			$(".hold").show();
	});
	$("a.modal-link").click(function()
	{
		loadModal(780, "/layout/set/modal/"+$(this).attr("href"));
		return false;
	});
	$(".sidebar-slides .slide-container").cycle(
	{
		fx: "scrollHorz",
		cleartype: false,
		speed: 700,
		timeout: 6000,
		pager: ".sidebar-slides ul.slide-pager",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">' + slide + '</a></li>'; 
		}
	});
	
	
	   
    
});

function loadModal(mWidth,mURL)
{
	$("#sitewrapper").after('<div id="overlay">&nbsp;</div><div id="modal"><div id="modal-content"><img src="../images/spinner.gif"></div></div>');
	$("#overlay").css({width:$("body").width(),height:$(document).height()}).show();
	$("#modal").css({"top":($(document).scrollTop()+100),"left":($(window).width()/2)-(mWidth/2)});
	$("#modal").animate({"width":mWidth,"height":"50px"},250,function(){
		$("#modal-content").load(mURL,function(){
			$("#modal").animate({"height":$("#modal-content").outerHeight(true)},500,function(){
				$("#overlay").css({height:$(document).height()});
			});

			$("#overlay, #modal-content p.close a").click(function(){
				$("#modal").animate({"height":"50px"},500,function(){
					$("#modal-content").html("&nbsp");
					$("#modal").animate({"width":"0px","height":"0px"},500,function(){
						$("#modal").remove();
						$("#overlay").remove();
					});
				});
				return false;
			});
		});
	});
}

function loadHomeModal(content)
{	
	if ($.cookie("modalHP") != "true") {
		if (content.parentNode.tagName.toLowerCase() == "a") {
			modalLink = $(content.parentNode).attr("href");
		} else {
			modalLink = 'http://www.thayerinteractive.com/clickthru/clickthrough.rry/105458';
		}
		$("#sitewrapper").after('<div id="overlayHP">&nbsp;<script type="text/javascript" language="JavaScript">var gpgName="Splash Page";</script></div><div id="modalHP"><div id="modalContentHP"></div><a href="'+modalLink+'" id="modalBookNow" name="omni_reservation_splash" target="_blank">Book Now</a><a href="#" id="modalClose">Close</a><a href="#" id="modalContinue">Continue</a></div>');
		//$("#overlay").fadeIn(function(){	
			$("#modalContentHP").replaceWith(content);
			$("#modalHP, #modalHP img").show();
		
			if ($.browser.msie == true && $.browser.version.indexOf("6") > -1){
				$("#modalHP").css({
			        "top":($(document).scrollTop()+100),
		           "left":(($(window).width()/2)-($("#modalHP img").attr("width")/2))
				});
			} else {
				$("#modalHP").css({
			        "top":("100px"),
		           "left":(($(window).width()/2)-($("#modalHP img").attr("width")/2))
				});
			}
		
		
			$("#modalHP a#modalClose, #modalHP a#modalContinue").click(function(){
				$("#modalHP").remove();
				$("#overlayHP").fadeOut(function(){$("#overlayHP").remove();});
				$.cookie("modalHP", "true", { path: '/' });
			
			});
		//});
	}
}