var VGP = {
	aanbodSwitch: function(parent) {
		var aanbodParent = document.id(parent),
			aanbodSwitchers = aanbodParent.getElements('ul.switcher a'),
			aanbodSwitchees = aanbodParent.getElements('.switchee'),
			aanbodSoort = aanbodParent.getElement('#aanbodsoort'),
			aanbodMode = aanbodParent.getElement('#aanbodmode'),
			aanbodSelects = aanbodParent.getElements('.select'),
			aanbodPrices = aanbodParent.getElements('.prijslijst');

		aanbodMode.addEvent('change', function() {
			var value = aanbodMode.value || 'alle';
			aanbodSelects.each(function(select) {
				if (select.hasClass(value)) {
					select.removeClass('hidden');
					select.getElements('input, select').each(function(i) {
						i.removeProperty('disabled');
					});
				} else if (!select.hasClass('hidden')) {
					select.addClass('hidden');
					select.getElements('input, select').each(function(i) {
						i.setProperty('disabled', 'disabled');
					});
				}
			});
			if (value == 'aog') {
				aanbodSoort.getParent('div.left').addClass('hidden');
				aanbodSoort.getElement('[value=koop]').selected = true;
				aanbodPrices.each(function(price) {
					if (price.hasClass(aanbodSoort.value)) {
						price.removeClass('hidden');
						price.getElements('input, select').each(function(i) {
							i.removeProperty('disabled');
						});
					} else if (!price.hasClass('hidden')) {
						price.addClass('hidden');
						price.getElements('input, select').each(function(i) {
							i.setProperty('disabled', 'disabled');
						});
					}
				});
				aanbodSoort.setProperty('disabled', 'disabled');
			} else if (aanbodSoort.getParent('div.left').hasClass('hidden')) {
				aanbodSoort.getParent('div.left').removeClass('hidden');
				aanbodSoort.removeProperty('disabled');
			}
		});

		aanbodSoort.addEvent('change', function() {
			aanbodPrices.each(function(price) {
				if (price.hasClass(aanbodSoort.value)) {
					price.removeClass('hidden');
					price.getElements('input, select').each(function(i) {
						i.removeProperty('disabled');
					});
				} else if (!price.hasClass('hidden')) {
					price.addClass('hidden');
					price.getElements('input, select').each(function(i) {
						i.setProperty('disabled', 'disabled');
					});
				}
			});
		});

		aanbodSwitchers.each(function(s) {
			s.addEvent('click', function(e) {
				if (e) e.stop();
				var href = s.getProperty('href').replace(/^[^#]+/,'');
				aanbodSwitchees.each(function(switchee) {
					if ('#'+switchee.getProperty('id') == href) {
						switchee.removeClass('hidden');
						switchee.getElements('input, select').each(function(i) {
							i.removeProperty('disabled');
						});
					} else {
						aanbodSwitchees.each(function(switchee) {
							if ('#'+switchee.getProperty('id') == href) {
								switchee.removeClass('hidden');
								switchee.getElements('input, select').each(function(i) {
									i.removeProperty('disabled');
								});
							} else {
								switchee.addClass('hidden');
								switchee.getElements('input, select').each(function(i) {
									i.setProperty('disabled', 'disabled');
								});
							}
						});
						switchee.addClass('hidden');
						switchee.getElements('input, select').each(function(i) {
							i.setProperty('disabled', 'disabled');
						});
					}
				});
				aanbodSwitchers.each(function(a) {
					a.removeClass('active');
				});
				s.addClass('active');
			});
		});
		aanbodSwitchers[0].fireEvent('click');
	}
};

