function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


$(document).ready(function(){

	$("#rubricator>ul>li>a").each(function( i ){
		if (getCookie( "Cat" + (i+1) ) == "on")
			$(this).addClass("active").next().show();
	});

	$("#rubricator ul ul").hide().filter(
		function () {
			return $(this).prev().hasClass("active");
		})
		.show();

	$("#rubricator>ul>li>a").click(function(){
		if ($(this).is('.active')) {
			$(this).removeClass("active");
			document.cookie = "Cat" + ($("#rubricator>ul>li>a").index(this)+1) + "=off; path=/; expires=Mon, 01-Jan-1970 00:00:00 GMT";
		}
		else {
			$(this).addClass("active");
			document.cookie = "Cat" + ($("#rubricator>ul>li>a").index(this)+1) + "=on; path=/; expires=Wed, 01-Jan-2020 00:00:00 GMT";
		}
	});

	$("#rubricator a.last").click(function(){
		$(this).next().toggle();
		return false;
	});

	$("#dmenu td.num3>a").click(function(){
		return false;
	});

	$("#dmenu td:not(.middle)").hover(function(){
		$(this).addClass('sel');
	},function(){
		$(this).removeClass('sel');
	});

	$("#categories .item .title, #categories .item .img").click(function(){
		$("#categories .item").removeClass('active');
		$(this).parent().addClass('active');
	});


	function compare(type) {
		$("#compare_small, #compare_middle, #compare_big").removeClass('active')
			.filter(function () {
                  return $(this).html() == type;
                })
			.addClass('active');
		$("#comparetable tbody tr").hide().filter("[rel='" + type + "']").show();
	}

	$("#compare_small, #compare_middle, #compare_big").click(function(){
		compare($(this).html());
	});

	$("#compare_big").click();

	$("#compare").click(function(){
		$("#comparetable tbody tr:visible input:not(:checked)").parent().parent().hide();
	});


});
