var nav = new Array();
var direct = false;
var init_nav = function()
{
	$('a').each(function(){
		if($(this).attr('id')!=='') {
			nav.push($(this));
			$(this).click(function(){
				for(var i=0;i<nav.length;i++) {
					$(nav[i]).removeClass('selected');
				}
				$(this).addClass('selected');	
				toLoad = $(this);
				$('#image_block').fadeOut('def',function(){
					load_project();
				});
				if(direct) location = '/#/'+$(this).attr('id');
				else location.hash = '#/'+$(this).attr('id');
				return false;
			});
		};
	});
}

var load_project = function()
{
	$('#loader').show();
	targ = toLoad;
	$.get("includes/"+targ.attr('id')+".html",
	       {},
	       function(returned_data)
	       {
	       $('#loader').hide();
			$('#image_block').fadeIn('def');
	        $('#image_block').html(returned_data);	
	         
	       });
	//	}
	
}

$(document).ready(function(){
	init_nav();
	if(!direct) {	
		var loc = document.location.hash.replace('#/','');
		if(!loc.length) toLoad = $('#unit');
		else toLoad = $('#'+loc);
		if(toLoad) toLoad.click();		
	}	else {
		$('#image_block').fadeIn('def');
	}
});