/***********************************************************************

Author:     4rn0
Company:    Tiekstramedia
URL:        http://www.tiekstramedia.nl
			http://www.4rn0.nl

***********************************************************************/


/* Initialize behaviour on page or DOM load
-------------------------------------------------------------------- */
if (document.addEventListener) { document.addEventListener('DOMContentLoaded',init,null); }
/*@cc_on @*/ /*@if (@_win32) document.write("<script defer src=/js/init.js><"+"/script>"); /*@end @*/
window.onload = init;

function init() {

	if (arguments.callee.done) {
		return;
	}
	
	arguments.callee.done = true;
	
	if (typeof(document.getElementById) == 'undefined') {
		document.getElementById = function(id) {
			return document.all[id];
		};
	}
	toggleSearchForm();
	initializeSiteMap();
	selectBoxZindexHack();
}

function toggleSearchForm() {

	var searchTimer;
	var searchButton = document.getElementById('searchButton');
	var searchForm = document.getElementById('searchForm');
	
	if (searchButton && searchForm) {
		searchButton.onclick = function() {
			
			var searchForm = document.getElementById('searchForm');
			var searchButton = document.getElementById('searchButton');
			var searchInput = document.getElementById('query');
			
			if (searchForm && searchButton && searchInput) {
				searchButton.parentNode.className = (searchForm.style.visibility == 'visible') ? '' : 'active';
				searchForm.style.visibility = (searchForm.style.visibility == 'visible') ? 'hidden' : 'visible';
				searchForm.style.visibility == 'visible' ? searchInput.focus() : searchInput.blur();
			}
			
			return false;
			
		};
		
	
		searchForm.onmouseout = function() {
			searchTimer = setTimeout(hideSearchForm, 500);
		};
	
		searchForm.onmouseover = function() {
			clearTimeout(searchTimer);
		};
		
	}
}

function hideSearchForm() {

	var searchButton = document.getElementById('searchButton');
	var searchForm = document.getElementById('searchForm');
	var searchInput = document.getElementById('query');
	
	searchButton.parentNode.className = '';
	searchForm.style.visibility = 'hidden';
	searchInput.blur();
	
	var allSelectBoxes  = document.getElementsByTagName('select');	for (j=0; j<allSelectBoxes.length; j++) {		if (allSelectBoxes[j].style.visibility == 'hidden') {			allSelectBoxes[j].style.visibility = 'visible';		}	}}

function initializeSiteMap() {
	
	var lis = document.getElementsByTagName('LI');
	if (lis) {
		for (var i = 0; i < lis.length; i++) {
			if (lis[i].className == 'active') {
				lis[i].className = null;
				lis[i].getElementsByTagName('A')[0].onclick = toggleSiteMap;
			}
		}
	}
	
}

function toggleSiteMap() {
	this.parentNode.className = (this.parentNode.className == 'active') ? null : 'active';
	return false;
}function selectBoxZindexHack() {	var allUls = document.getElementsByTagName('ul');	var allSelectBoxes  = document.getElementsByTagName('select');	var searchForm = document.getElementById('searchForm');	for (i = 0; i < allUls.length; i++) {		if (allUls[i].className == 'mainNavigation') {						allUls[i].onmouseover = function() {				for (j=0; j<allSelectBoxes.length; j++) {					allSelectBoxes[j].style.visibility = "hidden";				}			}						allUls[i].onmouseout = function() {				for (j=0; j<allSelectBoxes.length; j++) {					if (allSelectBoxes[j].style.visibility == 'hidden' && searchForm.style.visibility != 'visible') {						allSelectBoxes[j].style.visibility = 'visible';					}				}			}					}	}}