$(document).ready(function() {
	$("#sliding-navigation li.sliding-element a").each(function(i){
		$(this).click(function(){showSection("#"+this.id.substring(0,this.id.indexOf("-anchor")));});
	});
	showSection(document.location.hash);
	slide("#sliding-navigation", 25, 15, 150, .8);
	
	$(document).konami(function(){
		window.location="http://www.youtube.com/watch?v=R7yfISlGLNU&fmt=22";
	});
});

String.prototype.beginsWith = function(t) {
	return (t == this.substring(0, t.length));
}

function showSection(anchor) {
	var shown = false;
	$("#content div").each(function(i){
		if (anchor.beginsWith("#"+this.id)){
			$(this).show();
			shown = true;
		}else{
			$(this).hide();
		}
	});
	if (!shown) $("#home").show();
}

function slide(navigation_id, pad_out, pad_in, time, multiplier) {
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		$(this).css("margin-left","-180px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
}
