Event.observe(window, "load", function(){
	if($("designs")){
		$$("#goto_links li a").each(function(n){
			Event.observe(n, "click", function(){
				var obj = n.getAttribute("rel");
				if($(obj).style.display == "none") $(obj).style.display = "block";
				new Effect.ScrollTo(obj);
				new Effect.Highlight(obj, {startcolor: '#9b2c2e', endcolor: '#000000'});
			});
		});
		$$("#show_designs li a").each(function(n){
			Event.observe(n, "click", function(){
				var obj = n.getAttribute("rel");
				if(obj == "websites"){
					if($("logo_div").visible()) $("logo_div").slideUp(); 
					if(!$("website_div").visible()) $("website_div").slideDown();
				}
				else if(obj == "logos"){
					if($("website_div").visible())$("website_div").slideUp();
					if(!$("logo_div").visible()) $("logo_div").slideDown();
				}
				else if(obj == "both"){
					if(!$("website_div").visible()) $("website_div").slideDown();
					if(!$("logo_div").visible()) $("logo_div").slideDown();
				}
			});
		});
	}
	else if($("projects")){
		$$("#right ul li a").each(function(n){
			var filter = n.getAttribute("rel");
			var lower = 0.2, upper = 1.0;
			Event.observe(n, "click", function(){
				var fades = [];
				$$("#main a").each(function(a){
					a.observe("mouseover", function(){
						if(a.getStyle("opacity") == lower){
							var _fade = function(){
								a.fade({from:upper, to:lower, duration: 0.3});
								a.stopObserving("mouseout", _fade);
							}
							a.appear({from:lower, to:upper, duration:0.3});
							a.observe("mouseout", _fade);
						}
					});
					if(!a.getAttribute("rel").match(filter) && a.style.opacity != lower)
						fades.push(new Effect.Fade(a, {from:upper, to:lower, sync: true,afterFinish: function(){a.setStyle({opacity: lower})}}));
					else if(a.getAttribute("rel").match(filter) && a.style.opacity == lower)
						fades.push(new Effect.Appear(a, {from:lower, to:upper, sync: true,afterFinish: function(){a.setStyle({opacity:upper})}}));					
				});
				new Effect.Parallel(fades, {duration: 0.3});
			});
		});
		$$("#main a").each(function(n){
			Event.observe(n, "mouseover", function(e){
				$("helper").setStyle({
					left: Event.pointerX(e)+10+"px",
					top: Event.pointerY(e)+10+"px"
				});
				$("helper").update("<h3>"+n.firstChild.getAttribute("alt")+"</h3>");
				switch($("helper").firstChild.innerHTML){
					case "A*": $("helper").insert("<p>A simple pathfinding excersice</p><p>Language: Javascript</p>"); break;
					case "say": $("helper").insert("<p>Just an ajax experiment with google charts</p><p>Languages: JS/PHP/SQL</p>"); break;
					case "textcalc": $("helper").insert("<p>Creates a statistical breakdown of texts</p><p>Languages: JS/PHP</p>"); break;
					case "matchmaker": $("helper").insert("<p>Tries to find compatible users based on interests</p><p>Languages: JS/PHP/SQL</p>"); break;
					case "formCreator": $("helper").insert("<p>Dynamic web-based form-creation tool</p><p>Language: Javascript</p>"); break;
					case "modal": $("helper").insert("<p>Yet another modalbox for the web. This one is based off of</p><p>Language: JS</p>"); break;
					case "Beard Logger": $("helper").insert("<p>Watch the evolution of my beard over time</p><p>Languages: PHP/JS/SQL</p>"); break;
				}
				$("helper").style.display = "block";
			});
			Event.observe(n, "mousemove", function(e){
				$("helper").setStyle({
					left: Event.pointerX(e)+10+"px",
					top: Event.pointerY(e)+10+"px",
					opacity: "0.9"
				});
			});
			Event.observe(n, "mouseout", function(){ $("helper").style.display = "none"; });
		});
	}
	else if($("contact")){
		Event.observe("contact_form", "submit", function(e){
			Try.these(
				function(){e.stopPropagation();},
				function(){e.preventDefault();}
			);
			$("contact_form").request({onComplete: function(transport){
				$("main").update("<h2>Thank You</h2><p>Your message has been sent.</p>");
			}});
				$("main").update("<img src=\"images/ajax-loader.gif\" class=\"loader\" alt=\"Loading...\"/>");
		});
	}
});
