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);
			scroll(0,0);
		} else {
			$.post("/setpage.php", {page: page}, function() {
				document.location = '/shop/';
			});
		}
	}
	LoadMenu();
}

function LoadMenu() {
	$("#navigation").load("/getmenu.php");
}

/*function LoadMenu() {
	var index;
	$("#navigation_list ul:last li.selected").each(function() {
		index = $(this).parent().children("li").index(this) + 1;
	});
	$("#navigation_list").load("/getmenu.php", function() {
		$("#navigation_list ul:last li:nth-child(" + index + ")").addClass("selected");
		$("#navigation_list a").click(function() {
			$("#navigation_list li").removeClass("selected");
			$(this).parent().addClass("selected");
		});
	});
} */


$(document).ready(function() {
	$("body").prepend("<div id='zoom' style='background:#fff;'><img alt=''/></div>");
	$("#zoom").hide().css({position: 'absolute', border: '1px solid #000'});
	$(".thumb")
		.mouseover(function(event) {
			var imgsrc = $(this).attr("src").replace("productImages_thumb", "productImages_thumbBIG");
			var imghl = $(this).attr("longdesc");
			if (imghl.length > 0) {
				$("#zoom").prepend("<p style='padding:2px;border:2px solid red;font-weight:bold;'></p>");
				$("#zoom p").html(imghl);
			}
			$("#zoom img").attr("src", imgsrc).load(function() {
				$("#zoom").show();
			});
		})
		.mouseout(function() {
			$("#zoom").hide();
			$("#zoom img").removeAttr("src");
			$("#zoom p").remove();
		})
		.mousemove(function(event) {
			$("#zoom").css({left: event.clientX + 11, top: $(window).scrollTop() + event.clientY + 11});
		})
		.click(function() {
			$("#zoom").hide();
		});
});


