function changeMerk(form) {
	currentMerk = form.merk.options[form.merk.selectedIndex].value;
	currentModel = '';
	updateModel(form, form.merk.options[form.merk.selectedIndex].value);
}
var merk_model = false;
function updateModel(form, merk) {
	ops = new Array();
	ops[0] = "-- geen voorkeur";
	var length;
	if ($type(merk_model) != 'object') { return;}
	var modellen = merk_model[merk];
	if ($type(modellen) != 'array') {
		length = 1;
	} else {
		length = modellen.length + 1;
	}
	for (j = form.model.options.length; j < length; ++j) {
		addOption(form.model);
	}
	for (j = form.model.options.length; j > length; --j) {
		form.model.options[form.model.options.length - 1] = null;
	}
	for (j = 1; j < length; ++j) {
		form.model.options[j].value = modellen[j-1];
		form.model.options[j].text = modellen[j-1];
	}
	form.model.options[0].selected = true;
	updateCount(form);
}
function addOption(select) {
	var newOpt = new Option(select.options.length, select.options.length, false, false);
	select.options[select.options.length] = newOpt;
}
var countRequest = new Request.HTML({url:'index.php', update: 'counter'});
countRequest.addEvent('complete', function() { $('counter_container').fade('in'); });
function updateCount(form) {
	form = $(form);
	$('counter_container').fade('out');
	countRequest.get({
		option:'com_occasion', 
		controller:'ajax',
		task:'count', 
		'merk':form.merk.value, 
		'model':form.model.value, 
		'brandstof':form.brandstof.value, 
		'carrosserievorm':form.carrosserievorm.value, 
		'voertuigsoort':form.voertuigsoort.value, 
		'trans':form.trans.value, 
		'bouwjaar_min':form.bouwjaar_min.value, 
		'prijs_min':form.prijs_min.value, 
		'prijs_max':form.prijs_max.value,
		'kmstand_max':form.kmstand_max.value});
}

var ImageSwitcher = new Class({
	Implements: [Chain],
	initialize: function(source, target) {
		this.source = $(source);
		this.target = $(target);
		this.targetFader = new Fx.Tween(this.target, 
							{property: 'opacity', link: 'chain', duration: 'short'});
		this.sourceFader = new Fx.Tween(this.source, 
							{property: 'opacity', link: 'chain', duration: 'short'});
		this.targetFader.addEvent('complete', 
									function() {this.callChain();}.bind(this));
		this.source.addEvent('click', this.switchImage.bind(this));
	},
	switchImage: function() {
		this.chain(
			function() {this.sourceFader.start(0);this.targetFader.start(0);},
			function() { 
				var src = this.source.src;
				this.source.src = this.target.src;
				this.target.src = src; 
				this.callChain();
			},
			function() {this.sourceFader.start(1);this.targetFader.start(1);}
			);
		this.callChain();
	}
});

