/**************************************************************
Event attacher
Voorbeeld van gebruik: document.attachEvent("onload", functieNaamHier);
***************************************************************/
document.events = [];
document.attachEvent = function(type, reference) {

    var evt = this.events;
    if(!evt[type]) evt[type] = [];
    evt[type][evt[type].length] = reference;

    document[type] = function(e) {
        document.executeEvents(type, e);
    }
}

document.executeEvents = function(type, e) {
    for(var i in this.events[type]) {
        this.events[type][i](e);
    }
}

window.onunload = function() { document.executeEvents('onunload'); }
window.onload = function() { document.executeEvents('onload'); }
window.onresize = function() { document.executeEvents('onresize'); }

document.attachEvent("onresize", siteHeight);

/**********************************************************************
Statistieken teller.
**********************************************************************/
function pageHit(){
	p = escape(document.location.href);
	rfr = escape(document.referrer);
	if (rfr == "undefined"){ rfr = "";}
	sx = screen.width;
	sy = screen.height;
	sc = (navigator.appName.indexOf("Microsoft") > -1) ? screen.colorDepth : screen.pixelDepth;
	src = 'stats.php?p=' + p + '&rfr=' + rfr + '&sx=' + sx + '&sy=' + sy + '&sc=' + sc;
	src = '<img style="position:absolute;left:-10px;top:-10px;" src="' + src + '" width="1" height="1" border="0" alt="" />';
	document.getElementById('counter').innerHTML = src;

	//console.log(src);
}

/**********************************************************************
jQuery
**********************************************************************/
$(document).ready(function(){
	pageHit();

	// Drop down menu
	$('#mainnavigation').droppy();
	$('#subnavigation').droppy();

	// pijltjes achter de menuitems zetten waar een submenu onder zit (alleen in #mainnavigation kunnen submenu's voorkomen. In #subnavigation dus niet)
	$('#mainnavigation ul li:has(ul)').children('a').append('&nbsp;<img src="images/bullet3.gif">');

    // Aan het laatst item van het hoofdmenu de class "last" toevoegen, zodat daar geen grijs streepje naast komt
    $('#mainmenu > ul:first > li:last > a:first').addClass("last");

	// Hoogte van de site oprekken tot minimaal browser grootte
	siteHeight();

	// Search submit link
	$('#submitSearch').click(function(event){
		event.preventDefault();

		if($('#keyword')[0].value == ''){
			alert('Please fill in a keyword');
		} else {
			document.zoeken.submit();
		}
	});

});

// function for preloading images
jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// Hoogte van de site oprekken tot minimaal browser grootte
function siteHeight(){
	if(jQuery.browser.msie){
		iWindowHeight = document.documentElement.clientHeight;
	} else {
		iWindowHeight = window.innerHeight;
	}
	iSiteHeight = $('#siteWrap').height();

	if(iSiteHeight < iWindowHeight){
		iDifference = iWindowHeight - iSiteHeight;

		// Let op: in ie6 wordt de iContentHeight niet goed ingesteld (2 pixels...)
		if(document.getElementById('contentWrap2cols')){
			iContentHeight = $('#contentWrap2cols').height() + iDifference;
			$('#contentWrap2cols').css('height',iContentHeight+'px');
		} else if(document.getElementById('contentWrap3cols')){
			iContentHeight = $('#contentWrap3cols').height() + iDifference;
			$('#contentWrap3cols').css('height',iContentHeight+'px');
		}
	}
}


