function unifyProductTableHeights()
{
	// size the product grid cells per row
	$(".product_grid > tbody > tr").each(function(x){
		if(!$(this).data("calculated"))
		{
			var ic = ".product_image"; // image cells
			var c = $(this).find(ic);
			var mH = 0;
			var p = 10;
			
			if(c.length > 0)
			{
				var h = new Array();
				for(var i=0; i < c.length; i++) { h[i] = $(c[i]).height(); }
				mH = Math.max.apply(null, h);
			}
			
			if(mH > 0)
			{
				var csstxt = "height: " + (mH+p) + "px; padding: 0px !important;";
				c.css("cssText", csstxt);
			}
			
			$(this).data("calculated", true);
		}
	});	
}

$(document).ready(function() {
	$("li.has_submenu").hover(
		function(){
			if(!$(this).data("timer"))
			{
				var z=$(this);
				var timerId=setTimeout(function(){
					z.data("timer", null).find(".submenu").fadeIn("fast");
				}, 333);
				$(this).data("timer", timerId);
			}
		},
		function(){
			var t;
			t=$(this).data("timer");
			if(t) clearTimeout(t);
			$(this).data("timer", null).find(".submenu").hide();
			
		}
	);
	
	// insert expand-buttons to toplevel categories
	// and also add proper class if it's opened (change to minus sign)
	$(".catlv1.catkids").each(function(){
		$(this).prepend(($(this).hasClass("item-active"))? "<span class=\"expand_icon opened\"></span>":"<span class=\"expand_icon\"></span>");
	});
	
	$(".expand_icon").click(
		function()
		{
			$(this).parent().children("ul").slideToggle("medium");
			$(this).parent().removeClass("item-active");
			$(this).toggleClass("opened");
		}
	);
	
	// more clickable
	$("table.product_grid td.product_image").click(
		function()
		{
			var url = $(this).find("a").attr("href");
			if(url) window.location = url;
		}
	);
	
	$("table.product_grid td.product_image").css("cursor","pointer");
	
	$(window).load(unifyProductTableHeights);
});
