var shadowStr = '<div class="wrap0"><div class="wrap1"><div class="wrap2"><div class="wrap3"></div></div></div></div>';
var popupLink = {
    links: false,
    popUpBox: false,
    init: function()
    {
        popupLink.links = $('ul.thumbs li a');
        $.each(popupLink.links, function(){
            this.onclick = function(){
                if($('#popup'))
                {
                    $('#popup').remove();
                }
                popupLink.buildPopup($(this).find('img'));
                return false;
            }
        })
    },
    buildPopup: function(obj)
    {
        var preImage = new Image();

        $('#main').prepend('<div id="popup"><p><a href="#">Close</a></p><img src="" alt=""></div>');

        preImage.onload = function()
        {
            popupLink.popUpBox = $('#popup');
            popupLink.popUpBox.width(parseInt(preImage.width + 32) + 'px');
            popupLink.popUpBox.height(parseInt(preImage.height + 16) + 'px');
            var image = $('#popup img');
            var src = obj.src();
            image.css('visibility','visible');
            image.fadeIn('slow');
            $('#popup p a').bind('click', function(){
                $('#popup').remove();
            });
            image.src(obj.src().replace('tb_', ''));
        }
        preImage.src = obj.src().replace('tb_', '');
    }
};

$(document).ready(function(){
        $('.shadow').wrap(shadowStr);
        popupLink.init();
    }
);