$(document).click(function() { clicked = 1; });

function callback(hash)
{
	if(clicked == 0)
	{
		goto(hash);	
	}
	
	clicked = 0;
}
$(document).ready(function() {
	$.history.init(callback);
});	

var currentPage = "/";
function goto(page)
{
	if(page != "")
	{
		//console.log(page);
		page = page.replace("amp;","");
		//this.currentPage = page;
		$.ajaxSetup({
			'beforeSend' : function(xhr) {
				xhr.overrideMimeType('text/html; charset=ISO-8859-1');
			}
		});
		
		//console.log(window.location.pathname);
		if(window.location.pathname == "/")
		{
			window.location.hash = "" + page;
		}
		else
		{
			window.location.href = "http://www.spareit.nl/#" + page;	
		}
		$.get(page+"?jquery", 
			
			function(data){
				////ele = $(data).find('#pagina').html();
				_gaq.push(['_trackPageview', page]);
				var pagenew = data.replace(/href=\"(.*?)\"/g, 'onclick="goto(\'$1\')"');
				$('#pagina').html(pagenew);
				//$('#pagina').html(data);
				if(page.match(/winkelwagen/g))
				{
					$.get("/includes/chart.php", 
						function(data){
							$("#chart_content").html(data);
						});
				}
				
	
			});
	
		if(!page.match(/webshop\/[0-9]/g) && !page.match(/webshop.html/g) && !page.match(/hfdcat/g))
		{
			$("#right").css("display", "none");
			$("#pagina").css("width", "725px");
		}
		else
		{
			$("#right").css("display", "block");
			$("#pagina").css("width", "485px");
		}
	}
}

$(function(){
	$('#nav li:first').css("background-image", "none");
	$('#nav li:first a').css("padding-top", "0px");
});	

$(document).ready(function(){
	var page = $('#container').html();
	var pagenew = page.replace(/href=\"(.*?)\"/g, 'onclick="goto(\'$1\')"');
	pagenew = pagenew.replace(/href=\'(.*?)\'/g, 'onclick="goto(\'$1\')"');
	$('#container').html(pagenew);
	$('.menu_item:last a').css('border', 'none');
	
	$.get("/includes/chart.php", 
	function(data){
		$("#chart_content").html(data);
	});
	
});
