test=$;
$(document).ready(function() {
    popup_activ=false;
    
    $=test;
   
    
    $('a[rel=popup]').each(function(){
        var me=$(this);
        me.attr('popup_href',me.attr('href'));
        me.removeAttr('href');
        me.css('cursor','pointer');
    });
    
    $('a[rel=popup]').click(function(){
        
        
        
        
        if(popup_activ == true) return false;
        popup_activ=true;
        var me=$(this);
        var img=$('<img />').attr('src',me.attr('popup_href'));
        var img_pre=$('<img style="z-index:0; width:1px;height:1px;"/>').attr('src',me.attr('popup_href'));
        $(img_pre).appendTo('body');
        var popup_div=$('<div style="z-index:99999;position:fixed;"/>').hide();
        var centerme=function(){
            var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
            var viewportWidth = window.innerWidth ? window.innerWidth : $(window).width();
            
            popup_div.css('left',(viewportWidth /2 - popup_div.width() /2 )+ 'px');
            popup_div.css('top', (50)+ 'px');
        }
        $(img).load(function(){
            centerme();
            popup_div.show();
            
            
        });
        popup_div.draggable();
        var button_div=$('<div style="text-align:right;padding:13px;"><span style="-moz-box-shadow: 2px 2px 8px #888;-webkit-box-shadow: 2px 2px 8px #888;box-shadow: 2px 2px 8px #888;margin-left:90px;cursor:pointer;background:none repeat scroll 0 0 #EEEEEE;border:1px solid #444444;font-weight:bold;padding:3px;text-align:center;">Schliessen</span></div>');
        button_div.appendTo(popup_div);
        button_div.click(function(){
            if(popup_activ == false) return false;
            popup_activ=false;
            $(this).parent().hide('scale',250,function(){$(this).remove();return true;});
            return true;
        });
        img.prependTo(popup_div);
        
        
        
        popup_div.appendTo($('body'));
    
        popup_div.css('left',(window.innerWidth /2 - popup_div.width() /2 )+ 'px');
        popup_div.css('top', (window.innerHeight/2 - popup_div.height()/2 -50)+ 'px');
        
        centerme();
        
        
        popup_div.show('scale',250);
        
        return false;
        
    });
});

