//jquery in nonconflict mode and $-function fix, inside this block, prototype methods won't work
(function($){ jQuery.noConflict(); $(function(){
	
	$.fn.maxHeight = function(){
		var max = 0;
		$(this).each(function(){
			var height = $(this).height();
			max = height>max? height : max;
		});
		return max;
	}
	$.fn.syncHeightPerLine = function(options){
		var conf = $.extend({
			syncDescendant: false	/* change this to a child-selector for the .find() method */
		}, options);
	  var syncList = $(this);
	  var toSync = [];
	  syncList.each(function(i, val) {
	  	$(conf.syncDescendant? $(this).find(conf.syncDescendant) : this ).each(function(){ toSync.push(this); });	
	      if (($(this).next().length && $(this).position().top != $(this).next().position().top) ||
	                         !$(this).next().length
	                         ) {
	          $(toSync).height($(toSync).maxHeight());
	          toSync = [];
	      }
	  });
	}
	
	$(".catalog-listing li").syncHeightPerLine({syncDescendant:".attributes"});
	$(".grid-row li .product-desc .form-button, .add-to-holder .form-button")
		.each(function(){
			var text = $(this).hide().text();
			var button = this;
			$(this).after(
				$('<a href="#" class="form-button order-button"><span>'+text+'</span></a>').click(function(e){
					e.stopPropagation();
					e.preventDefault();
					$(button).click();
				})
			);
		});	
});})(jQuery);
