$().ready(function()
	{
		
		
		$('a[id^=button_]').click //Adding the following function to every a with an id that starts with button.
			(
				
				function(event)
				{
					//runs twice beacuse of back button support, but think it stops before animation.
					event.preventDefault();
					
					//We remove the button_ from the id and replace it with content_.
					var currentId = this.id;
					var id_to_be_animated = currentId.substring(7, currentId.length);
					
					//And we add the page id to the adress bar
					window.location.hash = id_to_be_animated;
					
					var title = id_to_be_animated
					title = title.replace(/_/gi, " ");
					if (title == "Movies About com")
					{
						title = "Movies-About.com"
					}
					if (title == "home")
					{
						tile = "News";
					}
					title = title.charAt(0).toUpperCase() + title.slice(1);
					if(title == "ITrust")
					{
						title = "iTrust";
					}
					document.title = "Jorgnsn | " + title
					
					//Then we add the _content in the start
					id_to_be_animated = "content_" + id_to_be_animated;
					
					//We find the current visible div and hide it
					$('#[id^=content_]').each
						(
							function(i)
							{
								if($('#'+this.id).is(":visible"))
								{
									if(id_to_be_animated != this.id)
									{	
										$('#'+this.id).hide();
										_gaq.push(['_trackPageview']); //Updates analytics tracking maybe
										
										
									}
								}
							}
						);
					//We remove the active class from the active nav_button and putit on the slicked button.
					
					$('.button_active').removeClass('button_active');
					$(this).addClass('button_active');
					
					//We animate in the new div. if the hight of the new div is longer then box, we slidedown
					if($('#'+id_to_be_animated).height() > $('.info_box_mid').height())
					{
						$('#'+id_to_be_animated).slideDown('fast');
						
					}
					else
					{
						$('#'+id_to_be_animated).fadeIn('fast');
						
					}
					
				}
			)
	
		//Seting up the scrolling on select_box
		$('.select_box_arrow').click
			(
				function(event)
				{
					event.preventDefault();
				}
			)
		$('.select_box_arrow').mousedown
			(
				function(event)
				{
					
					var speed = 300;
					var select_box_content_height = get_select_box_content_height()
					var step = select_box_content_height/get_select_box_children();
					var select_box_content_wrapper_height = $('#select_box_content_wrapper').height();
					
					if($('#select_box_content').is(':animated') == false)
					{
						if(this.id == "arrow_up")
						{
							
							if($('#select_box_content').css('marginTop').replace("px","")+step <= 0) //if we are at first item.
							{
								$('#select_box_content').animate({marginTop: '+='+step}, speed);	
							}
						}
						else //arrow_down
						{
							max_y = select_box_content_wrapper_height - select_box_content_height-5;
							pos_y = $('#select_box_content').css('marginTop').replace("px", "");
							
							if(pos_y-step >= max_y) //if we are at last item.
							{
								$('#select_box_content').animate({marginTop: '-='+step}, speed);
							}
							
						}
					}
					
					
					
					
				}
			
			)
		
		//iOs touch
		//$('a.works_icon').live('touchend', function(e) 
		//	{
    	//		var current = $(this);
    	//		current.trigger("click");
    	//		this.innerHTML = "peder";
    			
		//	}
		//);
		//icon_small_shadow
		
		
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    		//Disable hover if on iDevice, if not here iOs must doubble click	
    	}
		else
		{
		$('a.works_icon').mouseover
		(	
			function()
			{
				var shadow_to_be_animated_id = "shadow_" + (this.id.substr(7)); //7 is word button. probably dodgy way of doing it
				$('#'+shadow_to_be_animated_id).fadeIn('fast');
			}
		)
		$('a.works_icon').mouseout
		(	
			function()
			{
				var shadow_to_be_animated_id = "shadow_" + (this.id.substr(7)); //7 is word button. probably dodgy way of doing it
				$('#'+shadow_to_be_animated_id).fadeOut('fast');
			}
		)
		}
		
		set_content_from_hash_url();
		
		//if backbutton pressed reloads hash.
		var hash = location.hash;
		setInterval(function()
		{
    		if (location.hash != hash)
    		{
        		hash = location.hash;
        		set_content_from_hash_url();
        	}
			}, 100);
		
		
		//Morroskyld
		//setInterval(function()
		//{
    	
    	//	animateInfoBoxDown();
		
    	//}, 20);
		
		
		}
		
		
		

);
var MarginTop = 10;
var Speed = 0;
//morro
function animateInfoBoxDown()
{
	$('#info_box').animate({"marginTop": MarginTop});
	//$('#info_box').css({"marginTop": MarginTop});
	MarginTop +=Speed
	Speed += 0.3;
}

function get_select_box_children()
{
	return $('#select_box_content').children().length;
}
function get_select_box_content_width()
{
	var num_of_children = get_select_box_children();
	var child_0 = $('#select_box_content').children()[0];
	var margin = 40;
	return ($(child_0).width()+margin)*num_of_children;
}
function get_select_box_content_height()
{
	var num_of_children = get_select_box_children();
	var child_0 = $('#select_box_content').children()[0];
	var margin = 10;
	return ($(child_0).height()+margin)*num_of_children;
}
function set_content_from_hash_url()
{
	
	if(window.location.hash != "")
	{
		var location = window.location.hash.substring(1);
		button_to_be_clicked = $('#button_' + location)
		button_to_be_clicked.click();
		
		
	}

}







