var Popup = Class.create({
    initialize: function( strUrl, intWidth, intHeight, intLeft, intTop ) {
        this.close = this.close.bind(this);

        Utility.createOverlay();
        document.$overlay.setStyle({display: "block"});

        this.content = new Element("div").setStyle({
            position: 'absolute',
            width   : intWidth+'px',
            height  : intHeight+'px',
            left    : intLeft+'px',
            top     : intTop+'px',
            zIndex  : 10001
        });
        this.content.setAttribute('id', 'popup_content');
        $(document.body).insert(this.content);


        this.img = new Element("img", {src: Utility.strGfxPath+"cancel.png", alt: "X"}).setStyle({
            position: 'absolute',
            left    : intLeft+intWidth+'px',
            top     : intTop-7+'px',
            zIndex  : 10002
        });
        this.img.setAttribute('id', 'popup_image');
        this.img.observe('click', this.close);
        $(document.body).insert(this.img).observe('click', this.close);

        this.iframe = new Element("iframe", {border: 0, frameBorder: 0, src: strUrl}).setStyle({width: "100%", height:"100%"});
        this.iframe.setAttribute('id', 'popup_iframe');
        this.content.insert(this.iframe);
    },

    close: function() {
        this.iframe.remove();
        this.content.remove();
        this.img.remove();
        document.$overlay.setStyle({display: "none"});
        $(document.body).stopObserving('click', this.close);
        console.log('close');
    }
});

function popup( strUrl, intWidth, intHeight, intLeft, intTop ) {
    new Popup( strUrl, intWidth, intHeight, intLeft, intTop );
}

function close_popup() {
	if (
	 ! document.getElementById('popup_content') ||
	 ! document.getElementById('popup_image') ||
	 ! document.getElementById('popup_iframe') ||
	 ! document.$overlay
	) return false;
	document.getElementById('popup_content').style.display = 'none';
	document.getElementById('popup_image').style.display = 'none';
	document.getElementById('popup_iframe').style.display = 'none';
	document.$overlay.style.display = 'none';
}