                // addLoadEvent function
                function addLoadEvent(fn) {
                    var oldonload = window.onload;
                    if (typeof window.onload != 'function') {
                        window.onload = fn;
                    } else {
                        window.onload = function() {
                            oldonload();
                            fn();
                        }
                    }
                }
                //addLoadEvent(init);


                // Init function
                function init() {
                    // Code to run after window.onLoad
                    if (window.initLightbox) {
                        initLightbox();
                    }

                    initCalendars();
                    //initNewsletters();

                }

jQuery.noConflict();
jQuery(document).ready( function() {

    // Code to run after window.onLoad
    if (window.initLightbox) {
        initLightbox();
    }

    // links met rel="external" openen in een nieuw venster
    jQuery('A[rel="external"]').click( function() {
        window.open(jQuery(this).attr('href') );
        return false;
    } );
    
    // fix interne links
    jQuery('A[href*=#]').each(function() {                                        
        //vervang de href voor het pad naar deze pagina + de hash van de interne link
        jQuery(this).attr('href', location.pathname + jQuery(this).attr('href'));
    });

    //stretch right column
    stretchRightColumn();

    initCalendars();
    //initNewsletters();

});

// stretch right column to full length
function stretchRightColumn() {

    //zoek column die we moeten stretchen
    if (jQuery("#rightColumn").length > 0) {
        var sDiv = "#rightColumn";
    } else if (jQuery("#rightColumnBig").length > 0) {
        var sDiv = "#rightColumnBig";
    } else if (jQuery("#rightColumnSmall").length > 0) {
        var sDiv = "#rightColumnSmall";
    }

    //bereken benodigde elementen
    iPage = jQuery(document).height();
    iHeader = jQuery("#header").height();
    iFooter = Math.max(jQuery("#footer").height(), jQuery("#footer_klein").height());
    iPaddingTop = Math.max(jQuery(sDiv).css('padding-top').replace('px', ''), 1);
    iRightColumn = iPage - iHeader - iFooter - iPaddingTop;

    //jQuery(sDiv).css('height', '');
    // for ie6, set height since min-height isn't supported
    if (jQuery.browser.msie && jQuery.browser.version == 6.0) {
        jQuery(sDiv).css('height', iRightColumn + 'px');
    }
    //jQuery(sDiv).css('min-height', iRightColumn + 'px');

}

// initCalendar function
function initCalendars() {

    //maak maand-dropdown-box
    if (jQuery('.calendarModule') !== null) {
        jQuery('.calendarModule').each(function(index, Element) {

            //vind div en maak event handlers aan
            var oMonthSpan = jQuery(this).find(".month");
            oMonthSpan.mouseover( function() {
                chooseMonthCalendar(this);
            });

            oMonthSpan.mouseout( function () {
                if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
                    clearTimeout(oTimeoutCalenderChooseMonthPopup);
                }
                oTimeoutCalenderChooseMonthPopup = setTimeout(function () { closeChooseMonthPopup(); }, 500);
            });

            oMonthSpan.click( function () {
                return false;
            });

            buildCalendar(this);

        });
    }

}

// buildCalendar function
function buildCalendar(oCalendar) {

    var aDls = jQuery(oCalendar).find('dl').each( function(index, Element) {

        var aChildNodes = jQuery(this).children();
        var oDt = null;
        var oDd = null;

        jQuery(aChildNodes).each( function(sub_index, sub_Element) {

            if (this.tagName == 'DT') {
                oDt = jQuery(this);
            } else if (jQuery(this).hasClass('calendarInfobox')) {
                oDd = jQuery(this);
            }

            if ((jQuery(oDt).length > 0) && (jQuery(oDd).length > 0)) {

                //jQuery(oDt).contents = jQuery(oDd).html();
                var htmlContent = jQuery(oDd).html();
                jQuery(oDt).mouseover( function () {

                    if (window.oTimeoutCalenderPopup !== undefined) {
                        clearTimeout(oTimeoutCalenderPopup);
                    }
                    closeCalendarPopup();

                    var oBody = jQuery(document).find("body:first");

                    var oCalendarInfobox = document.createElement("div");
                    oCalendarInfobox.setAttribute('id','calendarInfobox');
                    oCalendarInfobox.innerHTML = htmlContent;
                    oBody.append(oCalendarInfobox);

                    var oCalendarInfoboxArrow = document.createElement("div");
                    oCalendarInfoboxArrow.setAttribute('id','calendarInfoboxArrow');
                    oBody.append(oCalendarInfoboxArrow);

                    var aPos = findPos(this);
                    oCalendarInfobox.style.left = aPos[0] - oCalendarInfobox.clientWidth - 18 - 5 + "px";
                    oCalendarInfobox.style.top = aPos[1] - (oCalendarInfobox.clientHeight / 2) + "px";

                    oCalendarInfoboxArrow.style.left = aPos[0] - 5 - 9 + "px";
                    oCalendarInfoboxArrow.style.top = aPos[1] + 4  + "px";

                    jQuery(oCalendarInfobox).mouseover( function () {
                        if (window.oTimeoutCalenderPopup !== undefined) {
                            clearTimeout(oTimeoutCalenderPopup);
                        }
                    });

                    jQuery(oCalendarInfobox).mouseout( function () {
                        oTimeoutCalenderPopup = setTimeout (function () { closeCalendarPopup(); }, 500);
                    });

                });

                jQuery(oDt).mouseout( function () {
                    if (window.oTimeoutCalenderPopup !== undefined) {
                        clearTimeout(oTimeoutCalenderPopup);
                    }

                    oTimeoutCalenderPopup = setTimeout (function () { closeCalendarPopup(); }, 500);
                });

                jQuery(oDt).click( function () {
                    return false;
                });

                // Reset
                oDt = null;
                oDd = null;
            }


        });

    });

}

// closeCalendarPopup function
function closeCalendarPopup () {

    var oBody = jQuery(document).find("body:first");
    var oCalendarInfobox = jQuery("#calendarInfobox");

    if (!oCalendarInfobox) {
        return false;
    }

    var oCalendarInfoboxArrow = jQuery("#calendarInfoboxArrow");
    jQuery(oCalendarInfobox).remove();
    jQuery(oCalendarInfoboxArrow).remove();

}

// chooseMonthCalendar function
function chooseMonthCalendar (oMonthSpan) {

    if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
        clearTimeout(oTimeoutCalenderChooseMonthPopup);
    }
    closeChooseMonthPopup();

    var oBody = jQuery(document).find("body:first");

    var oCalendarMonthBox = document.createElement("div");
    oCalendarMonthBox.setAttribute('id','calendarMonthBox');
    oCalendarMonthBox.innerHTML = oMonthSpan.lastChild.innerHTML;
    oCalendarMonthBox.style.display = "block";

    jQuery(oBody).append(oCalendarMonthBox);

    var aPos = findPos(oMonthSpan);
    oCalendarMonthBox.style.left = aPos[0] - 22 + "px";
    oCalendarMonthBox.style.top = aPos[1] + 13 + "px";

    jQuery(oCalendarMonthBox).mouseover( function () {
        if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
            clearTimeout(oTimeoutCalenderChooseMonthPopup);
        }
    });

    jQuery(oCalendarMonthBox).mouseout( function () {
        oTimeoutCalenderChooseMonthPopup = setTimeout (function () { closeChooseMonthPopup(); }, 500);
    });

    oMonthSpan.onclick = null;
}

// closeChooseMonthPopup function
function closeChooseMonthPopup () {

    var oBody = jQuery(document).find("body:first");
    var oCalendarMonthBox = jQuery("#calendarMonthBox");

    if (!oCalendarMonthBox) {
        return false;
    }
    jQuery(oCalendarMonthBox).remove();

}

// findPos function
function findPos(obj) {
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }

    return [curleft,curtop];
}


/*
// Ajax request nieuwsbrief
function initNewsletters() {

    var aNewsletterModules = $$('.newsletterModule');

    var i = aNewsletterModules.length;
    while (i--) {
        if (aNewsletterModules[i].getElement('form').hasClass('subscribeForm')) {
            new Newsletter(aNewsletterModules[i].getProperty('id'));
        }
    }

}

var Newsletter = new Class({
    initialize:         function (sModuleId) {
                            this._sModuleId = sModuleId;

                            $(sModuleId).getElement('form').addEvent('submit', this.sendRequest.bind(this));
                        },

    sendRequest:        function (e) {
                            new Event(e).stop();

                            new Request.JSON({
                                url:        'nieuwsbrief/register/submit/',
                                onRequest:  this.onRequestHandler.bind(this),
                                onSuccess:  this.onSuccessHandler.bind(this),
                                onFailure:  this.onFailureHandler.bind(this)
                            }).post($(this._sModuleId).getElement('form'));
                        },

    onRequestHandler:   function () {
                            $(this._sModuleId).getElement('form').setStyle('display', 'none');
                            $(this._sModuleId).getFirst('.ajaxResponse').setStyle('display', 'none');
                            $(this._sModuleId).getFirst('.ajaxLoader').setStyle('display', 'block');
                        },

    onFailureHandler:   function () {
                            $(this._sModuleId).getElement('form').setStyle('display', 'block');
                            $(this._sModuleId).getFirst('.ajaxResponse').setStyle('display', 'block');
                            $(this._sModuleId).getFirst('.ajaxLoader').setStyle('display', 'none');

                            $(this._sModuleId).getFirst('.ajaxResponse').empty();
                            $(this._sModuleId).getFirst('.ajaxResponse').appendText('Fout bij het verzenden van het formulier.');
                        },

    onSuccessHandler:   function (oResponseText) {
                            $(this._sModuleId).getFirst('.ajaxResponse').setStyle('display', 'block');
                            $(this._sModuleId).getFirst('.ajaxLoader').setStyle('display', 'none');


                            $(this._sModuleId).getFirst('.ajaxResponse').empty();

                            if (oResponseText.success) {
                                $(this._sModuleId).getElement('form').setStyle('display', 'none');
                                $(this._sModuleId).getFirst('.ajaxResponse').appendText(oResponseText.msg);
                            } else {
                                $(this._sModuleId).getElement('form').setStyle('display', 'block');
                                $(this._sModuleId).getFirst('.ajaxResponse').innerHTML = 'Foutmelding: <br />' + oResponseText.msg;
                            }
                        }
});
*/

