FilterForm = Class.create();

Object.extend(FilterForm.prototype, {
	initialize: function(category)
	{
		if(typeof category != "undefined")
		{
			this.category = category;
		}
		else
		{
			this.category = "";
		}
		
		$('brand').observe('change', this.on_select_change.bindAsEventListener(this));
		$('yearmin').observe('change', this.submit_form);
		$('yearmax').observe('change', this.submit_form);
        $('transmissie').observe('change', this.submit_form);

		$('subcat').observe('change', this.submit_form);
		$('transmission').observe('change', this.submit_form);
		$$('input.euro_radio').each(function(elem)
		{
			elem.observe('click', this.submit_form);
		}.bind(this));
	},
	
	submit_form: function(event)
	{
		this.form.submit();
	},
	
	on_select_change: function(event)
	{
		select = $('brand');
		value = select.options[select.selectedIndex].value;
		
		window.location = window.base_url + 'trucks/' + this.category + '/' + value;
	}
});

AdminFilterForm = Class.create();

Object.extend(Object.extend(AdminFilterForm.prototype, FilterForm.prototype), {
	initialize: function()
	{		
		$('brand').observe('change', this.submit_form);
		$('yearmin').observe('change', this.submit_form);
		$('yearmax').observe('change', this.submit_form);
		
		$('subcat').observe('change', this.submit_form);
		$('transmission').observe('change', this.submit_form);
		$$('input.euro_radio').each(function(elem)
		{
			elem.observe('click', this.submit_form);
		}.bind(this));
	},
	
	on_select_change: function(event)
	{
		this.submit_form();
	}
});

CategorySlider = {
	setup: function(current_value)
	{
		new Control.Slider('priority-handle', 'priority-slider', {
			range: $R(0, 100),
			values: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
			sliderValue: current_value,
			onSlide: function(e)
			{
				$('priority').value = e;
			}
		});
	}
};
