var searchTimeouthome = '0';
var q = "";
$(window).load(function(){
    $('.subdomainLargeImage').each(function(index) {
        img =$(this).attr("src");
        id = $(this).attr("id");
        checkImage( img, id); 
             
    });
});


$(function(){
   
    $("#leftMenu li").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
    $("#rightMenu li").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
        
    $("._blank").attr("target","_blank");
    $(".lightBox").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600, 
        'speedOut'		:	200, 
        'overlayShow'	:	true,
        'titleShow'                    :                 true,
        'titlePosition'                :                 'over'
    });
    
 
    
    $("#searchQ").attr("autocomplete","off");
    $("#searchQ").keyup( function(){
        if( searchTimeouthome != '0'){
            clearTimeout( searchTimeouthome );
        }
        searchTimeouthome = setTimeout("homeSearch()", 100);
    });
    
    $(".scrollableImages").scrollable();
    
    $(".newsItemClick").click(function(){
        $( $(this).attr("href") ).slideToggle(800);
        return false;
    });
    
    /*
    var cont_left = $(".items").position().left;
        $(".items img").hover(function() {
            // hover in
            width = $(this).width();
            height = $(this).height();
            $(this).parent().parent().parent().parent().css("height","400px").css("line-height","400px");
            $(this).parent().parent().parent()
           
           
             .css("height","350px")
             .css("width","350px");
            
            $(this).animate({
               height: "350",
               width: "350",
             
              
            }, "1");
        }, function() {
            // hover out
            $(this).parent().parent().parent().css("z-index", 0)
            .css("position","relative")
           
            .css("height","")
             .css("width","");;
            $(this).animate({
                height: height,
                width: width,
                
            }, "1");
        });
        
        $(".items im").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
        */
    
    //blokkeer selectie en rechtermuis
   // $('body').disableTextSelect();
   // $(document)[0].oncontextmenu = function() {return false;}    
    //
   
    leftMenuLoadNews();



   
});

var delay = (function(){
    var timer = 0;
    return function(callback, ms){
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();

function checkImage( img, id )
{
    if( $("#"+id).width() < 50 ){
       $("#wrap_"+id).hide();
    }
    else{
        $("#wrap_"+id).fadeIn();
    }
    
}

function global_show_loading( id )
{
    $("#"+id).html("<img src='/media/images/icons/loading.gif' alt='Please wait...'/>");
}
function global_hide_loading( id )
{
    $("#"+id).html("&nbsp;");
}

function leftMenuLoadNews()
{
    return true;
}

var keyNav = '0';
function homeSearch()
{
    q = $("#searchQ").val();    
    if( q.length > 0)
    {
        $.post("/search/ajax/?q="+q, function( data ){
            $("#homeSearchResults").html( data );
            $("#homeSearchResults").show();
            if( keyNav != '0')
            {
                $.keynav.reset();
                $.keynav.currentEl = 0;
            }
            keyNav = $('#homeSearchResults a').keynav('keynav_focusbox','keynav_box');
                    
                   
        });
    }
    else
    {
        $("#homeSearchResults").html( "" );
        $("#homeSearchResults").hide();
    }
}

