$(document).ready(function() {

  $('.numeric-stepper-plusminus:not(.checkout)').live('mousedown', function(e){
		if(e.target==$(this).find('input')[0]) return;
		var input = $(this).find('input'),
		width = $(this).width();
		height = $(this).height();
		if((e.pageX-$(this).offset().left)>($(this).width()/2)) {
			//clicked in left half
			input.val(parseInt(parseInt(input.val())+1));
			if( ! $(this).parents('.error')) {
			  $(this).css({'background-position':'100% -'+height+'px'});
			} else {
				$(this).css({'background-position':'0 -'+height+'px'});
		 	}
		} else {
			//…lower half
			input.val(Math.max(parseInt(input.val())-1,0));
			if( ! $(this).parents('.error')) {
				$(this).css({'background-position':'100% -'+(height*2)+'px'});
			} else {
				$(this).css({'background-position':'0 -'+(height*2)+'px'});
			}
		}
		return false;
	}).live('mouseup', function(event){
		if( ! $(this).parents('.error')) {
			$(this).css({'background-position':'100% 0'});
		} else {
			$(this).css({'background-position':'0 0'});
		}
		if($(this).hasClass('submit-on-blur') && event.target===this) {
			update_basket_from_numeric_stepper(this);
			}
		}).find('input').live('keypress',function(event) {
			return false;

	});
	$('.numeric-stepper-plusminus:not(.checkout).submit-on-blur input').live('blur', function(){
		update_basket_from_numeric_stepper(this);
	});

	$('.vendorheadline .info').each(function() {
		var $this = $(this);
		$this.ToolTipAlt({
			"tooltip" : $this.closest('h2').next('.vendorinfo'),
			"speed" : 500,
			"align" : "center"
		});
	});

	function update_basket_from_numeric_stepper(elem) {
    $element = $(elem);
    $element.attr('readonly', 'readonly');
    $('#page').fadeTo('fast', '0.5');
    $element.closest('form').submit();
  }
});
