jQuery(document).ready(function () {
	var h = true;
	var i = true;
	var j = "";
	function setReload_nav(a) {
		window.reload_nav = a
	}
	function getReload_nav() {
		return window.reload_nav
	}
	function setReload_compare(a) {
		window.reload_compare = a
	}
	function getReload_compare() {
		return window.reload_compare
	}
	setReload_nav(true);
	setReload_compare(true);
	var k = location.hash.slice(1);
	if (k != "") {
		handleHashChange()
	}
	jQuery(window).hashchange(function (e) {
		handleHashChange()
	});
	jQuery(".layered-navigation-select").live('change', function () {
		setReload_nav(true);
		setReload_compare(false);
		window.location.hash = hashUrl(jQuery(this).val());
		return false
	});
	function handleHashChange() {
		var a = location.hash.slice(1);
		path = window.location.href;
		path = path.split("#")[0];
		path = path.split("?")[0];
		path = ajaxListURL(path + "?" + a);
		nv = getReload_nav();
		cm = getReload_compare();
		loadAjaxProductsList(path, nv, cm);
		setReload_nav(false);
		setReload_compare(false);
    return false;
	}
	function loadAjaxProductsList(e, f, g) {
		e = ajaxListURL(e);
		jQuery(".col-main").append("<div class=\"products-list-loader\"><div>Loading</div></div>");
		if (f) {
			//jQuery(".block-layered-nav-list").append("<div class=\"products-list-loader\"><div>Loading</div></div>")
		}
		jQuery.get(e, {},
		function (a, b, c) {
			if (b == "error") {
				jQuery(".col-main").html("<p>There was an error making the AJAX request</p>")
			} else {
				var d = jQuery("<div />").html(a);
				jQuery(".col-main").html(d.find('.col-main').html());
				if (f) {
					jQuery(".block-layered-nav-list").html(d.find('.block-layered-nav-list').html())
				}
				if (g) {
					jQuery(".block-compare").html(d.find('.block-compare').html())
				}
				if (typeof(window.ajaxproload) == "function") {
					ajaxproload()
				}
			}
		})
	}
	function ajaxListURL(a) {
		if (a.indexOf("ajax=1") < 0) {
			if (a.indexOf("?") < 0) {
				a = a + "?ajax=1"
			} else {
				a = a + "&ajax=1"
			}
		}
		return a
	}
	function hashUrl(a) {
		a.match(/\?(.+)$/);
		var b = RegExp.$1;
		if (b.indexOf("ajax=1") >= 0) {
			b = b.replace("ajax=1&", "");
			b = b.replace("&ajax=1", "");
			b = b.replace("ajax=1", "")
		}
		return b
	}
});
