/**
 * Functions.js - Bootstrap for all Javascript functionality
 * 
 * @author  Webstores <info at webstores dot nl>
 *           Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

//WS.Event.addEvent(window, 'load', function() {
document.observe('dom:loaded', function() {
	WS.Util.toggleValue('search-field', 'focus');
	// Aanmeldingsformulier samen-uit-dag	
	if($('amount-total')) {
		//calcTotal();
		$('group-number').observe('focus', function(e) {e.element().value = e.element().value == '[in te vullen getal]' ? '' : e.element().value});
		$('toddlers-number').observe('focus', function(e) {e.element().value = e.element().value == '[in te vullen getal]' ? '' : e.element().value});
		$('museumjaarkaart-number').observe('focus', function(e) {e.element().value = e.element().value == '[in te vullen getal]' ? '' : e.element().value});
		$('supervisors-number').observe('focus', function(e) {e.element().value = e.element().value == '[in te vullen getal]' ? '' : e.element().value});		
		$('group-number').observe('keyup', function(e) {
			calcTotal();
		});
		$('group-composition').observe('change', function(e) {
			calcTotal();
		});
		$('toddlers-number').observe('keyup', function(e) {
			calcTotal();
		});
		$('museumjaarkaart-number').observe('keyup', function(e) {
			calcTotal();
		});
		$('supervisors-number').observe('keyup', function(e) {
			calcTotal();
		});
		/*$('parking-card').observe('change', function(e) {
			calcTotal();
		});*/
		new Validation('samen-uit-form', {useTitles : true});
	}
	FontSizer.initialize(['content']);
	if($('accordion')) {
		var acc = new accordion('accordion', {
			classNames: {
				toggle: 'accordion-toggle',
				toggleActive: 'accordion-toggle-active',
				content: 'accordion-content'
			}
		});
		/*acc.activate($$('.accordion-toggle')[0]);*/
	}
	if($('album-scroller')) {
		var carousel = new Carousel($('album-scroller'), $$('.slide'), $$('a.carousel-jumper'), {
			duration: 0.8,
			auto: true,
			frequency: 5,
			selectedClassName: 'selected'
		});
	}
	if($('publication-scroller')) {
		var carousel = new Carousel($('publication-scroller'), $$('.slide'), $$('a.carousel-jumper'), {
			duration: 0.8,
			auto: true,
			frequency: 5,
			selectedClassName: 'selected'
		});
	}
	if($('toggle-contact')) {
		WS.Event.addEvent('toggle-contact', 'click', function(e) {
			WS.toggleClass('toggle-contact', 'expanded');
			WS.toggleClass('contact-form', 'collapsed');
			WS.Event.stopEvent(e);
		});
	}
	if($('reply-toggle')) {
		WS.Util.createToggle('reply');
		WS.hide('reply-container');
	}	
	if($('replyfull-toggle')) {
		WS.Util.createToggle('replyfull');
		WS.hide('replyfull-container');
	}
	if($('replynews-toggle')) {
		WS.Util.createToggle('replynews');
		WS.hide('replynews-container');
	}		
	if($('publication-tabs')) {
		var publicationTabs = new Tabs('publication-tabs');
		publicationTabs.initialize();
	}
});

var calcTotal = function() {
	var groupNumber = $('group-number').value;
	var toddlers = $('toddlers-number').value;
	var museumjaarkaarthouders = $('museumjaarkaart-number').value;
	var supervisors = $('supervisors-number').value;
	var groupComposition = $('group-composition').value;
	//var parkingCard = $('parking-card').checked;
	
	var total = groupNumber * 10;	
	total = total - (toddlers * 10) - (museumjaarkaarthouders * 10) - (supervisors * 10);	
	total = groupComposition == 'als gezin' && total > 30 ? 30 : total;
	total = total < 0 ? 0 : total;
	//total += parkingCard ? 4.5 : 0;
		
	$('amount-total').innerHTML = String(total).replace('.', ',');
}
