
Event.observe(window, 'load', function() {
	initSifr();
	attachFlashAnim();
	attachBlokControl();
	attachContactForm();
	attachFaqScroll();
});

var SifrInitialized = false;

function initSifr() {
	if (typeof(sIFR)=='function') {
		
		sIFR.rollback("h1");
		
		sIFR.replaceElement("h1", named({
			sFlashSrc: "/swf/fonts/helvetica_thin.swf",
			sColor: "#FFFFFF",
			sWmode: 'transparent' 
			}));
		sIFR.replaceElement(".left h2", named({
			sFlashSrc: "/swf/fonts/helvetica_thin.swf",
			sColor: "#E2001A",
			sWmode: 'transparent',
			sFlashVars: 'textalign=right'
			}));
		sIFR.replaceElement(".page h2", named({
			sFlashSrc: "/swf/fonts/helvetica_thin.swf",
			sColor: "#E2001A",
			sWmode: 'transparent'
			}));
	}
}

function attachFlashAnim() {
	if ($('flashanim')) {
		var so = new SWFObject("/swf/webplayer/webplayer.swf", "webplayer", "800", "290", "8", "#000000");
		so.addParam("quality", "high");
		so.write("flashanim");
	}
	
	
}

function attachBlokControl() {
	
	if ($('blokcontrol')) {
		
		var CurrentBlok = 'blok0';

		
		$A($$('#blokcontrol a')).each(function(el) {
			el.observe('click', function(e) {
				Event.stop(e);
				focuscatch();
				$A($$('#blokcontrol a.active')).each(function(el) {
					el.removeClassName('active');
				});
				
				var parts = el.href.split('#');
				$(CurrentBlok).hide();
				CurrentBlok = parts[1];
				$(CurrentBlok).show();
				initSifr();
				el.addClassName('active');
				/*
				$(CurrentBlok).appear({
					duration:0.3,
					afterFinish: function() {
						initSifr();
						}
				});
				*/
			})
		});
	}
}

function attachContactForm() {
	if ($('contactform')) {
		Form.focusFirstElement('contactform');
		$A($$('input.nietzakelijk')).each(function(el) {
			el.observe('click', function() {
				toggleZakelijk(false)
			});
		});
		$A($$('input.zakelijk')).each(function(el) {
			el.observe('click', function() {
				toggleZakelijk(true)
			});
		});
		$A($$('.labeltoggle')).each(function(el) {
			el.observe('click', function() {
				switch($F(el)) {
					case 'sportzaak':
						$('club_of_bedrijf_label').innerHTML = 'Sportzaak:';
					break;
					case 'tennisschool':
						$('club_of_bedrijf_label').innerHTML = 'Tennisschool:';
					break;
					default:
						$('club_of_bedrijf_label').innerHTML = 'Tennisclub:';
					break;
				}
			});
		});
		$('contactform').observe('submit', function(e) {
			Event.stop(e);
			var validForm = validateForm('contactform');
            if (validForm) {
            	$('contactform').request({
	                onComplete: function(transport) {
            			if(transport.responseText=='true') {
            				$('contactform').hide();
            				$('contactform').innerHTML = 'Bedankt voor uw interesse, wij nemen spoedig contact met u op.';
            				$('contactform').appear({duration:0.3});
            			} else {
            				window.alert(transport.responseText);
            			}
	                }
            	});
            }
		});
	}
}

function toggleZakelijk(display) {
	if (display) {
		if (!$('zakelijk').visible()) {
			$('zakelijk').blindDown({duration:0.2});
		}
	} else {
		if ($('zakelijk').visible()) {
			$('zakelijk').blindUp({duration:0.2});
		}
	}
}

function attachFaqScroll() {
	if ($('faqscroll_container')) {
		var faqscroll = new Control.ScrollBar('faqscroll_content','faqscroll_track');  
	}
}

function focuscatch() {
	$('focuscatch').focus();
}
