var currentForm;

window.addEvent('domready', function() {

// Direct Advies Accordion --------------------------------------------------------------------------------
	var accordion = new Accordion($$('.advies-toggler'),$$('.advies-element'), {
		opacity: 50,
		start: 'all-closed',
		alwaysHide: true
	});

// Form Info Accordion --------------------------------------------------------------------------------	
	var accordion2 = new Accordion($$('.info-toggler'),$$('.info-element'), {
		opacity: 100,
		start: 'all-closed',
		alwaysHide: true
	});

//Show hide Hypotheekvormen --------------------------------------------------------------------------------
	$('verstuur-btn').addClass('hideme'); // Start by hiding the 'VERSTUUR' button
	var divs = $$(['#bestaandewoning-container', '#nieuwbouwwoning-container', '#oversluiting-container', '#tweedehypotheek-container', '#woonboot-container', '#scheepshypotheek-container', '#recreatiewoning-container']);
	divs.each(function(div){
		var link = $(div.id + '-toggler');
		div.setStyle('display', 'none');
		link.addEvent('click', function(e){
			e = new Event(e);
			divs.each(function(other){
				if (other != div) {
					other.setStyle('display', 'none');
				} else {
					if (div.submited) {
						// Form as already been submited with success
						$('verstuur-btn-success').removeClass('hideme');
						$('verstuur-btn').addClass('hideme');
						$('verstuur-btn-spinner').addClass('hideme');
					} else {
						// Form as never been submited or submited but errors
						$('verstuur-btn').removeClass('hideme');
						$('verstuur-btn-success').addClass('hideme');
						$('verstuur-btn-spinner').addClass('hideme');
					}
				}
			});
			
			div.setStyle('display', (div.getStyle('display') == 'block') ? 'none' : 'block');
			e.stop();
		});
	});

// MooForms Custom Radio --------------------------------------------------------------------------------
    MooRadioButtons = new mooForms('form', {
		imageDir: 'uploads/scripts/mooforms/images/',
		radioImage: {image: 'radio.png', width: 34, height: 34}
	});

// Autocomplete for form WOONPLAATS fields --------------------------------------------------------------------------------
	var plaatsen = ['Amsterdam', 'Bussum'];
	new Autocompleter.Local('woonplaats1', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats2', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats3', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats4', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats5', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats6', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});
	new Autocompleter.Local('woonplaats7', plaatsen, {
		'minLength': 1,
		'overflow': false,
		'width': '220px',
		'selectMode': 'type-ahead',
		'forceSelect': 'false'
	});

// Smooth scroll when video opens to top of page --------------------------------------------------------------------------------
	new SmoothScroll({ duration:700 }, window);

// MooMask --------------------------------------------------------------------------------
	Mask = new mooMask();
	Mask.inlineMask(); //Inline Masking

// Tooltips --------------------------------------------------------------------------------
	theTips = new TipsX3 ($$('.tipper'));

// Focus style change on input and textarea --------------------------------------------------------------------------------
	$$('input').addEvents({
		'focus': function() { this.addClass('focus'); },
		'blur': function() { this.removeClass('focus'); }
	});
	$$('textarea').addEvents({
		'focus': function() { this.addClass('focus'); },
		'blur': function() { this.removeClass('focus'); }
	});
	$$('.verstuur-btn').addEvents({
		'mouseover': function() { this.addClass('hover'); },
		'mouseout': function() { this.removeClass('hover'); }
	});

// -------------------------------------------------------------------------------------------------------------------

// Hypotheekvorm :::: Show ROAR in case of Success
	var handleSuccess = function(theResponse) {
		var roar = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roar.alert('Verzonden', theResponse);
		currentForm.setStyle('display','none');
		currentForm.div.submited=true;
		$('verstuur-btn-success').removeClass('hideme');
		$('verstuur-btn').addClass('hideme');
		$('verstuur-btn-spinner').addClass('hideme');
	}

	var handleFailure = function(theResponse) {
		var roar = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roar.alert('Fout!', theResponse);
	}

	var handleAjaxResponse = function(theResponse) {
		if (theResponse.match('Uw')) { // This is linked to the formscript.php file line 1578
			handleSuccess(theResponse);
		} else {
			handleFailure(theResponse);
		}
	}

// Hypotheekvorm :::: Submit the activated form
	$$('.verstuur-btn').addEvents({ // Link the VERSTUUR button to sending the form
        'click': function() {submitActiveForm();}
	});
	var submitActiveForm = function() { // Once the submit button is clicked,
		$('verstuur-btn').addClass('hideme'); // hide the submit button and 
		$('verstuur-btn-spinner').removeClass('hideme'); //show the spinner button
		
		var divs = $$(['#bestaandewoning-container', '#nieuwbouwwoning-container', '#oversluiting-container', '#tweedehypotheek-container', '#woonboot-container', '#scheepshypotheek-container', '#recreatiewoning-container']);
		/* let's get the current displayed form */
		divs.each(function(div){
			if (div.getStyle('display')!='none') {
				/* get the form inside the div */
				var theForm=div.getElement('form');
				currentForm=theForm;
				currentForm.div=div;

				/* define ajax behavior */
				var ajax_propertie=theForm.get('send');
				ajax_propertie.addEvent('onSuccess',function(responseText) {
					handleAjaxResponse(responseText);
				});

				/* warning, probably mootools bug, certainly strange behavior,  */
				/* you really need to force the Url using theForm.action in the line below */
				theForm.send(theForm.action);
			}
		});
	}

// -------------------------------------------------------------------------------------------------------------------

// Stuur een email :::: Submit
	$$('.stuuremail-btn').addEvents({ // Link the VERSTUUR button to sending the form
        'click': function() {submitStuuremail();}
	});
	var submitStuuremail = function() { // Once the submit button is clicked,
		$('stuuremail-btn').addClass('hideme'); // hide the submit button and 
		$('stuuremail-btn-spinner').removeClass('hideme'); //show the spinner button
		
		var divsStuuremail = $$(['#stuuremail-container']);
		/* let's get the current displayed form */
		divsStuuremail.each(function(divStuuremail){
			if (divStuuremail.getStyle('display')!='none') {
				/* get the form inside the div */
				var theStuuremailForm=divStuuremail.getElement('form');
				currentStuuremailForm=theStuuremailForm;
				currentStuuremailForm.divStuuremail=divStuuremail;

				/* define ajax behavior */
				var ajax_Stuuremailpropertie=theStuuremailForm.get('send');
				ajax_Stuuremailpropertie.addEvent('onSuccess',function(responseStuuremailText) {
					handleStuuremailAjaxResponse(responseStuuremailText);
				});

				/* warning, probably mootools bug, certainly strange behavior,  */
				/* you really need to force the Url using theForm.action in the line below */
				theStuuremailForm.send(theStuuremailForm.action);
			}
		});
	}
	
// Stuur een email :::: Show ROAR in case of Success
	var handleStuuremailSuccess = function(theStuuremailResponse) {
		var roarStuuremail = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roarStuuremail.alert('Verzonden', theStuuremailResponse);
		$('stuuremail-btn-success').removeClass('hideme');
		$('stuuremail-btn').addClass('hideme');
		$('stuuremail-btn-spinner').addClass('hideme');
	}

	var handleStuuremailFailure = function(theStuuremailResponse) {
		var roarStuuremail = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roarStuuremail.alert('Fout!', theStuuremailResponse);
	}

	var handleStuuremailAjaxResponse = function(theStuuremailResponse) {
		if (theStuuremailResponse.match('Uw')) { // This is linked to the formscript.php file line 1578
			handleStuuremailSuccess(theStuuremailResponse);
		} else {
			handleStuuremailFailure(theStuuremailResponse);
		}
	}
	
// -------------------------------------------------------------------------------------------------------------------

// Bel mij terug :::: Submit
	$$('.belmijterug-btn').addEvents({ // Link the VERSTUUR button to sending the form
        'click': function() {submitBelmijterug();}
	});
	var submitBelmijterug = function() { // Once the submit button is clicked,
		$('belmijterug-btn').addClass('hideme'); // hide the submit button and 
		$('belmijterug-btn-spinner').removeClass('hideme'); //show the spinner button
		
		var divsBelmijterug = $$(['#belmijterug-container']);
		/* let's get the current displayed form */
		divsBelmijterug.each(function(divBelmijterug){
			if (divBelmijterug.getStyle('display')!='none') {
				/* get the form inside the div */
				var theBelmijterugForm=divBelmijterug.getElement('form');
				currentBelmijterugForm=theBelmijterugForm;
				currentBelmijterugForm.divBelmijterug=divBelmijterug;

				/* define ajax behavior */
				var ajax_Belmijterugpropertie=theBelmijterugForm.get('send');
				ajax_Belmijterugpropertie.addEvent('onSuccess',function(responseBelmijterugText) {
					handleBelmijterugAjaxResponse(responseBelmijterugText);
				});

				/* warning, probably mootools bug, certainly strange behavior,  */
				/* you really need to force the Url using theForm.action in the line below */
				theBelmijterugForm.send(theBelmijterugForm.action);
			}
		});
	}
	
// Bel mij terug :::: Show ROAR in case of Success
	var handleBelmijterugSuccess = function(theBelmijterugResponse) {
		var roarBelmijterug = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roarBelmijterug.alert('Verzonden', theBelmijterugResponse);
		$('belmijterug-btn-success').removeClass('hideme');
		$('belmijterug-btn').addClass('hideme');
		$('belmijterug-btn-spinner').addClass('hideme');
	}

	var handleBelmijterugFailure = function(theBelmijterugResponse) {
		var roarBelmijterug = new Roar({
			position:'upperLeft',
			duration: 10000
		});
		// First parameter is the title but not very usefull here
		roarBelmijterug.alert('Fout!', theBelmijterugResponse);
	}

	var handleBelmijterugAjaxResponse = function(theBelmijterugResponse) {
		if (theBelmijterugResponse.match('Uw')) { // This is linked to the formscript.php file line 1578
			handleBelmijterugSuccess(theBelmijterugResponse);
		} else {
			handleBelmijterugFailure(theBelmijterugResponse);
		}
	}

// End window.addEvent
});







// Image and Video player
	var flashvars = {};
	flashvars.xmlfile = "http://www.deinternethypotheek.nl/imageadmin/images.php?album=1";
	// ---
	var params = {};
	params.allowScriptAccess = "always";
	params.wmode = "transparent";
	// ---
	var attributes = {};
	// ---
	swfobject.embedSWF("uploads/scripts/ssp/player.swf", "player", "425", "319", "8.0.0", "scripts/ssp/expressInstall.swf", flashvars, params, attributes);
// END
