$(document).ready( function() {
    /**
    * Externe links in nieuw venster
    */
    var hostname = document.location.hostname;
    var eimage = ' <img src="/images/elink.gif" alt="" />';
    $('a').each(function(){
    if (this.href && (this.hostname != hostname)
        && (this.protocol=='http:' || this.protocol=='https:')
        && (this.hostname != 'www.addthis.com')
        && (this.hostname != 'esarp.twokings.eu')
        && (this.hostname != 'nimd-esarp.org')
        && (this.hostname != 'yimd.org')
        && (this.hostname != 'ynimd.twokings.eu')
        
        ) {
      this.target="_blank";
      this.title = this.title + " This link will open in a new window.";
      //this.innerHTML = this.innerHTML+eimage;
    }
    });
    //console.log(jQuery.browser);
    if(jQuery.browser.flash == true) {
        $('#left #navmapholder').height('140px');
    }
    
    $('#textsize a').click(function() {
        size= $(this).attr('rel');
        //console.log(size);
        if(size == "large") {
            $('body').css('font-size','14px');
            $('#column_full').css('font-size','14px');
        }
        if(size == "small") {
            $('body').css('font-size','11px');
            $('#column_full').css('font-size','12px');
        }
        
        if(jQuery.cookie('positionx') != "") {
            jQuery("#sticker").attr('style','position: absolute; left: '+jQuery.cookie('positionx')+'px; top: '+jQuery.cookie('positiony')+'px; ');
        }
        jQuery.cookie('textsize', size, { path: '/', expires: 7 });
    });
    
    if(jQuery.cookie('textsize') != "") {
        size= jQuery.cookie('textsize');
        
        if(size == "large") {
            $('body').css('font-size','14px');
            $('#column_full').css('font-size','14px');
        }
        if(size == "small") {
            $('body').css('font-size','11px');
            $('#column_full').css('font-size','12px');
        }        
    }
    
  
    $('.moreinternallinks').toggle(
        function() {
            $(this).text('See less related resources');
            $(this).parent().find('div.entry_sidebar').show();
        },
        function() {
            $(this).text('See all related resources');
            $(this).parent().find('div.entry_sidebar').hide();
            $(this).parent().find('div#sidebar1, div#sidebar2, div#sidebar3').show();     
        }
    );


    //Menuopenklikbaarheid
    $('ul#menu li ul').hide();
    $('ul#menu li.active ul').show();
    $('ul#menu li.active ul li ul').hide();
    $('ul#menu li ul:has(a.active)').show();
    
    $('ul#menu li.active ul li:has(ul) a.parent').toggle(function() {
        $(this).parent().find('ul').show();
    },function() {
        $(this).parent().find('ul').hide();
    });
    

    //Foto's naast de nieuwsberichten tonen
    $('div#news div.entry').hover( function() {
        $(this).addClass('homenewsover');
        index= $('div#news div.entry').index(this);
        if($('#home_column_left img.frontpage_image:eq('+index+')').is('*')) {
            if(!$('#home_column_left img.frontpage_image:eq('+index+')').is(':visible')) {
                $('#home_column_left img.frontpage_image').fadeOut('slow');
                $('#home_column_left img.frontpage_image:eq('+index+')').fadeIn('slow');
            }
        }
    }, function() {
        $(this).removeClass('homenewsover');
    }
    );
    
        // checkbox om document aan archief te toe te voegen of te verwijderen
    $(".doclink a").tooltip({ 
    track: true, 
    delay: 0, 
    showURL: false, 
    extraClass: "right" 
    }); 

    beginimage= 1;
    eindimage= 9;
    aantalimages= $('#image_thumbs img:not(#prev):not(#next)').parent().length;
    $('#image_thumbs img:lt('+eindimage+'):not(#prev):not(#next)').parent().show();
    $('span.title_image').text($('span.thumbtitle:first').text());
    
    $('#next').click( function() {
        if(eindimage < aantalimages) {
            $('#image_thumbs img:eq('+beginimage+'):not(#prev):not(#next)').parent().hide();
            beginimage++;
            eindimage++;
            $('#image_thumbs img:eq('+eindimage+'):not(#prev):not(#next)').parent().show();
        }
    });
    
    $('#prev').click( function() {
        if(beginimage > 1) {
            beginimage--;
            $('#image_thumbs img:eq('+beginimage+'):not(#prev):not(#next)').parent().show();
            $('#image_thumbs img:eq('+eindimage+'):not(#prev):not(#next)').parent().hide();
            eindimage--;
        }
    });
    
    $('#image_thumbs img:not(#prev):not(#next)').click(function() {
        src= $(this).attr('src');
        src= src.replace("w=45", "w=540");
        src= src.replace("h=30", "h=326");
        $('img.main_image').attr('src',src);
        $('p.image_info').html($(this).parent().find('span.thumbdescription').html());
        //$('span.title_image').text($(this).parent().find('span.thumbtitle').text());
    });

    $('#land_image span').text($('#land_image img').attr('alt'));
    $('#land_thumbs img').click(function() {
        src= $(this).attr('src');
        //console.log(src);
        src= src.replace("w=26", "w=165");
        src= src.replace("h=22", "h=150");

        $('#land_image img').attr('src',src);
        $('#land_image span').text($(this).attr('alt'));
    });
    
    
    $('.minithumbs img').click(function() {
        src= $(this).attr('src');
        //console.log(src);
        src= src.replace("w=30", "w=270");
        src= src.replace("h=30", "");

        $('img.bigthumb').attr('src',src);
    });
    
    $('#land_right h3').not('#programme_moreinfoheader').not('.feedtitle').css('background-image','url(/images/arrow_dark.gif)');
    $('#land_right h3').not('#programme_moreinfoheader').not('.feedtitle').next('p').hide();
    
    $('#land_right h3').not('#programme_moreinfoheader').not('.feedtitle').toggle(function() {
        $(this).next('p').slideDown('slow');
        $(this).css('background-image','url(/images/arrow_dark_down.gif)');
    }, function() {
        $(this).next('p').slideUp('slow');
        $(this).css('background-image','url(/images/arrow_dark.gif)');
    });
    
    $('#getembedcode').toggle(function() {
        $('#embedcode').slideDown('slow');
    }, function() {
        $('#embedcode').slideUp('slow');
    });
    
    
});

if (!window.console || !console.firebug) {  
  var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",  
  "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];  
  
  window.console = {};  
  for (var i = 0; i < names.length; ++i)  
    window.console[names[i]] = function() {}  
} 
