
var active = false;

function clickAction(obj){

    if(active){
        restoreAction();
        active = false;
        return;
    }

    var db=document.body, dd=document.documentElement;

    offset = db.scrollTop + dd.scrollTop - 40;
    zoffset = 100 + offset;

    $('shutter').style.top = '0px';
    $('zoomer').style.top  = zoffset +'px';

    var zoom = new Image();
    zoom.src = obj.src;
    zoom.id = 'zoom_image';
    zoom.style.cursor = 'pointer';

    size = 500;

    if(zoom.height!=0){
        ratio = zoom.width / zoom.height;
        zoom.width = size;
        zoom.height = zoom.width / ratio;
        
        if(zoom.height > size){
            zoom.height = size;
            zoom.width = zoom.height*ratio;
        }
    }

    ml = -Math.round(zoom.width/2);
    zoom.style.marginLeft = ml+'px';

    zoom.onclick = function(){
        restoreAction();
    };

    $('zoomer').insert(zoom,{
        position: 'top'
    });

    active = true;
    $('shutter').appear({
        from: 0.0,
        to: 0.8
    });
    $('zoomer').appear({
        from: 0.0,
        to: 1.0
    });
}

function restoreAction(){
    try {
        $('zoomer').fade({
            from: 1.0,
            to: 0.0
        });
        $('shutter').fade({
            from: 0.8,
            to: 0.0
        });
        $('zoom_image').remove();
    }catch(e){

    }
}
