var used_ajax = false;

function setPage(p, c, s) {
	$(".category").val(c);
	$(".subcategory").val(s);
}

function LoadPage(page) {
	used_ajax = true;
	setPage("","","");
	if ( typeof LoadPage.lastpage == 'undefined' ) {
	}

	if (LoadPage.lastpage == page) {
		//alert('already loaded');
    } else {
    	var url = window.location.href.split('/');
    	LoadPage.lastpage = page;
		if (url[3] == 'shop') {	    
	    	var height = $("#content").height();
			$("#content").html("<h1>Loading...</h1><div style='height: " + height + "px;'></div>").load("/getpage.php?page=" + page);
			$("link[rel='stylesheet']").not("[href='/css/main.css']").remove();
			scroll(0,0);
			$.post("/setpage.php", {page: page});
		} else {
			$.post("/setpage.php", {page: page}, function() {
				document.location = '/shop/';
			});
		}
	}
}

function LoadMenu() {
	var index;
	$("#navlist ul:last li.selected").each(function() {
		index = $(this).parent().children("li").index(this) + 1;
	});
	$("#navlist").load("/getmenu.php", function() {
		if (index > 0) {
			$("#navlist ul:last li:nth-child(" + index + ")").addClass("selected");
		}
		$("#navlist a").click(function() {
			$("#navlist li").removeClass("selected");
			$(this).parent().addClass("selected");
		});	
	});
}

$(document).ready(function() {
	$("#navlist a").click(function() {
		$("#navlist li").removeClass("selected");
		$(this).parent().addClass("selected");
	});
});