// the jQuery-magic
jQuery(function($) {
    // top nav-bar
    var TimerTopNav;
    $(window).bind('scroll', function(){
        if ( $("#fancy_outer").css('display') == 'none' ) {
            if ( $(window).scrollTop() > 0 )  /* not on top */
                topnav_show();
            else  /* on top */
                topnav_hide();
        }
    });
    $('#topnav').hover(function(){   /* mouse over */
        clearTimeout(TimerTopNav);
        TimerTopNav = setTimeout( function(){
            topnav_show();
        }, 200 );
    }, function(){   /* mouse out */
        clearTimeout(TimerTopNav);
        TimerTopNav = setTimeout( function(){
            if ( $(window).scrollTop() == 0 || $("#fancy_outer").css('display') == 'block' )
                topnav_hide();
        }, 500 );
    });
    
    // author-images
    var TimerAuthorImage;
    $(".author-image.rolldown").hover(function(){   /* mouse over */
        var el = $(this);
        clearTimeout(TimerAuthorImage);
        TimerAuthorImage = setTimeout( function(){
            el.stop().animate({ height: '90px' }, 400);
        }, 500 );
    }, function(){   /* mouse out */
        var el = $(this);
        clearTimeout(TimerAuthorImage);
        TimerAuthorImage = setTimeout( function(){
            el.stop().animate({ height: '18px' }, 300);
        }, 500 );
    });
    
    // image licence
    $(".licence-included").hover(function(){   /* mouse over */
        $(this).children(".wp-image-wrapper").children(".licence-author").stop().animate({ opacity: 0.85 }, 300 );
    }, function(){   /* mouse out */
        $(this).children(".wp-image-wrapper").children(".licence-author").stop().animate({ opacity: 0 }, 200 );
    });
    
    // click on fancybox -> full screen
    $("#fancy_content").click(function(){
        window.location = $(this).children("img").attr("src");
    });
    
    // moretweets-questionmark
    $("#entry-social-moretweets").click(function(){
        $(".entry-social-topsy").fadeToggle( 200 );
    });
});

function topnav_hide( duration ) {
    jQuery('#topnav').stop().animate({ height: '9px' }, 200);
    jQuery('#topnav ul').stop().animate({ opacity: 0 }, 200, function(){
        jQuery(this).css('display', 'none');
    });
};
function topnav_show( ) {
    jQuery('#topnav').stop().animate({ height: '17px' }, 300);
    jQuery('#topnav ul').stop().delay(100).css('display', 'block').animate({ opacity: 1 }, 300 );
};

