(function($){
var slider_increment = function(){
	$this = $(this);
	var val = $this.slider('option','value');
	var inc = $this.slider('option','step');
	var max = $this.slider('option','max');
	$this.slider('option','value', (Number(val)+Number(inc))>max?max :(Number(val)+Number(inc)));
	$this.click();
	return this;
	}
var slider_decrement = function(){
	$this = $(this);
	var val = $this.slider('option','value');
	var inc = $this.slider('option','step');
	var min = $this.slider('option','min');
	$this.slider('option','value', (val-inc)<min?min :(val-inc));
	$this.click();
	return this;
	}

var arrow_mouse_down = function(){
	$this_arrow = $(this);
	
	st = setTimeout(function(){
		var int1 = setInterval ( function(){$this_arrow.click();} , 20 );
		$(document).unbind('mouseup').bind('mouseup',function(){clearInterval(int1); $(document).unbind('mouseup')});
		},300);
		
	$(document).bind('mouseup',function(){ clearTimeout(st); $(document).unbind('mouseup')});
	
	} 

var slider_pm = function(){
	var $this = $(this);
	if(!$(this).is('.slider_field'))
	{
		$(this).addClass('slider_field');
		var left_arrow = $('<div></div>').addClass('slider_leftArrow');
		var right_arrow = $('<div></div>').addClass('slider_rightArrow');
		var slider_body = $('<div></div>').attr('id',$this.attr('id')+'_body');
		var ret = $().slider.apply(slider_body,arguments);
		if(arguments[0]['for_item']!=null && arguments[0]['onchange']!=null)
		{
			var slide_func = arguments[0]['onchange'];
		}
		else slide_func = function(){};
		
		left_arrow.click(function(){slider_decrement.apply(slider_body); slide_func.apply(slider_body)}).mousedown(arrow_mouse_down);
		right_arrow.click(function(){slider_increment.apply(slider_body); slide_func.apply(slider_body)}).mousedown(arrow_mouse_down);
		//$(left_arrow).bind('click',slide_func).bind('mousedown',slide_func);
		$this.append(left_arrow).append(right_arrow).append(slider_body);
	}
	else
		var slider_body = $this.find('#'+$this.attr('id')+'_body');
		
	return slider_body.slider.apply(slider_body,arguments);
	
	}
	
	$.fn.slider_pm = slider_pm;
})(jQuery)
