$(document).ready(function(){

	//rebuild store listing
//	$(".store_module .listing div.article").addClass('article_container').addClass('clear');
	$(".store_module .listing .spec_group_menu select").change(function(){
		this.form.submit();
	});
	$(".shop_categories_module a,.shop_specifications_module a").removeClass('clear');

	//store aticle click
	$(".store_module .listing div.article").hover(
		function(){$(this).addClass('hover');},
		function(){$(this).removeClass('hover');}		
	).click(function(e){
		var $target = $(e.target);
		if(!$target.parents('.ui').length){
			self.location.href = $(this).find(".thumb a").attr('href');
		}
	});

	//order button
	$(".store_module div.ui .submit").mousedown(function(){
		o = $(this).parents('.ui').find('.input');
		if(!o.val())
			o.val(1);
	});

	//change shopping cart
	//$(".shop_cart td.thumb").next().next().attr('colspan',2);
	//$(".shop_cart td.thumb").next().remove();
	//$(".shop_cart td.thumb").remove();

	//put title above image...
	if($(".store_module .listing").length){
		$('.store_module .listing div.category').remove();
		$(".store_module .listing .article").each(function(){
			$(this).find('div.title:eq(0)').prependTo($(this));
		});
		//make all same height
		make_same_height(".store_module .listing div.thumb a");
		make_same_height(".store_module .listing div.title");
		make_same_height(".store_module .listing div.specs");
		//vertical align thumb
		$(".store_module .listing .article .thumb").each(function(){
			$(this).css('padding-top',parseInt(($(this).children(":eq(0)").height() - $(this).height()) / 2) + 'px');
		});
	}
});

var make_same_height = function(selector){
	var max_height = 0;
	$(selector).each(function(){
		if($(this).height() > max_height){
			max_height = $(this).height();
		}
	});
	$(selector).height(max_height);	
}
