var bg = new Array();

bg[0] = "1.jpg";
bg[1] = "2.jpg";
bg[2] = "3.jpg";
bg[3] = "4.jpg";
bg[4] = "5.jpg";
bg[5] = "6.jpg";
bg[6] = "7.jpg";
bg[7] = "8.jpg";
bg[8] = "9.jpg";
bg[9] = "10.jpg";

var i = 1;

$(document).ready(function()
{
	/*
	$("#content").css("top", "-1000px");
	$("#footer").hide();

	$("#content").delay(3000).animate({"top":"0px"}, 2500, function()
	{
		$("#footer").fadeIn("slow");
	});*/
	
	// Fix height of box
	if($("ul.subnav > li").size() > 1 && $("ul.subnav li.selected a").attr("href") != "#stills")
	{
		var newHeight = $(".page:first").outerHeight();
		$(".inner").css({"height":newHeight + "px"});
	}
	
	$("h1 a").hover(function()
	{
		$(this).stop().animate({paddingLeft:"15px", backgroundPosition:"0px 0px"}, 200);
	}, function()
	{
		$(this).stop().animate({paddingLeft:"0px", backgroundPosition:"-15px 0px"}, 200);
	});
	
	$("#header ul.nav li.selected a").css({backgroundColor:"#586FFF"}).delay(1000).animate({paddingBottom:"5px", marginTop:"-5px"}, 100);
	
	$("#header ul.nav li:not(.selected) a").hover(function()
	{
		$(this).stop().animate({backgroundColor:"#586FFF",paddingBottom:"5px", marginTop:"-5px"}, 100);
	}, function()
	{
		$(this).stop().animate({backgroundColor:"#D34A47",paddingBottom:"0px", marginTop:"0px"}, 200);
	});
	
	$("#header ul.social a").hover(function()
	{
		$(this).stop().animate({paddingBottom:"5px", marginTop:"-5px"}, 100);
	}, function()
	{
		$(this).stop().animate({paddingBottom:"0px", marginTop:"0px"}, 200);
	});
	
	fadeBackground();
	sortNav();

	// Gallery
	$("ul.gallery a").bind("click", function()
	{
	var link = $(this);
		
		if(link.attr("href").replace("/thumbs","") != $("div.viewer img").attr("src"))
		{
		
			$("ul.gallery a img").css({opacity:1.0});
		
			$(this).children("img").stop().animate({opacity:0.5}, 200, function()
			{
				$("div.inner").removeAttr("style");


				$("div.viewer").slideUp(200, function()
				{
					$("div.viewer").empty().append("<img src='" + link.attr("href").replace("/thumbs","") + "' class='loadingimage' />");

					$("img.loadingimage").load(function()
					{
						$("div.viewer").slideDown(500);
					});
				});
			});
		}	
		
		return false;
	});
});

function fadeBackground()
{
	if($("ul.subnav li.selected a").attr("href") != "#trailer")
	{
		$("#background").append("<img src='/lib/images/backgrounds/" + bg[i] + "' class='top' />");
	
		$("img.top").load(function()
		{
			$(this).delay(10000).fadeIn("slow", function()
			{
				$("#background img:first").remove();
				$(this).removeClass("top");
			
				if(i < bg.length - 1)
				{
					i++;
				}
				else
				{
					i = 0;
				}
				
				fadeBackground();
			});
		});
	}
}

function sortNav()
{
	$(".subnav a, a.internal").bind("click", function()
	{
		$(".subnav li").removeClass("selected");
		$(this).parent().addClass("selected");
	
		
		var offset = $($(this).attr("href")).position();
		var newHeight = $($(this).attr("href")).outerHeight();
		
		//alert(offset.left);
		
		$(".inner").stop().animate({"marginLeft":-offset.left + "px", "height":newHeight + "px"}, 500);
		
		return false;
	});
}
