$(document).ready(function(){

    $('img[data-hover],input[data-hover]').imghover();
	
    if ($.browser.msie && $.browser.version < 7) {
        $('img[src$=.png]').pngfix();
    }

    $('input[data-placeholder]').inputPlaceholder();

    var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
    $('a').each(function(){
        var href = $(this).attr('href');
        if (href.match(filetypes)){
            $(this).click(function() {
                _gaq.push(['_trackPageview', href]);
            });
        }
    });

    // Menu
    $('#mainmenu>ul>li>a').hover(function(){
        closeMenus();
        $(this).addClass('active');
        $(this).parent().find('>ul').show();
    });

    function closeMenus(){
        $('#mainmenu a.active').removeClass('active');
        $('#mainmenu>ul>li>ul').hide();
    }

    var closeTimer;
    $('#mainmenu>ul>li').hover(function(e){
        if (e.type === 'mouseenter') {
            clearTimeout(closeTimer);
        } else {
            closeTimer = setTimeout(closeMenus,400);
        }
    });

    // Submenu's
    $('div.submenu_opener').each(function(){
        var p = $(this);
        var s = $(this).next('ul');

        if (s.length > 0) {
            $('<div></div>').click(function(){
                if (p.hasClass('active')) {
                    s.hide();
                    p.removeClass('active');
                } else {
                    var g = p.attr('data-group') || '';
                    if (g) $('div.submenu_opener[data-group='+g+'].active>div').click();
                    s.show();
                    p.addClass('active');
                }
            }).appendTo(this);
			
            if (!$(this).hasClass('active')) {
                s.hide();
            }
        }
    });

    $('li.subsub').each(function(){
        var s = $(this).find('ul');

        if (s.length > 0) {
            $('<div></div>').click(function(){
                var li = $(this).parent('li');
                if (li.hasClass('active')) {
                    s.hide();
                    li.removeClass('active');
                } else {
                    s.show();
                    li.addClass('active');
                }
            }).insertAfter($(this).find('>a'));
	
            if (!$(this).hasClass('active')) {
                s.hide();
            }
        }
    });

    $("#datepicker").each(function(){
        $(this).datepicker({
            dateFormat: 'DD dd-mm-yy',
            dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
            dayNamesShort: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za']
        });
    });


    $('#slideselect').slideselect();
    // Fix IE6 rendering
    if ($.browser.msie && $.browser.version < 7)
        $('body').hide().show();

    $("#paginate").each(function(){
        itemsPerPage = 10;
        paginatorStyle = 1;
        paginatorPosition = 'bottom';
        enableGoToPage = false;
        showIfSinglePage = false;
        firstPageSymbol = "";
        lastPageSymbol = "";
        separator = "";
        previousPageSymbol = '<img src="/images/button_search_prev.gif" width="15" height="17" alt="Vorige">';
        nextPageSymbol = '<img src="/images/button_search_next.gif" width="15" height="17" alt="Volgende">';
        $(this).pagination();
    });
    
    $("#pressarchive").each(function(){
        $(this).show();
        itemsPerPage = 20;
        paginatorStyle = 1;
        paginatorPosition = 'bottom';
        enableGoToPage = false;
        showIfSinglePage = false;
        firstPageSymbol = "";
        lastPageSymbol = "";
        separator = "";
        previousPageSymbol = '<img src="/images/button_search_prev.gif" width="15" height="17" alt="Vorige">';
        nextPageSymbol = '<img src="/images/button_search_next.gif" width="15" height="17" alt="Volgende">';
        $(this).pagination();
    });

    var added = false;
    if ($('UL.agenda_listing li').size() == 4){
        $('UL.agenda_listing li.readmore').hide();
    } else {
        $('UL.agenda_listing li:gt(2)').each(function(){
            added = true;
            $(this).hide();
        });
        if (added){
            $('UL.agenda_listing li.readmore').each(function(){
                $(this).show();
                $(this).find('a').click(function(){
                    $('UL.agenda_listing li:gt(2)').each(function(){
                        $(this).show();
                    });
                    $('UL.agenda_listing li.readmore').hide();
                    return false;
                });
            });
        }
    }
});
    
function enable(_id, _boolean) {

    obj = $('#' + _id).get(0);
    obj.disabled = !_boolean;

    if (_boolean) {
        obj.focus();
    }
}

function textCounter(field, countfield,	maxlimit) {
    if (field.value.length > maxlimit) // if the current length is more than allowed
        field.value =field.value.substring(0, maxlimit); // don't allow further input
    else
        document.getElementById(countfield).innerHTML = maxlimit - field.value.length;
}


