/*
   eg.js
   http://github.com/enure/gallery/tree/master

   requires jquery, http://jquery.com/.
   
   these effects are not necessary.
   they provide slight usablity enhancements.
*/

$(document).ready(function() {
    /*
     * Indicates that one can click the left of right side of the photo to
     * navigate by highlighting the relevant arrow.
     */
    $('#eg-back').hover(function() {
        $('#eg-link_back').addClass('eg-hover');
    },function(){
        $('#eg-link_back').removeClass('eg-hover');
    });
    
    $('#eg-forward').hover(function() {
        $('#eg-link_forward').addClass('eg-hover');
    },function(){
        $('#eg-link_forward').removeClass('eg-hover');
    });

    /*
     * Indicates that one can click the left of right side of the photo to
     * navigate by prensenting a message on the first photo of a collection.
     * Fades out after 6 seconds.
     */
    if (!window.location.search) {
        $('body#eg').append('<p id="eg-navHelp" class="eg">Navigate with the arrow keys, or click the right or left side of the photo.</p>');
        $('p#eg-navHelp').fadeIn('slow');
        setTimeout(function() {
            $('p#eg-navHelp').fadeOut('slow');
        }, 6000);
        setTimeout(function() {
            $('p#eg-navHelp').remove();
        }, 6100);
    }

    /*
     * Provides keyboard navigation
     * Code taken from: http://plugins.jquery.com/project/keynav/
     */
    $(document).keydown(function(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 37) location.href=$('#eg-back').attr('href');
        if (key == 38) location.href=$('#eg-link_home').attr('href');
        if (key == 39) location.href=$('#eg-forward').attr('href');
    });


});