function openLightpopup() {
    lightpopup.open(this.href, this.innerHTML);
    return false;
}

lightpopup = {
    _mask: null,
    _loader: null,
    _container: null,
    _titlebar: null,
    _isVisible: false,
    _closebutton: null,
    _init: function() {
        if(this._mask != null)return;
        this._mask = document.createElement('div');
        this._loader = document.createElement('iframe');
        this._container = document.createElement('div');
        this._closebutton = document.createElement('div');
        this._titlebar = document.createElement('div');
        $(this._mask).hide()
            .css('background-color', 'black')
            .css('z-index', '9999')
            .css('position', 'fixed')
            .css('right', '0')
            .css('left', '0')
            .css('top', '0')
            .css('bottom', '0');
        $(this._container).hide()
            .css('position', 'fixed')
            .css('top', '50%')
            .css('left', '50%')
            .css('width', '700px')
            .css('height', '524px')
            .css('margin-left', '-350px')
            .css('margin-top', '-262px')
            .css('z-index', '10000');
        $(this._closebutton)
            .css('float', 'right')
            .css('cursor', 'pointer')
            .addClass('lightpopup_close')
            .click(function() {lightpopup._setVisible(false);});
        $(this._titlebar)
            .css('height', '24px')
            .css('font-size', '20px')
            .css('color', 'white')
            .html('<span></span>')
            .append(this._closebutton);
        $(this._loader)
            .css('height', '500px')
            .css('width', '100%')
            .css('border', 'none')
            .css('background-color', 'white');

        $('body')
            .append(this._mask)
            .append(this._container);
        $(this._container)
            .append(this._titlebar)
            .append(this._loader);
    },
    open: function(url, title) {
        this._init();
        this._setVisible(true);
        this._loader.src = url;
        $('span', this._titlebar)
            .html(title);
    },
    _setVisible: function(visible) {
        if(visible && !this._isVisible) {
            $(this._mask).fadeTo(200, 0.95, function() {lightpopup._onVisibilityChanged(true);})
        }else if(!visible && this._isVisible) {
            $(this._container).hide();
            $(this._mask).fadeTo(200, 0, function() {lightpopup._onVisibilityChanged(false);})
        }
    },
    _onVisibilityChanged: function(newVisibility) {
        this._isVisible = newVisibility;
        if(!this._isVisible) {
            $(this._mask).hide();
        } else {
            $(this._container).show();
        }
    }
};
