﻿function showGroup() {
	$("div.products").hide();
	var selection = $("#product option:selected").val();
	$("#"+selection).show();
}

$(document).ready(function() {
	showGroup();
	$("#product").change(function(){
		showGroup();
		$("#product").parent().submit();
	});

	$("#all #nav_categories li a").click(function(){
		var link = $(this).attr("href");
		$("#all").hide();
		$(link).show();
		return false;
	});

	$("div.products h2").css("cursor","pointer");
	$("div.products h2").click(function(){
		$(this).parent().hide();
		$("#all").show();

	});

	var attrib = "";
	$("div.products a").hover(function(){
		$("body").append("<div id=\"tooltip\"><p><strong>Артикул:<\/strong><br \/>"+$(this).attr('title')+"<\/p><\/div>");
		$("#tooltip").css({opacity:0});
		attrib = $(this).attr("title");
		if($(this).attr("title") != ""){
			$(this).removeAttr("title");
			$("#tooltip").css({opacity:0.8}).show();
			$(this).mousemove(function(kmouse){
				$("#tooltip").css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			})
		}
	}, function() {
		$("#tooltip").hide().remove();
		$(this).attr("title", attrib);
	});

	$("#backToCatalog a").click(function() {
		$("#cats div form").submit();
		return false;
	});
	
	$(".sort").change(function() {
		var search1 = ($("#sort0 option:selected").val()) ? $("#sort0 option:selected").val() : "";
		var search2 = ($("#sort1 option:selected").val()) ? $("#sort1 option:selected").val() : "";
		var search3 = ($("#sort2 option:selected").val()) ? $("#sort2 option:selected").val() : "";
		$("table tr").hide();
		$("table tr.params").show();
		$("table tr:contains('"+search1+"'):contains('"+search2+"'):contains('"+search3+"')").show();
		var ch = 1;
		$("table tr:visible").each(function() {
			$(this).removeClass();
			if (ch == 2) {
				$(this).addClass("odd");
				ch = 1;
			} else {
				$(this).addClass("even");
				ch = 2;
			}
		})
		$("table tr:first").removeClass().addClass("params");
	});
});
