$(document).ready(function()
{					
	$("a").live("click", function()
		{
			var href = $(this).attr("href").replace(/#/g, "");//Takes out the # in the href
			var classLink = $(this).attr("class");
			switch(classLink)
				{
					case "toPage":
					if($(this + ":last"))
						{
							$("html, body").animate({scrollTop: 0},"slow");
						}
					$(".banner").fadeOut("slow", function ()
						{
							$(".header .loader").fadeIn("slow");
							$(".page").animate({opacity: 0}, "slow", function ()
										{
											$(".page").slideUp("slow", function ()
												{
													$(".content .loader").fadeIn("slow", function ()
														{
															$(".banner").load("pages/" + href + "/header.php?p=" + Math.random(), function ()
																{
																	$(".page").load("pages/" + href + "/content.php?p=" + Math.random(), function ()
																		{
																			$(".page").css("opacity", 0);
																			
																			$(".header .loader").fadeOut("slow", function ()
																				{
																					$(".banner").fadeIn("slow");
																				});
																			$(".page").slideDown("slow", function ()
																				{
																					$(".content .loader").fadeOut("slow", function ()
																						{
																							$(".page").animate({opacity: 1}, "slow");
																						});
																				});
																		});
																});
														});
												});
										});
						});
				break;
				case "toProject":
						$("html, body").animate({scrollTop:0},"fast", function()
							{
							$(".whiteout").css("background", "#FFF");
							$(".wrapper").fadeOut("slow", function()
								{
									$(".banner, .page").html("");
									$(".whiteout").fadeIn("slow", function ()
										{
											$(".progress").fadeIn("slow");
											$("html, body").css("background", "url(pages/" + href + "/bg.png) top left");
											$(".bar").animate({width:25},"fast");
											$(".banner").load("pages/" + href + "/header.php", function()
												{
													$(".bar").animate({width:50},"fast");
													$(".page").load("pages/" + href + "/content.php", function()
														{
															$(".bar").animate({width:100},"fast");
															$(".progress").fadeOut("slow", function ()
																{
																	$(".whiteout").fadeOut("slow", function()
																		{
																			$(".toPage").each(function ()
																				{
																					$(this).attr("class", "fromProject");
																				});
																			$(".icons ul li a img").each(function ()
																				{
																					var src = $(this).attr("src");
																					$(this).attr("src", src.replace("orange","grey"));
																				});
																			$(".wrapper").fadeIn("slow", function ()
																				{
																					$(".prev, .next").fadeIn("slow");
																				});
																		});
																});
														});
												});
										});
								});
						});
				break;
				case "fromProject":
					$(".next, .prev").fadeOut("slow");
					$("html, body").animate({scrollTop:0},"fast", function()
						{
							$(".wrapper").fadeOut("slow", function()
								{
									$(".banner, .page").html("");
									$(".whiteout").fadeIn("slow", function ()
										{
											$(".progress").fadeIn("slow");
											$("html, body").css("background", "#FFD800 url(css/body/bg.png) top left no-repeat");
											$(".bar").animate({width:25},"fast");
											$(".banner").load("pages/" + href + "/header.php", function()
												{
													$(".bar").animate({width:50},"fast");
													$(".page").load("pages/" + href + "/content.php", function()
														{
															$(".bar").animate({width:100},"fast");
															$(".progress").fadeOut("slow", function ()
																{
																	$(".whiteout").fadeOut("slow", function()
																		{
																			$(".fromProject").each(function ()
																				{
																					$(this).attr("class", "toPage");
																				});
																			$(".icons ul li a img").each(function ()
																				{
																					var src = $(this).attr("src");
																					$(this).attr("src", src.replace("grey","orange"));
																				});
																			$(".wrapper").fadeIn("slow");
																		});
																});
														});
												});
										});
								});
						});
				break;
			}
		});
		var browser=navigator.appName;
		$(".icons ul li a img").hover(
			function ()
				{
					if(browser=="Microsoft Internet Explorer")
						{
							$(this).animate({marginTop: "-5px"},"fast");
						}
					else
						{
							$(this).animate({marginTop: "-5px",opacity: 1},"fast");
						}
				},function ()
				{
					if(browser=="Microsoft Internet Explorer")
						{
							$(this).animate({marginTop: "15px"},"fast").animate({marginTop: "0px"},"fast");
						}
					else
						{
							$(this).animate({marginTop: "15px",opacity: .25},"fast").animate({marginTop: "0",opacity: .5},"slow");
						}
				});
			if(browser!="Microsoft Internet Explorer")
				{
					$(window).keydown(function (e)
						{
							switch(e.which)
								{
									case 80: $("a[href='#portfolio']:first").trigger('click');
									break;
									case 69: $("a[href='#equipment']:first").trigger('click');
									break;
									case 67: $("a[href='#contact']:first").trigger('click');
									break;
									case 72: $("a[href='#home']:first").trigger('click');
									break;
									case 83: $("a[href='#services']:first").trigger('click');
									break;
									case 27: killPage();
									break;
								}
						});
				}
		function killPage()
			{
				var r=confirm("You pressed the escape key.  If you want I could refresh the page for you and we can see if that will help you.  So if you want press ok and I will fresh the page, otherwise, click cancel and you'll remain on this page");
				if (r==true)
					{
						window.location.reload();
					}
			}
});
