Locale.use("nl-NL");
$$('html')[0].set('id','js');
if (Browser.Platform.win) {
	$$('html')[0].addClass('win');
}
if (Browser.ie7 || Browser.ie8){
	var tmp = new Element('div',{
		'class':'before',
		html:''
	});
	Array.each($$('#nav li.active'),function(elm) {
		tmp.inject(elm,'bottom');
	});
}
if(document.id('submitFormNow') != undefined) {
	document.id('submitFormNow').addEvent('click',function(e) {
		e.stop();
		document.id('theSearchForm').submit();
	});
}
if(document.id('expand-btn') != undefined) {
	var open = false;
	var fxy = new Fx.Morph('ContactFormExpandable', {
		duration: 1200,
		link: 'cancel'
	});
	var size = document.id('ContactFormExpandableSize').getScrollSize();
	document.id('expand-btn').addEvent('click',function(e) {
		e.stop();
		if(open == false) {
			open = true;
			fxy.start({height:size.y+1});
			document.id('expand-btn').addClass('open');
		} else {
			open = false;
			fxy.start({height:0});
			document.id('expand-btn').removeClass('open');
		}
	});
	
	if(document.id('behandelingForm').hasClass('error')) {
		open = true;
		document.id('ContactFormExpandable').setStyle('height',size.y+1);
		document.id('expand-btn').addClass('open');
	}
	
	var msk = new Mask('ContactFormExpandable', {
		inject: { where: 'inside', target: 'ContactFormExpandable' }
	});

	var msg = $$('#ContactFormExpandableSize h1')[0];
	var val = new Form.Validator.Inline('behandelingForm', {
		stopOnFailure: true,
		useTitles: true,
		errorPrefix: "",

		onFormValidate: function(passed, form, event) {
			if (passed) {
				var req = new Request.JSON({
					url: form.get('name'),
					onRequest: function() {
						msk.show();
					},
					onComplete: function(response) {
						if(response.validate.error) {
							msg.setStyle('display','block').set('class','failed').set('html',response.validate.msg);
						} else {
							msg.setStyle('display','block').set('class','success').set('html',response.validate.msg);
							Array.each($$('form input','form textarea'),function(elm,ind) {
								elm.set("disabled","disabled").addClass("disabled");
							});
							_gaq.push(['_trackPageview','/aanvraag-formulier/'+response.validate.title]);
						}
						msk.hide();
						document.id('behandelingForm').addClass('completed');
					}
				}).send(document.id('behandelingForm'));
			}
		},
		onElementFail: function(elm, arr) {
			var next = elm.getNext('div');
			elm.removeClass('read');
			
			elm.addEvent('click',function(e) {
				elm.addClass('read');
				next.dispose();
				elm.removeEvents();
			});
			elm.addEvent('focus',function(e) {
				elm.addClass('read');
				next.dispose();
				elm.removeEvents();
			});
			next.addEvent('click',function(e) {
				elm.addClass('read');
				next.dispose();
				elm.removeEvents();
			});
		}
	});
	document.id('stickup').addEvent('click',function(e) {
		e.stop();
		val.validate();
	});
	
}
if(document.id('faq') != undefined) {
	this.FAQ = [];
	var scope = this;
	Array.each($$('ul#faq li'),function(elm,ind) {
	
		scope.FAQ[ind] = {};
		scope.FAQ[ind].a = elm.getChildren('div')[0];
		scope.FAQ[ind].q = elm.getChildren('h3')[0];
		
		scope.FAQ[ind].orginal = scope.FAQ[ind].a.getCoordinates();
		scope.FAQ[ind].eFx = new Fx.Morph(scope.FAQ[ind].a,{
			time			: 1000,
			transition		: 'quint:in:out',
			link			: 'cancel'
		});
		scope.FAQ[ind].a.setStyles({height:0,overflow:'hidden'});
		
		scope.FAQ[ind].q.addEvent('click',function(e) {
			e.stop();
			
			if(elm.hasClass('open')) {
				$$('ul#faq li').removeClass('open');
				scope.FAQ[ind].eFx.start({'height':0});
			} else {
				$$('ul#faq li').removeClass('open');
				elm.addClass('open');
				
				for(i=0;i<scope.FAQ.length;i++) {
					scope.FAQ[i].eFx.start({'height':0});
				}
				scope.FAQ[ind].eFx.start({'height':scope.FAQ[ind].orginal.height});
			}
		});
	});
}
