var default_content="";

$(document).ready(function(){
	
	checkURL();
	$('ul li a').click(function (e){

			checkURL(this.hash);

	});
	
	//filling in the default content
	default_content = $('#pageContent').html();
	
	
	setInterval("checkURL()",250);
	
});

var lasturl="";

function checkURL(hash)
{
	if(!hash) hash=window.location.hash;
	
	if(hash != lasturl)
	{
		lasturl=hash;
		
		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content
		
		if(hash=="")
		$('#content').html(default_content);
		
		else
		loadPage(hash);
	}
}


function loadPage(url)
{
	url=url.replace('#','');
	if(url!="top"){
	$('#loading').css('visibility','visible');
	
	$.ajax({
		type: "POST",
		url: "load_page.asp",
		data: 'page='+url,
		dataType: "html",
		success: function(msg){
			
			if(parseInt(msg)!=0)
			{
				$('#content').html(msg);
				$('#loading').css('visibility','hidden');
				if(url=="products"){
					
					var total = $('#slider img').length;
					var rand = Math.floor(Math.random()*total);
					$('#slider').nivoSlider({
						startSlide:rand,
						slices: 13, // For slice animations
						boxCols: 18, // For box animations
						boxRows: 7
					});
					//$('#slider').nivoSlider();
				}
			}
		}
		
	});
	}
}
