$(document).ready(function() {

    $("body").prepend("<div id='overlay' class='ebox_active' title='click to return'></div>");

    $("div#overlay").animate({
        opacity: 0
    },0);

    $("a.ebox_thumb").click(function(){
        var myThumb = $(this).children("img");
        var myImage = $(this).attr("href");
        
        var topDistance = $(window).scrollTop();
        
        thumbWidth = myThumb.width();
        thumbHeight = myThumb.height();
        var thumbX = myThumb.offset().left;
        var thumbY = myThumb.offset().top;
        var bigWidth = $(this).attr("rev");
        var bigHeight = $(this).attr("rel");
        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var docWidth = $(document).width();
        var docHeight = $(document).height();

 

        bigWidth *= 1;
        bigHeight *= 1;
        
        bigX = windowWidth - bigWidth;
        bigX /= 2;
        bigY = windowHeight - bigHeight;
        bigY /= 2;

        $("div#overlay").width(docWidth).height(docHeight).animate({
            opacity: .6
        });

        $("body").prepend("<img src='"+myImage+"' id='current_pic' class='ebox_active' title='click to return' />");
        $("img#current_pic").width(thumbWidth).height(thumbHeight).css({
            left: thumbX, top: thumbY
        }).animate({
            opacity: .01
        },0).bind('load', function(){

                $(this).animate({
                    width: bigWidth, height: bigHeight, left: bigX, top: bigY+topDistance, opacity: 1
                }, 'fast');
                
                $(".ebox_active").click(function(){
                    $("div#overlay").animate({
                        opacity: 0 
                    },'normal').width(1).height(1);
                    $("#current_pic").animate({ 
                        width: thumbWidth, height: thumbHeight, left: thumbX, top: thumbY, opacity: 'hide' 
                    },function(){$("#current_pic").remove();});

            });
        });
        
        return false;
    });
    
    
});

