var preview=null;
var cover=null;
var serial=null;

window.addEvent("domready", function(){
    $$("a.imagelink").each(function(element){
        element.onclick=function(){
            preview=new Element("img");
            cover=new Element("div");
            serial=new Element("h1");
            preview.setStyles({
                position:"absolute",
                left:"50%",
                marginLeft:"-200px",
                top:window.getHeight()/2+document.documentElement.scrollTop-200,
                opacity:0,
                border:"solid 2px #333"
            });
            cover.setStyles({
                position:"absolute",
                left:0,
                top:0,
                opacity:0,
                backgroundColor:"#FFFFFF",
                width:"100%",
                height:window.getScrollHeight()
            });
            serial.setStyles({
                position:"absolute",
                width:"100%",
                textAlign:"center",
                color:"#000",
                opacity:0,
                top:window.getHeight()/2+document.documentElement.scrollTop+190,
            });
            serial.innerHTML=this.id;

            cover.injectInside(document.body);
            new Fx.Styles(cover).start({
                opacity:[0,.8]
            });
            serial.injectInside(document.body);
            preview.fader=new Fx.Styles(preview);
            preview.onload=function(){
                new Fx.Styles(serial).start({
                    opacity:[0, 1]
                });
                this.fader.start({
                    opacity:[0,1]
                });
            }
            preview.src=this.href;
            preview.injectInside(document.body);
            preview.onclick=function(){
                preview.remove();
                preview=null;
                cover.remove();
                cover=null;
                serial.remove();
                serial=null;
            }
            cover.onclick=function(){
                preview.remove();
                preview=null;
                cover.remove();
                cover=null;
                serial.remove();
                serial=null;
            }
            return false;
        }
    });
});