function initInterface() {


	// zoek op kaart
	var tabAccuracy = new Array(3,6,8,10,12,13,16,16,17);
	$('address').addEvent('keydown', function(event) {

		if (event.key == 'enter') {

			event.stop();
			var address = $('address').value.trim();

			if (address != '') {
				geocoder = new GClientGeocoder();
				if (geocoder) {
					geocoder.getLocations(
						address, function(response) {
							if(response.Status.code!=200){
								showMsg(address + ' LANG_SEARCH_JS_LOCATION_NOTFOUND', true);
							} else {
								place = response.Placemark[0];
								accuracy = place.AddressDetails.Accuracy;
								map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), tabAccuracy[accuracy]);
							}
					});
				}
			}
		}
	});

	// kaart of lijst
	$('a_tab_map').addEvent('click', function(event) {
		event.stop();
		q.tab = 'map';
                selectTab();
		update();
        });     

	$('a_tab_list').addEvent('click', function(event) {
		event.stop();
		q.tab = 'list';
                selectTab();
		update();
        });     

	// koop of huur
	$('a_radio_sale').addEvent('click', function(event) {
		event.stop();
		q.salerent = 1;
                selectSaleRent(q.salerent);
		update();
        });

	$('a_radio_rent').addEvent('click', function(event) {
		event.stop();
		q.salerent = 2;
                selectSaleRent(q.salerent);
		update();
        });     

	// list: meer 
	$('a_list_more').addEvent('click', function(event) {
		event.stop();
                $('a_list_more').blur();
		q.list.append = true;
		update();
        });     

	// list: sorteren
	$('a_list_sort_price').addEvent('click', function(event) {
		event.stop();
		q.list.orderby = 'price';
		selectSort('price');
		update();
        });

	// type_short
	var div_type = $('div_type');
	$$(div_type.getElementsByTagName('input')).each(function(input) {
		input.addEvent('click', function(event) {
			doTypes();
		});
        });


	/*
	$('a_type').addEvent('click', function(event) {
		event.stop();
		popTypes(event);
        });     

	$('a_type_toggle').addEvent('click', function(event) {
		event.stop();
		toggleTypes(event);
        });

	$('a_type_close').addEvent('click', function(event) {
		event.stop();
		$('div_type').setStyle('left', -9000);
        });     

	$('a_type_ok').addEvent('click', function(event) {
		event.stop();
		doTypes();
        });     
	*/

	$('a_group').addEvent('click', function(event) {
		event.stop();
		popGroups(event);
        });     

	$('a_group_close').addEvent('click', function(event) {
		event.stop();
		$('div_group').setStyle('left', -9000);
        });     

	$('a_group_ok').addEvent('click', function(event) {
		event.stop();
		doGroups();
        });

	$('a_list_sort_city').addEvent('click', function(event) {
		event.stop();
		q.list.orderby = 'city';
		selectSort('city');
		update();
        });     

	// prijs slider (koop)
	var s1 = new Object();
	s1.range = new SliderRange('price_sale');
	s1.el = new DoubleSlider($('price_sale_slider_container'), $('price_sale_slider_knob_a'), {
		start: 0,
		end: 25,
		offset: 0,
		snap: false,
		onChange: function(pos) {
			$('price_sale_slider_value').set('html', s1.range.get(pos).display);
		},
		onComplete: function(pos) {
			if ($chk(q) && inited) {
				var value = s1.range.get(pos);
				q.price_sale = [value.min, value.max];
				update();
			}
		}
	}, $('price_sale_slider_knob_b')).setMin(0).setMax(25);
	sliders.set('price_sale', s1);
	//console.log(s1);

	// prijs slider (huur)
	var s2 = new Object();
	s2.range = new SliderRange('price_rent');
	s2.el = new DoubleSlider($('price_rent_slider_container'), $('price_rent_slider_knob_a'), {
		start: 0,
		end: 25,
		offset: 0,
		snap: false,
		onChange: function(pos) {
			$('price_rent_slider_value').set('html', s2.range.get(pos).display);
		},
		onComplete: function(pos) {
			if ($chk(q) && inited) {
				var value = s2.range.get(pos);
				q.price_rent = [value.min, value.max];
				update();
			}
		}
	}, $('price_rent_slider_knob_b')).setMin(0).setMax(25);
	sliders.set('price_rent', s2);
	//console.log(s2);

	// oppervlakte slider
	var s3 = new Object();
	s3.range = new SliderRange('floorspace');
	s3.el = new DoubleSlider($('floorspace_slider_container'), $('floorspace_slider_knob_a'), {
		start: 0,
		end: 8,
		offset: 0,
		snap: false,
		onChange: function(pos){
			$('floorspace_slider_value').set('html', s3.range.get(pos).display);
		},
		onComplete: function(pos) {
			if ($chk(q) && inited) {
				var value = s3.range.get(pos);
				q.floorspace = [value.min, value.max];
				update();
			}
		}

	}, $('floorspace_slider_knob_b')).setMin(0).setMax(8);
	sliders.set('floorspace', s3);

	// kamers slider
	var s4 = new Object();
	s4.range = new SliderRange('rooms');
	s4.el = new DoubleSlider($('rooms_slider_container'), $('rooms_slider_knob_a'), {
		start: 0,
		end: 10,
		offset: 0,
		snap: false,
		onChange: function(pos){
			$('rooms_slider_value').set('html', s4.range.get(pos).display);
		},
		onComplete: function(pos) {
			if ($chk(q) && inited) {
				var value = s4.range.get(pos);
				q.rooms = [value.min, value.max];
				update();
			}
		}

	}, $('rooms_slider_knob_b')).setMin(0).setMax(10);
	sliders.set('rooms', s4);
}

function showMsg(msg, is_err) {

	var html = '';
	if (is_err) html = '<img src="/img/icons/exclamation.gif" width="16" height="16">';
	else html = '<img src="/img/icons/accept.gif" width="16" height="16">';
	html += msg;

	$('msg').set('html', html);
	$('msg').setStyle('display', 'block');

	function remove(){
		$('msg').setStyle('display', 'none');
	};
	remove.delay(3000);
}

function selectSaleRent(a) {

        if (!$chk(a)) a = '1';

        if (a == 1) {
                $('a_radio_rent').set('class', 'radio_deselected');
                $('a_radio_sale').set('class', 'radio_selected');
                $('a_radio_sale').blur();
		$('div_price_rent').setStyle('display', 'none');
		$('div_price_sale').setStyle('display', 'block');
        } else {
                $('a_radio_sale').set('class', 'radio_deselected');
                $('a_radio_rent').set('class', 'radio_selected');
                $('a_radio_rent').blur();
		$('div_price_sale').setStyle('display', 'none');
		$('div_price_rent').setStyle('display', 'block');
        }
}

function selectSort(a) {

        if (!$chk(a)) a = 'sale';

        if (a == 'city') {
                $('a_list_sort_price').set('class', 'radio_deselected');
                $('a_list_sort_city').set('class', 'radio_selected');
                $('a_list_sort_city').blur();
        } else {
                $('a_list_sort_city').set('class', 'radio_deselected');
                $('a_list_sort_price').set('class', 'radio_selected');
                $('a_list_sort_price').blur();
        }
}

function selectTab() {

        if (q.tab == 'map') {
                $('a_tab_list').getParent().removeClass('selected');
                $('a_tab_map').getParent().set('class', 'selected');
                $('a_tab_map').blur();
		$('list').setStyle('display', 'none');
		$('div_objects').set('html', '');
		$('a_list_more').setStyle('display', 'none');
		$('div_list_sort').setStyle('display', 'none');
		$('map').setStyle('visibility', 'visible');
		$('div_address').setStyle('display', 'block');
	}

        if (q.tab == 'list') {
                $('a_tab_map').getParent().removeClass('selected');
                $('a_tab_list').getParent().set('class', 'selected');
                $('a_tab_list').blur();
		if (mgr) mgr.clearMarkers();
		$('map').setStyle('visibility', 'hidden');
		$('div_address').setStyle('display', 'none');
		$('list').setStyle('display', 'block');
        }
}

var SliderRange = new Class({

	type: '',
	pos: [0, 0],

	initialize: function(type) {
		this.type = type;
	},

	get: function(pos) {
		if (this.type == 'price_sale') return this.getPriceSale(pos, false);
		if (this.type == 'price_rent') return this.getPriceRent(pos, false);
		if (this.type == 'floorspace') return this.getFloorspace(pos, false);
		if (this.type == 'rooms') return this.getRooms(pos, false);

	},

	lookup: function(pos) {
		if (this.type == 'price_sale') return this.getPriceSale(pos, true);
		if (this.type == 'price_rent') return this.getPriceRent(pos, true);
		if (this.type == 'floorspace') return this.getFloorspace(pos, true);
		if (this.type == 'rooms') return this.getRooms(pos, true);

	},	

	getPriceSale: function(pos, lookup) {

		var values = [ 
			[0, '0'], 
			[50000, '50.000'], 
			[100000, '100.000'], 
			[150000, '150.000'], 
			[200000, '200.000'],
			[250000, '250.000'], 
			[300000, '300.000'], 
			[350000, '350.000'], 
			[400000, '400.000'], 
			[450000, '450.000'], 
			[500000, '500.000'], 
			[550000, '550.000'], 
			[600000, '600.000'], 
			[650000, '650.000'], 
			[700000, '700.000'], 
			[750000, '750.000'], 
			[800000, '800.000'], 
			[850000, '850.000'], 
			[900000, '900.000'], 
			[950000, '950.000'], 
			[1000000, '1.000.000'], 
			[1250000, '1.250.000'],
			[1500000, '1.500.000'],
			[1750000, '1.750.000'],
			[2000000, '2.000.000'],
			[-1, 'Geen maximum'],
		];

		if (lookup) {
			// welke positie hoort bij dit bedrag?
			var found = 0;
			values.each(function(v, i) {
				if (v) {
					if (v[0] == pos) {
						found = i;
					}
				}
			});
			return found;
		} else {

			var value = new Object();
			try {
				value.min = values[pos.minpos][0];
				value.max = values[pos.maxpos][0];
				if (value.min == 0) {
					if (value.max == -1) value.display = 'Alles';
					else  value.display = 'Tot  &euro; ' + values[pos.maxpos][1];
				} else if (value.max == -1) {
					value.display = 'Vanaf  &euro; ' + values[pos.minpos][1];
				} else {
					value.display = '&euro; ' + values[pos.minpos][1] + ' - &euro; ' + values[pos.maxpos][1];
				}
			} catch(e) {
				value.min = 0;
				value.max = -1;
				value.display = 'Alles';
			}

			return value;
		}
	},

	getPriceRent: function(pos, lookup) {

		var values = [ 
			[0, '0'], 
			[100, '100'], 
			[200, '200'], 
			[300, '300'], 
			[400, '400'],
			[500, '500'], 
			[600, '600'], 
			[700, '700'], 
			[800, '800'], 
			[900, '900'], 
			[1000, '1000'], 
			[1200, '1200'], 
			[1400, '1400'], 
			[1600, '1600'], 
			[1800, '1800'], 
			[2000, '2000'], 
			[2500, '2500'], 
			[3000, '3000'], 
			[3500, '3500'], 
			[4000, '4000'], 
			[4500, '4500'], 
			[5000, '5000'], 
			[5500, '5500'], 
			[6000, '6000'], 
			[10000, '10000'],
			[-1, 'Geen maximum'],
		];

		if (lookup) {
			// welke positie hoort bij dit bedrag?
			var found = 0;
			values.each(function(v, i) {
				if (v) {
					if (v[0] == pos) {
						found = i;
					}
				}
			});
			return found;
		} else {
			var value = new Object();
			try {
				value.min = values[pos.minpos][0];
				value.max = values[pos.maxpos][0];
				if (value.min == 0) {
					if (value.max == -1) value.display = 'Alles';
					else  value.display = 'Tot  &euro; ' + values[pos.maxpos][1];
				} else if (value.max == -1) {
					value.display = 'Vanaf  &euro; ' + values[pos.minpos][1];
				} else {
					value.display = '&euro; ' + values[pos.minpos][1] + ' - &euro; ' + values[pos.maxpos][1];
				}
			} catch(e) {
				value.min = 0;
				value.max = -1;
				value.display = 'Alles';
			}

			return value;
		}

	},

	getFloorspace: function(pos, lookup) {

		var values = [ 
			[0, '0'], 
			[50, '50'], 
			[75, '75'], 
			[100, '100'], 
			[125, '125'],
			[150, '150'], 
			[200, '200'], 
			[250, '250'], 
			[-1, 'Geen maximum'], 
		];

		if (lookup) {
			// welke positie hoort bij dit bedrag?
			var found = 0;
			values.each(function(v, i) {
				if (v) {
					if (v[0] == pos) {
						found = i;
					}
				}
			});
			return found;
		} else {

			var value = new Object();
			try {
				value.min = values[pos.minpos][0];
				value.max = values[pos.maxpos][0];
				if (value.min == 0) {
					if (value.max == -1) value.display = 'Alles';
					else  value.display = 'Tot ' + values[pos.maxpos][1] + ' m2';
				} else if (value.max == -1) {
					value.display = 'Vanaf ' + values[pos.minpos][1] + ' m2';
				} else {
					value.display = values[pos.minpos][1] + ' - ' + values[pos.maxpos][1] + ' m2';
				}
			} catch(e) {
				value.min = 0;
				value.max = -1;
				value.display = 'Alles';
			}

			return value;
		}
	},

	getRooms: function(pos, lookup) {

		var values = [ 
			[1, '1'], 
			[2, '2'], 
			[3, '3'], 
			[4, '4'], 
			[5, '5'],
			[6, '6'], 
			[7, '7'], 
			[8, '8'], 
			[9, '9'], 
			[10, '10'], 
			[-1, 'Geen maximum'], 
		];

		if (lookup) {
			// welke positie hoort bij dit bedrag?
			var found = 0;
			values.each(function(v, i) {
				if (v) {
					if (v[0] == pos) {
						found = i;
					}
				}
			});
			return found;
		} else {

			var value = new Object();
			try {
				value.min = values[pos.minpos][0];
				value.max = values[pos.maxpos][0];
				if (value.min <= 1) {
					if (value.max == -1) value.display = 'Alles';
					else  value.display = 'Tot ' + values[pos.maxpos][1] + ' ' + ((values[pos.maxpos][1] > 1) ? 'kamers' : 'kamer');
				} else if (value.max == -1) {
					value.display = 'Vanaf ' + values[pos.minpos][1] + ' ' + ((values[pos.minpos][1] > 1) ? 'kamers' : 'kamer');
				} else {
					value.display = values[pos.minpos][1] + ' - ' + values[pos.maxpos][1] + ' kamers';
				}
			} catch(e) {
				value.min = 1;
				value.max = -1;
				value.display = 'Alles';
			}

			return value;
		}
	}

});

function showNumObjects(num) {
	var str;
	if (num > 0) str = num + ' ' + ((num > 1) ? 'objecten' : 'object');
	else str = 'Geen objecten';
	$('num').set('html', str);
}

function doTypes(event) {

	// doorloop checkboxes
	var div = $('div_type');
	q.types = [];
	$$(div.getElementsByTagName('input')).each(function(input) {
		if (input.checked) {
			q.types[q.types.length] = input.value;
			//console.log(q.types);
		}
	});

	update();
}

function showPPM(info) {
// prijs/meter2 voor elke soort

	//console.log(info);

	// doorloop checkboxes
	var div = $('div_type');
	$$(div.getElementsByTagName('td')).each(function(td) {
		if (td.id != '') {
			var type = td.id.substring(3, td.id.length);

			if (typeof(info['ppm']) !== 'undefined' && info['ppm'] != null) {
				var ppm = computePPM(info['ppm'][type]);
				td.set('html', ppm);
				$('ppm').setStyle('visibility', 'visible');
			} else {
				td.set('html', '&nbsp;&nbsp;&nbsp;&nbsp;');
				$('ppm').setStyle('visibility', 'hidden');
			}
		}
	});
}

function computePPM(info) {

	var ppm = '';

	if (typeof(info) !== 'undefined' && info != null) {
		ppm = Math.round(info['sum_ppm'] / info['sum']);
	}

	if (ppm == 0) ppm = '';
	else ppm = add_dots(ppm);
		

	return ppm;
}

function add_dots(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function toggleTypes() {

	// toggle checkboxes
	var div = $('div_type');
	q.types = [];
	$$(div.getElementsByTagName('input')).each(function(input) {
		input.checked = !input.checked;
	});
}

function popGroups(event) {

	// bepaal positie
	var winsize = window.getSize();
	//console.log(winsize);
	var divsize = $('div_group').getSize();
	//console.log(divsize);

	var pos = {};
	pos.y = (event.page.y - divsize.y + 20);
	pos.x = (event.page.x - divsize.x);
	
	$('div_group').setStyle('top', pos.y);
	$('div_group').setStyle('left', pos.x);
}

function doGroups(event) {

	$('div_group').setStyle('left', -9000);

	// doorloop checkboxes
	var div = $('div_group');
	q.groups = [];
	$$(div.getElementsByTagName('input')).each(function(input) {
		if (input.checked) {
			q.groups[q.groups.length] = input.value;
		}
	});

	if (q.groups.length == 0) {
		$('a_group').set('html', 'Selecteer');
	} else {
		$('a_group').set('html', 'Wijzig selectie');
	}

	update();
}

/*
Class: DoubleSlider
        Creates a slider with two elements: a knob and a container. Returns the values.
Note:
        The Slider requires an XHTML doctype.
Arguments:
        element - the knob container
        knob - the handle
        options - see Options below
        maxknob - an optional maximum slider handle
Options:
	start - the minimum value for your slider.
	end - the maximum value for your slider.
        mode - either 'horizontal' or 'vertical'. defaults to horizontal.
        offset - relative offset for knob position. default to 0.
        knobheight - positions the max slider knob
	snap - whether the slider will slide in steps 
	numsteps - number of slide steps 
Events:
        onChange - a function to fire when the value changes.
        onComplete - a function to fire when you're done dragging.
        onTick - optionally, you can alter the onTick behavior, for example displaying an effect of the knob moving to the desired position.
                Passes as parameter the new position.
*/
var DoubleSlider = new Class({
	options: {
		onChange: Class.empty,
		onComplete: Class.empty,
		onTick: function(pos){
			this.moveKnob.setStyle(this.p, pos);			
		},
		start: 0,
		end: 100,
		offset: 0,
		knobheight: 16,
		knobwidth: 16,
		mode: 'horizontal',
		clip_w: 0, 
		clip_l: 0,
		isinit: true,
		snap: false,
		range: false,
		numsteps: null
	},
    initialize: function(el, knob, options, maxknob) {
		this.setOptions(options);
		this.element = $(el);
		this.knob = $(knob);
		this.previousChange = this.previousEnd = this.step = -1;
		if(this.options.steps==null){
			this.options.steps = this.options.end - this.options.start;
		}
		if(maxknob!=null) this.maxknob = $(maxknob);
		var mod, offset;
		switch(this.options.mode){
			case 'horizontal':
				this.z = 'x';
				this.p = 'left';
				mod = {'x': 'left', 'y': false};
				offset = 'offsetWidth';
				break;
			case 'vertical':
				this.z = 'y';
				this.p = 'top';
				mod = {'x': false, 'y': 'top'};
				offset = 'offsetHeight';
		}
		this.max = this.element[offset] - this.knob[offset] + (this.options.offset * 2);
		this.half = this.knob[offset]/2;
		this.full = this.element[offset] - this.knob[offset] + (this.options.offset * 2);
		this.min = $chk(this.options.range[0]) ? this.options.range[0] : 0;
		this.getPos = this.element['get' + this.p.capitalize()].bind(this.element);
		this.knob.setStyle('visibility', 'visible').setStyle('position', 'relative').setStyle(this.p, - this.options.offset);

		this.range = this.max - this.min;
		this.steps = this.options.steps || this.full;
		this.stepSize = Math.abs(this.range) / this.steps;
		this.stepWidth = this.stepSize * this.full / Math.abs(this.range) ;
		
		if(maxknob != null) {
			this.maxPreviousChange = -1;
			this.maxPreviousEnd = -1;
			this.maxstep = this.options.end;
			this.maxknob.setStyle('visibility', 'visible').setStyle('position', 'relative').setStyle(this.p, + this.max - this.options.offset).setStyle('bottom', this.options.knobheight);
		}
		var lim = {};
		lim[this.z] = [- this.options.offset, this.max - this.options.offset];

		this.drag = new Drag(this.knob, {
			limit: lim,
			modifiers: mod,
			snap: 0,
			onStart: function(){
				this.draggedKnob();
			}.bind(this),
			onDrag: function(){
				this.draggedKnob();
			}.bind(this),
			onComplete: function(){
				this.draggedKnob();
				this.end();
			}.bind(this)
		});
		if(maxknob != null) {  
			this.maxdrag = new Drag(this.maxknob, {
				limit: lim,
				modifiers: mod,
				snap: 0, 
				onStart: function(){
					this.draggedKnob(1);
				}.bind(this),
				onDrag: function(){
					this.draggedKnob(1);
				}.bind(this),
				onComplete: function(){
					this.draggedKnob(1);
					this.end();
				}.bind(this)
			});		
		}

		if (this.options.snap) {
			//this.drag.options.grid = Math.ceil(this.stepWidth);
			this.drag.options.grid = (this.full)/this.options.numsteps ;
			this.drag.options.limit[this.z][1] = this.full;
			//this.drag.options.grid = this.drag.options.grid - (this.knob[offset]/this.options.numsteps);
			status = "GRID - " + this.drag.options.grid  + "  , full = " + this.full// DEBUG

		}
		if (this.options.initialize) this.options.initialize.call(this);
    },
	setMin: function(stepMin){
		this.step = stepMin.limit(this.options.start, this.options.end);
		this.checkStep();
		this.end();
		this.moveKnob = this.knob;
		this.fireEvent('onTick', this.toPosition(this.step));
		return this;
	},
	setMax: function(stepMax){
		this.maxstep = stepMax.limit(this.options.start, this.options.end);
		this.checkStep(1);
		this.end();
		this.moveKnob = this.maxknob;
		var w= Math.abs(this.toPosition(this.step)- this.toPosition(this.maxstep)) + 3 ;
		var r = parseInt(this.clip_l + w); 

		this.fireEvent('onTick', this.toPosition(this.maxstep));
		// For Init Only 
		if(this.options.isinit){
			var lim = {}; var mi,mx;
			mi = - this.options.offset; 
			mx= parseInt(this.maxknob.getStyle('left')) - this.options.offset-4 ;
			lim[this.z] = [mi, mx];
			this.drag.options.limit = lim;
			this.options.isinit = false;
		}
		return this; 
	},
	clickedElement: function(event){
		var position = event.page[this.z] - this.getPos() - this.half;
		position = position.limit(-this.options.offset, this.max -this.options.offset);

		this.step = this.toStep(position);

		//this.moveKnob = this.knob;
		this.checkStep();
		this.end();
		//this.fireEvent('onTick', position);
	},

	draggedKnob: function(mx){
		var lim = {}; var mi,mx;
		if(mx==null) {
			this.step = this.toStep(this.drag.value.now[this.z]);	 
			this.checkStep();
		}else {
			this.maxstep = this.toStep(this.maxdrag.value.now[this.z]); 
			this.checkStep(1);
		}
	},
	checkStep: function(mx){
		var lim = {}; var mi,mx;
		var limm = {};
		if(mx==null) {if (this.previousChange != this.step){this.previousChange = this.step;}}
		else {if (this.maxPreviousChange != this.maxstep){this.maxPreviousChange = this.maxstep;}}

		if(this.maxknob!=null) {

			mi = - this.options.offset; 
			mx= parseInt(this.maxknob.getStyle('left')) - this.options.offset-this.options.knobwidth;
			lim[this.z] = [mi, mx];
			this.drag.options.limit = lim;

			mi = parseInt(this.knob.getStyle('left'))-this.options.offset+this.options.knobwidth; 
			
			mx= this.max - this.options.offset;
			limm[this.z] = [mi, mx];
			this.maxdrag.options.limit = limm; 

			if(this.step < this.maxstep){
				this.fireEvent('onChange', { minpos: this.step, maxpos: this.maxstep });
			} else{
				this.fireEvent('onChange', { minpos: this.maxstep, maxpos: this.step });
			}	
			this.clip_l = parseInt(this.knob.getStyle('left')) + 10;
			var w = Math.abs(parseInt(this.knob.getStyle('left')) - parseInt(this.maxknob.getStyle('left')));
		} else {  
			this.fireEvent('onChange', this.step);
		}
	},
	end: function(){
		if (this.previousEnd !== this.step || (this.maxknob != null && this.maxPreviousEnd != this.maxstep)) {
			this.previousEnd = this.step;
			if(this.maxknob != null) {
				this.maxPreviousEnd = this.maxstep;
				if(this.step < this.maxstep)
					this.fireEvent('onComplete', { minpos: this.step + '', maxpos: this.maxstep + '' });
				else    
					this.fireEvent('onComplete', { minpos: this.maxstep + '', maxpos: this.step + '' });
			}else{  
				this.fireEvent('onComplete', this.step + '');
			}
		}
	},
	
	toStep: function(position){
		return Math.round((position + this.options.offset) / this.max * this.options.steps) + this.options.start;
	},

	toPosition: function(step){
		return (this.max * step / this.options.steps) - (this.max * this.options.start / this.options.steps) - this.options.offset;
	}

});

DoubleSlider.implement(new Events);
DoubleSlider.implement(new Options);
