/**include
//_javascript/js-wrapper.js;
//_javascript/debug.js;
*/
/**
 * Class constructor
 * Initialisation of object is done by constructor
 */
var dinamic_popup_link = newClass({
    linkClass : null,
    links    : null,
    inProgress : false,

    winWr    : null,
    popWinWr : null,

    init : function(linkClass, newConf)
    {
        this.linkClass = linkClass;
        
        if (isDefined(newConf)) {
            var conf  = this.config;
            for (var k in newConf) {
                if (isDefined(conf, k)) {
                    conf[k] = newConf[k];
                }
            }
        }
    },
    onready : function(evtWr)
    {
        var aLst = this.$$("a." + this.linkClass);
        if (aLst) {
            aLst.addListener(this, "onclick", "onClickTag");
        }
        this.$w0.setOnUnload(this, "onUnloadMain");
    },

    onClickTag : function(evtWr)
    {
        var conf, url, loc, pw, pr, scr, x, y;
        evtWr.eventDrop();
        evtWr.elmWr.elm.blur();
        if (this.inProgress) {
            return;
        }

        url = evtWr.elmWr.elm.getAttribute("href");
        if (!/^https?\:\/\//.exec(url)) {
            loc = this.$w0.win.location;
            url = loc.protocol + "//" + loc.host + url;
        }

        if (this.popWinWr && this.popWinWr.win) {
            try {
                if (this.bv.isOpera) {
                    this.popWinWr.win.close();
                } else {
                    pw = this.popWinWr.win;
                    pw.focus();
                    if (pw.location.href != url) {
                        this.popWinWr.delOnUnload(this, "onUnloadPopUp");
                        this.popWinWr.createStyle("body *", "display:none;");
                        pw.location.href = url;
                    }
                    return;
                }
            } catch (e) {}
        }
        this.popWinWr = null;
        
        conf = this.config;
        this.inProgress = true;
        this.setTimeout(conf.resTime, this, "resetProgress");
        
		scr = this.winWr.win.screen;
		x = (scr.availWidth - conf.popupWidth)/2;
		y = (scr.availHeight - conf.popupHeight)/2;
		pr  = "width=" + conf.popupWidth + ",height=" + conf.popupHeight;
		pr += ",screenX=" + x + ",screenY=" + y;
		pr += ",left=" + x + ",top=" + y;
		pr += "," + conf.popupAddProp;
		this.openPopUp(this, "onreadyPopUp", url, conf.popupName + this.linkClass, pr);
    },

    resetProgress : function()
    {
        this.inProgress = false;
    },

    relocatePopUp : function(pw, url)
    {
        pw.location.replace(url);
    },

    onreadyPopUp : function(evtWr)
    {
        this.popWinWr = evtWr.winWr;
        this.popWinWr.win.focus();
        this.popWinWr.setOnUnload(this, "onUnloadPopUp");
        this.resetProgress();
    },

    onUnloadMain : function(evtWr)
    {
        if (this.popWinWr){
            this.popWinWr.win.close();
        }
    },

    onUnloadPopUp : function(evtWr)
    {
        this.popWinWr = null;
    },

    config : {
        "popupName"    : "dinamicPopup_",
        "resTime"      : 8000,
        "popupWidth"   : 650,
        "popupHeight"  : 420,
        "popupAddProp" : "status=no,resizable=yes"
    }

});