$(function() {
    $(':checkbox:checked').each(function(){
        $('label[for=' + $(this).attr('id') + ']').css('font-weight','bold');
    });
    
    $(':checkbox').live('click', function(){
        if($(this).is(':checked')){
            $('label[for=' + $(this).attr('id') + ']').css('font-weight','bold');
        }else{
            $('label[for=' + $(this).attr('id') + ']').css('font-weight','normal');
        }
    });
    
    $('div.search input').focusin(function(){
        if($(this).val() == 'Zoeken:'){
            $(this).val('');
        }
    }).focusout(function(){
        if($(this).val() == ''){
            $(this).val('Zoeken:');
        }
    });
    
    $('div.search form').submit(function(){
        $('div.main div.block:first').prepend('<div class="loading-overlay"><div class="loader">&nbsp;</div></div>');
        $('div.loading-overlay div.loader').css('margin-top', 300);
    });
    
    $('div.leesmeer').hide();
    
    $('a.leesmeer').live('click',function(e){
        e.preventDefault();
        $('div.leesmeer').toggle(); 
    });
    
    $('select#direct_link').live('change', function(){
        window.location = $(this).val(); 
    });
    
    $('select#direct_link').each(function(){
        $(this).selectmenu({style:'dropdown'});
    });
    
    $('.message-overlay').live('click', function(e){
        $('div.website-overlay').remove();
        e.preventDefault();
    });
    
    $("a[title=popup]").each(function(){
        var link = $(this).attr('href');
        $(this).attr('title','');
        if(strstr(link,'?')){
            var linktag = '&'
        }else{
            var linktag = '?'
        }
        $(this).attr('href', $(this).attr('href')  + linktag + 'popup').colorbox({innerWidth:850, innerHeight:700, iframe:true});
    });
});

function strstr( haystack, needle, bool ) { 
    var pos = 0;
 
    haystack += '';
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}
