MooTools.lang.setLanguage('nl-NL');
var VGP = {};

VGP.menu = new Class({
	Implements: [Events, Options],
	options: {
		parentID:  'nav',
		children:  'li.menu',
		toggles:   'li.menu h1 a',
		minHeight: 43,
		maxHeight: 215
	},
	initialize: function(options) {
		this.setOptions(options);
		this.parent   = $(this.options.parentID).getElement('div.content');
		this.children = this.parent.getElements(this.options.children);
		this.toggles  = this.parent.getElements(this.options.toggles);
		this.cur      = -1;
		this.active   = -1;

		this.children.each(function(child, index) {
			if (child.hasClass('active')) {
				this.active = index;
			}
		}, this);

		this.parent.setStyle('height', this.options.minHeight);
		this.children.setStyle('height', this.options.minHeight);

		this.attach();
	},
	attach: function() {
		this.toggles.each(function(toggle, index) {
			toggle.addEvent('click', function(e) {
				if (e) e.stop();
				this.show(index);
			}.bind(this));
		}, this);
	},
	show: function(index) {
		if (this.cur >= 0) {
			if (this.cur == index) {
				this.parent.tween('height', this.options.minHeight);
				this.children[index].tween('height', this.options.minHeight);
				this.children[index].getElement('h1').removeClass('active');
				if (this.active != index) {
					this.children[index].removeClass('active');
				}
				this.cur = -1;
			} else {
				this.children[this.cur].tween('height', this.options.minHeight);
				this.children[index].tween('height', this.options.maxHeight);
				if (this.active != this.cur) {
					this.children[this.cur].removeClass('active');
				}
				if (this.active != index) {
					this.children[index].addClass('active');
				}
				this.children[this.cur].getElement('h1').removeClass('active');
				this.children[index].getElement('h1').addClass('active');
				this.cur = index;
			}
		} else {
			this.parent.tween('height', this.options.maxHeight);
			this.children[index].tween('height', this.options.maxHeight);
			if (this.active != index) {
				this.children[index].addClass('active');
			}
			this.children[index].getElement('h1').addClass('active');
			this.cur = index;
		}
	},
	aanbodSwitch: function() {
		aanbodParent = this.parent.getElement('form#aanbod');
		aanbodSwitchers = aanbodParent.getElements('ul.switcher a');
		aanbodSwitchees = aanbodParent.getElements('div.switchee');
		aanbodSoort = aanbodParent.getElementById('aanbodsoort');
		aanbodMode = aanbodParent.getElementById('aanbodmode');
		aanbodSelects = aanbodParent.getElements('div.select');
		aanbodPrices = aanbodParent.getElements('div.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').removeProperty('disabled');
				} else if (!select.hasClass('hidden')) {
					select.addClass('hidden');
					select.getElements('input, select').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').removeProperty('disabled');
					} else if (!price.hasClass('hidden')) {
						price.addClass('hidden');
						price.getElements('input, select').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').removeProperty('disabled');
				} else if (!price.hasClass('hidden')) {
					price.addClass('hidden');
					price.getElements('input, select').setProperty('disabled', 'disabled');
				}
			});
		});

		aanbodSwitchers.addEvent('click', function(e) {
			if (e) e.stop();
			aanbodSwitchees.each(function(switchee) {
				if ('#'+switchee.getProperty('id') == this.getProperty('href')) {
					switchee.removeClass('hidden');
					switchee.getElements('input, select').removeProperty('disabled');
				} else {
					aanbodSwitchees.each(function(switchee) {
						if ('#'+switchee.getProperty('id') == this.getProperty('href')) {
							switchee.removeClass('hidden');
							switchee.getElements('input, select').removeProperty('disabled');
						} else {
							switchee.addClass('hidden');
							switchee.getElements('input, select').setProperty('disabled', 'disabled');
						}
					}, this);
					switchee.addClass('hidden');
					switchee.getElements('input, select').setProperty('disabled', 'disabled');
				}
			}, this);
			aanbodSwitchers.removeClass('active');
			this.addClass('active');
		});
		aanbodSwitchers[0].fireEvent('click');
	},
	profSwitch: function() {
		profParent = this.parent.getElement('form#professionals');
		profSwitchers = profParent.getElements('ul.switcher a');
		profSwitchees = profParent.getElements('div.switchee');
		profSwitchers.addEvent('click', function(e) {
			if (e) e.stop();
//			profParent.getElement('input'+this.getProperty('href')).checked = true;
			profSwitchees.each(function(switchee) {
				if ('#'+switchee.getProperty('id') == this.getProperty('href')) {
					switchee.removeClass('hidden');
					switchee.getElements('input').removeProperty('disabled');
					switchee.getElements('select').removeProperty('disabled');
				} else {
					switchee.addClass('hidden');
					switchee.getElements('input').setProperty('disabled', 'disabled');
					switchee.getElements('select').setProperty('disabled', 'disabled');
				}
			}, this);
			profSwitchers.removeClass('active');
			this.addClass('active');
		});
		profSwitchers[0].fireEvent('click');
	}
});
