if(!Control)
	var Control={};
	
Control.PriceSlider=Class.create();
Control.PriceSlider.prototype=
{
	initialize:function(handles, track,lowPriceAttr,highPriceAttr,range,initialValue, eventManager)
	{
		this.lowPriceAttr=lowPriceAttr;
		this.highPriceAttr=highPriceAttr;
		this.handleLow=handles.handleLow;
		this.handleHigh=handles.handleHigh;
		this.track=track;
		if(typeof range=='undefined')
		{
			range={low:0,high:100};
		}
		$(handles.handleLow).style.display="none";
		$(handles.handleHigh).style.display="none";
		
		this.rangeLow=range.low;
		this.rangeHigh=range.high;
		this.valueLow=initialValue.low;
		this.valueHigh=initialValue.high;
		this.trackLength=this.track.offsetWidth-5; //offset
		this.handleLength=this.handleLow.offsetWidth;
		this.dragging=false;
		this.eventMouseDown=this.startDrag.bindAsEventListener(this);
		this.eventMouseUp=this.endDrag.bindAsEventListener(this);
		this.eventMouseMove=this.update.bindAsEventListener(this);
		this.setValue(initialValue.low,this.handleLow);
		Element.makePositioned(this.handleLow);
		Event.observe(this.handleLow,"mousedown",this.eventMouseDown);
		this.setValue(initialValue.high,this.handleHigh);
		Element.makePositioned(this.handleHigh);
		Event.observe(this.handleHigh,"mousedown",this.eventMouseDown);
		Event.observe(document,"mouseup",this.eventMouseUp);
		Event.observe(document,"mousemove",this.eventMouseMove);
		$(handles.handleLow).style.display="block";
		$(handles.handleHigh).style.display="block";
		
		this.initialized=true;
		this.priceSliderTouchedLow=false;
		this.priceSliderTouchedHigh=false;
		this.disabled=false;
	},
	getNearestValue:function(value)
	{
		if(value>this.rangeHigh)
			return this.rangeHigh;
		if(value<this.rangeLow)
			return this.rangeLow;
		return value;
	},
	setValue:function(sliderValue,handle)
	{
		sliderValue=this.getNearestValue(sliderValue);
		handle.style.left=this.translateToPx(sliderValue);
		if(this.active)
		{
			if(this.activeHandle==this.handleLow)
			{
				this.valueLow=sliderValue;
				this.chosenLow=this.valueLow;
				this.priceSliderTouchedLow=true;
			}
			else 
				if(this.activeHandle==this.handleHigh)
				{
					this.valueHigh=sliderValue;
					this.chosenHigh=this.valueHigh;
					this.priceSliderTouchedHigh=true;
				}
			if(this.valueLow>this.valueHigh)
			{
				var tmpValue=this.valueLow;
				this.valueLow=this.valueHigh;
				this.valueHigh=tmpValue;
				var tmpHandle=this.handleLow;
				this.handleLow=this.handleHigh;
				this.handleHigh=tmpHandle;
				var tmpChosen=this.chosenLow;
				this.chosenLow=this.chosenHigh;
				this.chosenHigh=tmpChosen;
			}
		}
	},
	translateToPx:function(value)
	{
		return Math.round(((this.trackLength-this.handleLength)/(this.rangeHigh-this.rangeLow))*(value-this.rangeLow))+"px";
	},
	translateToValue:function(offset)
	{
		return((offset/(this.trackLength-this.handleLength)*(this.rangeHigh-this.rangeLow))+this.rangeLow);
	},
	startDrag:function(event)
	{
		if(!this.disabled)
		{
			if(Event.isLeftClick(event))
			{
				this.active=true;
				var handle=Event.element(event);
				this.activeHandle=handle;
				Event.stop(event);
				var pointer=[Event.pointerX(event),Event.pointerY(event)];
				var offsets=Position.cumulativeOffset(this.activeHandle);
				this.offsetX=(pointer[0]-offsets[0]);
				this.offsetY=(pointer[1]-offsets[1]);
			}
		}
	},
	update:function(event)
	{
		if(this.active)
		{
			if(!this.dragging)
				this.dragging=true;
			this.draw(event);
			if(navigator.appVersion.indexOf('AppleWebKit')>0)
				window.scrollBy(0,0);
			Event.stop(event);
		}
	},
	draw:function(event)
	{
		var pointer=[Event.pointerX(event),Event.pointerY(event)];
		var offsets=Position.cumulativeOffset(this.track);
		pointer[0]-=this.offsetX+offsets[0];
		pointer[1]-=this.offsetY+offsets[1];
		this.setValue(this.translateToValue(pointer[0]),this.activeHandle);
		if(this.initialized)
		{
			$('txtLowPrice').value=Math.round(this.valueLow);
		}
		$('txtHighPrice').value=Math.round(this.valueHigh);
	},
	endDrag:function(event)
	{
		if(this.active&&this.dragging)
		{
			this.active=false;
			this.dragging=false;
			this.onChange();
			Event.stop(event);
		}
		this.active=false;
		this.dragging=false;
	},
	onChange:function()
	{
		this.disabled=true;
		eventMan.publish(null,"priceChoice",null);
	},
	onEvent:function(oSrcWidget,sEvent,oData)
	{
		switch(sEvent)
		{
			case"priceChoice":
				eventMan.publish(this,"updateSearch",null);
				this.disabled=false;

				break;
		}
	},
	handleResults:function(oData)
	{
		var inLow=parseFloat(oData.lowPrice);
		var inHi=parseFloat(oData.highPrice);
		if(inLow>inHi)
		{
			var temp=inLow;
			inLow=inHi;
			inHi=temp;
		}
		this.rangeLow=inLow;
		this.rangeHigh=inHi;
		if(inLow!=inHi)
		{
			if(oData[this.lowPriceAttr])
			{
				this.valueLow=Math.max(parseInt(oData[this.lowPriceAttr]),inLow);
				this.priceSliderTouchedLow=true;
				this.chosenLow=parseInt(oData[this.lowPriceAttr]);
			}
			else
			{
				this.valueLow=this.rangeLow;
			}
			this.setValue(this.valueLow,this.handleLow);
			if(oData[this.highPriceAttr])
			{
				this.valueHigh=Math.min(parseInt(oData[this.highPriceAttr]),inHi);
				this.priceSliderTouchedHigh=true;
				this.chosenHigh=parseInt(oData[this.highPriceAttr]);
			}
			else
			{
				this.valueHigh=this.rangeHigh;
			}
			this.setValue(this.valueHigh,this.handleHigh);
			this.disabled=false;
		}
		else
		{
			this.valueLow=this.rangeLow;
			this.valueHigh=this.rangeHigh;
			this.disabled=true;
		}
		$('txtLowPrice').value=Math.round(this.valueLow);
		$('txtHighPrice').value=Math.round(this.valueHigh);
	},
	reset:function()
	{
		this.priceSliderTouchedLow=false;
		this.priceSliderTouchedHigh=false;
	},
	picksCleared:function()
	{
		if(this.priceSliderTouchedLow||this.priceSliderTouchedHigh)
		{
			return false;
		}
		else
		{
			return true;
		}
		
	}
}

if(!Control)var Control={};Control.GlobalPickerMonitor=Class.create();Control.GlobalPickerMonitor.prototype={initialize:function(){this.widgets=[];},subscribe:function(oWidget)
{this.widgets.push(oWidget);},unsubscribe:function(aWidget){for(var i=0;i<this.widgets.length;i++){if(this.widgets[i]===aWidget){this.widgets.splice(i,1);}}},toggleClearAll:function(){var i;var allClear=true;for(i=0;i<this.widgets.length;i++){var widget=this.widgets[i];if(!widget.picksCleared()){allClear=false;break;}}
if(typeof keywords!='undefined'&&keywords.keywords!=""){allClear=false;}if(allClear){Element.hide('clearAll');}else{Element.show('clearAll');}},onEvent:function(oSrcWidget,sEvent,oData){switch(sEvent){case"updateSearch":this.toggleClearAll();break;case"newSearchResults":this.toggleClearAll();break;}}}


function N2EventManager()
{
	this.aEvents={};
	this.subscribe=
	function(oWidget,aEvents)
	{
		var i;
		for(i=0;i<aEvents.length;i++)
		{
			var sEvent=aEvents[i];
			var aWidgets=this.aEvents[sEvent];
			if(!aWidgets)
			{
				aWidgets=this.aEvents[sEvent]=[];
			}
			aWidgets.push(oWidget);
		}
	};
	this.unsubscribe=function(oWidget)
	{
		for(var i in this.aEvents)
		{
			var aWidgets=this.aEvents[i];
			for(a=0;a<aWidgets.length;a++)
			{
				if(aWidgets[a]===oWidget)
				{
					aWidgets.splice(a,1);
				}
			}
		}
	};
	this.publish=function(oSrcWidget,sEvent,oData)
	{
		var aWidgets=this.aEvents[sEvent];
		if(aWidgets)
		{
			var i;
			for(i=0;i<aWidgets.length;i++)
			{
				var oWidget=aWidgets[i];
				oWidget.onEvent(oSrcWidget,sEvent,oData);
			}
		}
		if(sEvent=="newSearchResults"&&typeof globalPickerMonitor!='undefined')
		{
		globalPickerMonitor.toggleClearAll();
		}
	};
}



function addWindowOnload(onloadFunction)
{
	var method=window.onload;
	if(typeof method=="function")
	{
		window.onload=function()
		{
			method();
			onloadFunction();
		}
	}
	else
	{
		window.onload=function()
		{
			onloadFunction();
		}
	}
}

var eventMan=new N2EventManager();
function startUp(val_min, val_max, now_min, now_max)
{

//										handles,                                        track,      lowPriceAttr,    highPriceAttr,range,valori, eventManager
	priceSlide=new Control.PriceSlider({handleLow:$('handle1'),handleHigh:$('handle2')},$('track1'),'chosenPriceLow','chosenPriceHigh',{low:val_min, high:val_max},{low:now_min, high:now_max});
	eventMan.subscribe(priceSlide,["priceChoice"]);
	globalPickerMonitor=new Control.GlobalPickerMonitor();
	globalPickerMonitor.subscribe(priceSlide);
}

