$(document).ready(function(){ 

	$.address.init(function(event) {
		
	
	}).change(function(event){
		if(event.value!="/"){ 
			loadContent(event.value);
		}else{
			loadContent("main.php");
		}
		setButtonClass($("a[href='" +event.value.substring(1,event.value.length)+ "']"))
	})
	
	function setButtonClass(theButton){
	
		$('.nav a').removeClass("active");
		theButton.addClass("active");
		
		
			$.address.title($.address.title().split(' | ')[0] + ' | ' + $('a[class="active"]').text());
	}	
	
	var contentLoader;
	
	function loadContent(content){
		$(".content").fadeOut(300,function(){
			$(".preloader").show();
			/*if(contentLoader){
				contentLoader.abort();
			}
			contentLoader = $.ajax({
    			url: content,
    			success: function(){
					$(".content").fadeIn(400);
					$(".content").show()
					$(".preloader").hide();
					var theImage = $('.content').find('img');
					theImage.preload({placeholder:'src/images/preloader.gif', onRequest: function(){theImage.fadeOut()}, onRequest:function(){theImage.fadeOut(0);}, onFinish:function(){theImage.fadeIn("slow")}});
    			}
			});*/
			
			$(this).load(content, function(){
				$(this).fadeIn(500);
				$('.image_folio a p').fadeOut(0);
				
				$('.image_folio a').mouseover(function(){
					$(this).find('p').fadeIn('fast');
					$(this).find('img').fadeTo('fast',0.15);
				});
				
				$('.image_folio a').mouseleave(function(){
					$(this).find('p').fadeOut('slow');
					$(this).find('img').fadeTo('slow',1);
				});
				
				$(".preloader").hide();
				var theImage = $('.content').find('#Loading-thumb');
				theImage.preload({placeholder:'images/loading-pic.gif', onComplete:function(data){$(data.original).fadeOut(0);$(data.original).fadeIn('slow')}});
				
					$(".preloader").hide();
				var theImage = $('.content').find('.#loading-about');
				theImage.preload({placeholder:'images/loading-about.gif', onComplete:function(data){$(data.original).fadeOut(0);$(data.original).fadeIn('slow')}});

			});
		})
	}
})				
