
Event.observe(window, 'load', function() {
	attachMenu();
	attachLoginToggle();
	Cufon.replace('#submenu');
	initFlir();
});

var SifrInitialized = false;

function initFlir() {
	if (typeof(FLIR)!='undefined') {
		FLIR.init( { path: '/js/lib/facelift-2.0b3-B/' } );

		$$('#left h1, #content h1, #content h2, #side h2, .besloten_side h2').each(function(el) {
			FLIR.replace(el, new FLIRStyle({ cFont: 'din', mode: 'wrap'}));
		});
	}
}
function initSifr() {
	if (typeof(sIFR)=='function') {
		sIFR.replaceElement("#left h1", named({
			sFlashSrc: "/swf/fonts/din.swf",
			sColor: "#E85425", //oranje
			sWmode: 'transparent',
			sFlashVars: 'textalign=right' 
			}));
		sIFR.replaceElement("#content h1", named({
			sFlashSrc: "/swf/fonts/din.swf",
			sColor: "#E85425", //oranje
			sWmode: 'transparent'
			}));
		sIFR.replaceElement("#content h2", named({
			sFlashSrc: "/swf/fonts/din.swf",
			sColor: "#5A5A5C", //grijs
			sWmode: 'transparent'
			}));
		sIFR.replaceElement("#side h2", named({
			sFlashSrc: "/swf/fonts/din.swf",
			sColor: "#E85425", //oranje
			sWmode: 'transparent'
			}));
			
		sIFR.replaceElement(".besloten_side h2", named({
			sFlashSrc: "/swf/fonts/din.swf",
			sColor: "#5A5A5C", //grijs
			sWmode: 'transparent',
			sFlashVars: 'textalign=right' 
			}));
	}
}

function attachLoginToggle() {
	$A($$('#headermenu a')).each(function(el) {
		if (el.href.include('besloten/inloggen')) {
			el.observe('click', function(e) {
				Event.stop(e);
				$('login').toggle();
				if ($('login').visible()) {
					$('loginForm').focusFirstElement();
				}
			});
		}
	});

}

function attachMenu() {
	
	$A($$('#menu a.mainitem')).each(function(el) {
		var submenu = $('sub' + el.id);
		el.observe('mouseover', function(e) {
			submenu.show();
			submenu.stopObserving('mouseout');
			submenu.stopObserving('mouseover');
			submenu.observe('mouseover', function(e) {
				submenu.show();
			});
			submenu.observe('mouseout', function(e) {
				submenu.hide();
			});
		});
		el.observe('mouseout', function(e) {
			submenu.hide();
		});
		
		/*
		var ancestor = el.ancestors();
		var sibling = el.siblings();
		if (ancestor[0].hasClassName('item')) {
		} else {
			
		}
		*/
	});
}
