(function (WIN) {
    var RPXNOW = {};
    if ((typeof WIN.RPXNOW !== "undefined") && WIN.RPXNOW) {
        RPXNOW = WIN.RPXNOW
    }
    var DOC = WIN.document;
    var ACTIVEX = typeof WIN.ActiveXObject !== "undefined";
    var QUIRKS_MODE = DOC.compatMode != "CSS1Compat";
    var IE6 = (function () {
        var ua = WIN.navigator && WIN.navigator.userAgent;
        var m = ua.match(/MSIE\s([^;]*)/);
        if (m && m[1]) {
            var c = 0;
            return (6 == parseFloat(m[1].replace(/\./g, function () {
                return (c++==1) ? "" : "."
            })))
        } else {
            return false
        }
    })();
    var MOBILE = (function () {
        var mobile_devices = new RegExp("iphone|ipod|android|palm|blackberry|windows ce");
        var ua = "";
        try {
            ua = WIN.navigator.userAgent.toLowerCase()
        } catch(e) {}
        return ua.search(mobile_devices) != -1
    })();
    var SECURE = DOC.location.protocol === "https:";
    var SCHEME = WIN.location.protocol.replace(/[:]$/, "");
    var CDN_BASE = (SECURE ? "https://s3.amazonaws.com/static.rpxnow.com" : "http://cdn.rpxnow.com");
    RPXNOW.DEFAULT_BASE_URL = SCHEME + "://rpxnow.com/";
    var IMAGES = {
        bg_fade: ["bg_fade.png/0e76716712c714a189c0a07b33fda23e.png", "bg_fade_ie.png/08edc5705c9b61ecd20b6903b5830a1d.png"],
        bg_auth: ["bg_auth.png/072e699dadea176ace38e1f39c8b1c6f.png", "bg_auth.gif/59b67dc6128043d53a89808c2e08678a.gif"],
        lb_close: ["close.png/94726c11718cedfae4b35ca5dfcf8971.png", "close_ie.png/6e03cf22aa59b4844d0b78df3bc6787d.png"],
        lb_corners: ["corners.png/47464b01c238fc81a5a537859e37e930.png", "corners.gif/a5384cf51db4d3e85f3c4f95c546a9c5.gif"],
        lb_border: ["border.png/01c40882d59520662e8cebae63d73a2c.png", "border.gif/a7f3bf49b8e1d17d66a870e5b7d3b2b9.gif"],
        auth_background: ["background.png/ce2da388a4e0fa1ef809b2c4cc4d5139.png", "background.png/ce2da388a4e0fa1ef809b2c4cc4d5139.png"]
    };
    var LOADING_STRINGS = {
        hu: "Bet\u00f6lt\u00e9s",
        zh: "\u8f7d\u5165\u4e2d",
        en: "Loading",
        ro: "\u00cenc\u0103rcare",
        ru: "\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430",
        "sv-SE": "Laddar",
        cs: "Na\u010d\u00edt\u00e1n\u00ed",
        hr: "U\u010ditavanje",
        ja: "\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059",
        sr: "U\u010ditavam",
        ko: "\ub85c\ub529",
        "pt-BR": "Carregando",
        es: "Cargando",
        it: "Caricamento",
        "zh-CHT": "\u8f09\u5165\u4e2d",
        el: "loading",
        et: "Laetakse",
        fr: "Chargement",
        nl: "Laden",
        pl: "Loading",
        da: "Indl\u00e6ser",
        no: "Laster",
        vi: "\u0110ang t\u1ea3i",
        bg: "\u0417\u0430\u0440\u0435\u0436\u0434\u0430\u043d\u0435",
        fi: "Ladataan",
        de: "Lade",
        pt: "Carregando"
    };
    var COMMON_UI_PARAMS = ["token_url", "language_preference", "user_identifier", "flags", "default_provider", "email", "openid_proxy_url"];
    var cx = new RegExp("[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]", "g");
    var escapable = new RegExp('[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]', "g");
    var REGEXP_SPECIAL = ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\"];
    var REGEXP_ESCAPE_RE = new RegExp("(\\" + REGEXP_SPECIAL.join("|\\") + ")", "g");
    var ABSOLUTE_URL_RE = new RegExp("^https?://([a-z0-9]([\\-a-z0-9]*[a-z0-9])?\\.)*[a-z0-9]([\\-a-z0-9]*[a-z0-9])?(:[0-9]+)?(/[^?#]*(\\?[^#]*)?)?$", "i");
    var ABSOLUTE_URL_FRAG_RE = new RegExp("^https?://([a-z0-9]([\\-a-z0-9]*[a-z0-9])?\\.)*[a-z0-9]([\\-a-z0-9]*[a-z0-9])?(:[0-9]+)?(/[^?#]*(\\?[^#]*)?)?(#.*)?$", "i");
    var ABSOLUTE_PATH_RE = new RegExp("^/[^?#]*(\\?[^#]*)?$");
    var qbody = function () {
        return QUIRKS_MODE ? DOC.body : DOC.documentElement
    };
    var socialImageURL = function (name) {
        var path = IMAGES[name][IE6 ? 1 : 0];
        return CDN_BASE + "/images/" + path
    };
    var socialImageCSS = function (name) {
        return "url('" + socialImageURL(name) + "')"
    };
    var Util = {
        _hiddenDiv: null,
        getHiddenDiv: function () {
            var div = this._hiddenDiv;
            if (!div) {
                div = DOC.createElement("div");
                div.setAttribute("id", "FB_HiddenContainer");
                div.style.position = "absolute";
                div.style.top = "-10000px";
                div.style.left = "-10000px";
                div.style.width = "0px";
                div.style.height = "0px";
                DOC.body.insertBefore(div, DOC.body.firstChild);
                this._hiddenDiv = div
            }
            return div
        },
        addListener: function (name, elem, listener) {
            if (ACTIVEX) {
                elem.attachEvent("on" + name, listener)
            } else {
                elem.addEventListener(name, listener, false)
            }
        },
        addClickListener: function (elem, listener) {
            this.addListener("click", elem, listener)
        },
        bind: function (obj, fname) {
            return function () {
                obj[fname].apply(obj, arguments)
            }
        },
        isArray: function (obj) {
            return (Object.prototype.toString.apply(obj) === "[object Array]")
        },
        isBoolean: function (obj) {
            return (typeof obj === "boolean")
        },
        isFunction: function (obj) {
            return Object.prototype.toString.apply(obj) === "[object Function]"
        },
        isNull: function (obj) {
            return obj === null
        },
        isNumber: function (obj) {
            return typeof obj === "number" && isFinite(obj)
        },
        isObject: function (obj) {
            return (obj && (typeof obj === "object" || this.isFunction(obj))) || false
        },
        isString: function (obj) {
            return typeof obj === "string"
        },
        isUndefined: function (obj) {
            return typeof obj === "undefined"
        },
        indexOf: function (arr, val) {
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == val) {
                    return i
                }
            }
            return -1
        },
        log: function (msg) {
            if (WIN.console) {
                WIN.console.log("RPXNow: " + msg)
            }
        },
        getViewportHeight: function () {
            if (Util.isNumber(WIN.innerHeight)) {
                return WIN.innerHeight
            } else {
                return qbody().clientHeight
            }
        },
        getViewportWidth: function () {
            if (Util.isNumber(WIN.innerWidth)) {
                return WIN.innerWidth
            } else {
                return qbody().clientWidth
            }
        },
        getDocumentHeight: function () {
            return Math.max(qbody().scrollHeight, Util.getViewportHeight())
        },
        getDocumentWidth: function () {
            return Math.max(qbody().scrollWidth, Util.getViewportWidth())
        },
        parseQueryString: function (url_str) {
            var match = null;
            var result = {};
            var query_str = url_str.match(/^[^?]*(?:\?([^#]*))?(?:$|#.*$)/)[1];
            var _query_regex = new RegExp("([^=]+)=([^&]*)&?", "g");
            while (!this.isNull(match = _query_regex.exec(query_str))) {
                (result[decodeURIComponent(match[1])] = decodeURIComponent(match[2]))
            }
            return result
        },
        regexpEscape: function (text) {
            return text.replace(REGEXP_ESCAPE_RE, "\\$1")
        },
        toJSON: function (value) {
            return Util._toJSON("", {
                "": value
            })
        },
        _toJSON: function (key, holder) {
            var meta = {
                "\b": "\\b",
                "\t": "\\t",
                "\n": "\\n",
                "\f": "\\f",
                "\r": "\\r",
                '"': '\\"',
                "\\": "\\\\"
            };
            var quote = function (string) {
                escapable.lastIndex = 0;
                return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
                    var c = meta[a];
                    return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
                }) + '"' : '"' + string + '"'
            };
            var i, k, v, length, partial, value = holder[key];
            switch (typeof value) {
            case "string":
                return quote(value);
            case "number":
                return isFinite(value) ? String(value) : "null";
            case "boolean":
            case "null":
                return String(value);
            case "object":
                if (!value) {
                    return "null"
                }
                partial = [];
                if (Object.prototype.toString.apply(value) === "[object Array]") {
                    length = value.length;
                    for (i = 0; i < length; i += 1) {
                        partial[i] = Util._toJSON(i, value) || "null"
                    }
                    v = partial.length === 0 ? "[]" : "[" + partial.join(",") + "]";
                    return v
                }
                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = Util._toJSON(k, value);
                        if (v) {
                            partial.push(quote(k) + ":" + v)
                        }
                    }
                }
                v = partial.length === 0 ? "{}" : "{" + partial.join(",") + "}";
                return v
            }
            throw new Error("What happened?.")
        },
        parseJSON: function (text, reviver) {
            var j;
            var walk = function (holder, key) {
                var k, v, value = holder[key];
                if (value && typeof value === "object") {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v
                            } else {
                                delete value[k]
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value)
            };
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
                })
            }
            var areg = new RegExp("^[\\],:{}\\s]*$");
            var breg = new RegExp('\\\\(?:["\\\\\\/bfnrt]|u[0-9a-fA-F]{4})', "g");
            var creg = new RegExp('"[^"\\\\\\n\\r]*"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?', "g");
            var dreg = new RegExp("(?:^|:|,)(?:\\s*\\[)+", "g");
            if (areg.test(text.replace(breg, "@").replace(creg, "]").replace(dreg, ""))) {
                j = eval("(" + text + ")");
                return typeof reviver === "function" ? walk({
                    "": j
                }, "") : j
            }
            throw new SyntaxError("JSON.parse: " + text)
        }
    };
    Util.XHR = {
        fetch: function (url, callbacks) {
            var req = this._newRequest();
            req.onreadystatechange = function () {
                if (req.readyState != 4) {
                    return
                }
                switch (req.status) {
                case 200:
                case 304:
                    callbacks.success(req.responseText);
                    return;
                case -1:
                    return;
                default:
                    break
                }
                callbacks.failure(req.status, req.statusText, req.responseText)
            };
            req.open("GET", url, true);
            req.send(null)
        },
        _newRequest: function () {
            if (Util.isUndefined(WIN.XMLHttpRequest)) {
                try {
                    return new WIN.ActiveXObject("Msxml2.XMLHTTP.6.0")
                } catch(e1) {}
                try {
                    return new WIN.ActiveXObject("Msxml2.XMLHTTP.3.0")
                } catch(e2) {}
                try {
                    return new WIN.ActiveXObject("Msxml2.XMLHTTP")
                } catch(e3) {}
                try {
                    return new WIN.ActiveXObject("Microsoft.XMLHTTP")
                } catch(e4) {}
                throw new Error("This browser does not support XMLHttpRequest.")
            } else {
                return new WIN.XMLHttpRequest()
            }
        }
    };
    Util.Cookies = {
        _cached: null,
        get: function (name) {
            return this._parsedCookies()[name]
        },
        remove: function (name, options) {
            options = options || {};
            options.expires = new Date(0);
            return this.set(name, "", options)
        },
        set: function (name, value, options) {
            var text = (encodeURIComponent(name) + "=" + encodeURIComponent(value));
            if (Util.isObject(options)) {
                if (options.expires instanceof Date) {
                    text += "; expires=" + options.expires.toGMTString()
                }
                if ((options.path) && options.path !== "") {
                    text += "; path=" + options.path
                }
                if (Util.isString(options.domain) && options.domain !== "") {
                    text += "; domain=" + options.domain
                }
                if (options.secure === true) {
                    text += "; secure"
                }
            }
            DOC.cookie = text;
            return text
        },
        _parsedCookies: function () {
            if (Util.isNull(this._cached)) {
                var results = this._cached = {};
                var text = DOC.cookie;
                if (/[^=]+=[^=;]?(?:; [^=]+=[^=]?)?/.test(text)) {
                    var parts = text.split(/;\s/g),
                        name = null,
                        value = null,
                        match = null,
                        part = null;
                    for (var i = 0, len = parts.length; i < len; i++) {
                        part = parts[i];
                        match = part.match(/([^=]+)=(.*)/i);
                        if (match instanceof Array) {
                            try {
                                name = decodeURIComponent(match[1].replace(/\+/g, " "));
                                value = decodeURIComponent(match[2].replace(/\+/g, " "));
                                results[name] = value
                            } catch(e) {}
                        }
                    }
                }
            }
            return this._cached
        }
    };
    Util.QueryBuilder = function (dict) {
        var key;
        this.pairs = [];
        if (dict && typeof dict == "object") {
            for (key in dict) {
                if (dict.hasOwnProperty(key)) {
                    this.add(key, dict[key])
                }
            }
        }
    };
    Util.QueryBuilder.prototype = {
        add: function (key, value) {
            var enc = encodeURIComponent;
            if (!Util.isUndefined(value) && !Util.isNull(value)) {
                this.pairs.push([enc(key), enc(value)].join("="))
            }
        },
        toString: function () {
            return this.pairs.join("&")
        }
    };
    Util.HiddenForm = function (action, prepop) {
        this.formElem = DOC.createElement("form");
        this.submitElem = DOC.createElement("input");
        this.submitElem.setAttribute("type", "submit");
        this.formElem.appendChild(this.submitElem);
        var hiddenElem = Util.getHiddenDiv();
        hiddenElem.appendChild(this.formElem);
        this.inputElems = {};
        if (action) {
            this.setAction(action)
        }
        if (prepop && prepop instanceof Object) {
            var key;
            for (key in prepop) {
                if (prepop.hasOwnProperty(key)) {
                    this.setHidden(key, prepop[key])
                }
            }
        }
    };
    Util.HiddenForm.prototype = {
        setAction: function (url) {
            this.formElem.setAttribute("action", url)
        },
        setMethod: function (method) {
            this.formElem.setAttribute("method", method)
        },
        setTarget: function (name) {
            this.formElem.setAttribute("target", name)
        },
        setHidden: function (name, value) {
            if (Util.isNull(value)) {
                this.deleteHidden(name);
                return
            }
            var inputElem = this.inputElems[name];
            if (!inputElem) {
                inputElem = this.inputElems[name] = DOC.createElement("input");
                inputElem.setAttribute("type", "hidden");
                inputElem.setAttribute("name", name);
                this.formElem.appendChild(inputElem)
            }
            inputElem.setAttribute("value", value)
        },
        deleteHidden: function (name) {
            var inputElem = this.inputElems[name];
            if (inputElem) {
                this.formElem.removeChild(inputElem);
                this.inputElems.slice(Util.indexOf(this.inputElems, inputElem), 1)
            }
        },
        submit: function () {
            this.submitElem.click()
        },
        submitTo: function (w) {
            this.setTarget(w.getName());
            this.submit()
        }
    };
    Util.HiddenIframe = function () {
        var div = DOC.createElement("div");
        this.name = "rpx_auth_" + (new Date()).getTime();
        var hiddenElem = Util.getHiddenDiv();
        hiddenElem.appendChild(div);
        var src = IE6 ? RPXNOW.config.baseUrl + "blank.html" : "";
        div.innerHTML = ('<iframe src="' + src + '" name="' + this.name + '" id="' + this.name + '"></iframe>');
        this.iframeElem = DOC.getElementById(this.name);
        if (ACTIVEX) {
            WIN.frames[this.name].name = this.name
        }
    };
    Util.HiddenIframe.prototype = {
        getName: function () {
            return this.name
        },
        setSrc: function (src) {
            this.iframeElem.setAttribute("src", src)
        },
        addOnloadListener: function (cb) {
            var ifrm = this.iframeElem;
            if (ACTIVEX) {
                ifrm.onreadystatechange = function () {
                    if (ifrm.readyState === "complete") {
                        cb()
                    }
                }
            } else {
                ifrm.addEventListener("load", cb, false)
            }
        }
    };
    Util.PopupWindow = function (width, height, name) {
        this.width = width;
        this.height = height;
        this.window = null;
        this.name = "rpx_window_" + RPXNOW.config.appId + "_";
        if (Util.isUndefined(name)) {
            this.name += (new Date()).getTime()
        } else {
            this.name += name
        }
        this.closeListeners = []
    };
    Util.PopupWindow.prototype = {
        show: function (url) {
            if (!this.window) {
                var coords = this._getCenteredCoords();
                this.window = WIN.open(url || "", this.name, "width=" + this.width + ",height=" + this.height + ",status=1,location=1,resizable=yes,left=" + coords[0] + ",top=" + coords[1]);
                var that = this;
                var ii = WIN.setInterval(function () {
                    if (that.window.closed) {
                        WIN.clearInterval(ii);
                        that._onClose()
                    }
                }, 500)
            }
        },
        setLocation: function (url) {
            if (this.window) {
                this.window.location.href = url
            }
        },
        setSize: function (width, height) {
            this.width = width;
            this.height = height;
            if (this.window) {
                this.window.outerWidth = width;
                this.window.outerHeight = height
            }
        },
        close: function () {
            if (this.window) {
                this.window.close()
            }
        },
        addCloseListener: function (listener) {
            this.closeListeners.push(listener)
        },
        removeCloseListener: function (listener) {
            this.closeListeners.splice(Util.indexOf(this.closeListeners, listener), 1)
        },
        getName: function () {
            return this.name
        },
        focus: function () {
            this.window.focus()
        },
        _getCenteredCoords: function () {
            var xPos = null;
            var yPos = null;
            if (ACTIVEX) {
                xPos = WIN.event.screenX - (this.width / 2) + 100;
                yPos = WIN.event.screenY - (this.height / 2) - 100
            } else {
                var parentSize = [WIN.outerWidth, WIN.outerHeight];
                var parentPos = [WIN.screenX, WIN.screenY];
                xPos = parentPos[0] + Math.max(0, Math.floor((parentSize[0] - this.width) / 2));
                yPos = WIN.screenY + 15
            }
            return [xPos, yPos]
        },
        _onClose: function () {
            var i, listener;
            for (i = 0; i < this.closeListeners.length; i++) {
                listener = this.closeListeners[i];
                listener()
            }
        }
    };
    Util.LightBox = function (contents, width, height) {
        var transElem = DOC.createElement("div");
        transElem.className = "rpxnow_lightbox_trans";
        var transStyle = transElem.style;
        transStyle.backgroundColor = "black";
        if (ACTIVEX) {
            transStyle.filter = "alpha(opacity=40)"
        } else {
            transStyle.opacity = transStyle.KhtmlOpacity = transStyle.MozOpacity = "0.4"
        }
        transStyle.position = "absolute";
        transStyle.top = transStyle.left = "0";
        transStyle.width = transStyle.height = "100%";
        var closeImg = DOC.createElement("img");
        closeImg.src = socialImageURL("lb_close");
        closeImg.alt = "close";
        var closeStyle = closeImg.style;
        closeStyle.position = "absolute";
        closeStyle.top = closeStyle.right = "-4px";
        closeStyle.cursor = "pointer";
        closeStyle.width = closeStyle.height = "34px";
        this.containerElem = DOC.createElement("div");
        this.containerElem.className = "rpxnow_lightbox_container";
        var containerStyle = this.containerElem.style;
        containerStyle.position = "absolute";
        containerStyle.display = "block";
        containerStyle.padding = "10px";
        containerStyle.width = (width + (IE6 && QUIRKS_MODE ? 20 : 0)) + "px";
        containerStyle.height = (height + (IE6 && QUIRKS_MODE ? 20 : 0)) + "px";
        var topLt = DOC.createElement("div");
        var topLtStyle = topLt.style;
        topLtStyle.position = "absolute";
        topLtStyle.top = "0";
        topLtStyle.left = "0";
        topLtStyle.width = "20px";
        topLtStyle.height = "20px";
        topLtStyle.backgroundImage = socialImageCSS("lb_corners");
        var top = DOC.createElement("div");
        var topStyle = top.style;
        topStyle.position = "absolute";
        topStyle.top = "0";
        topStyle.left = "20px";
        topStyle.width = (width - 20) + "px";
        topStyle.height = "20px";
        topStyle.backgroundImage = socialImageCSS("lb_border");
        var topRt = DOC.createElement("div");
        var topRtStyle = topRt.style;
        topRtStyle.position = "absolute";
        topRtStyle.top = "0";
        topRtStyle.right = "0";
        topRtStyle.width = "20px";
        topRtStyle.height = "20px";
        topRtStyle.backgroundImage = socialImageCSS("lb_corners");
        topRtStyle.backgroundPosition = "top right";
        var mid = DOC.createElement("div");
        var midStyle = mid.style;
        midStyle.position = "absolute";
        midStyle.top = "20px";
        midStyle.left = "0";
        midStyle.width = (width + 20) + "px";
        midStyle.height = (height - 20) + "px";
        midStyle.backgroundImage = socialImageCSS("lb_border");
        var btmLt = DOC.createElement("div");
        var btmLtStyle = btmLt.style;
        btmLtStyle.position = "absolute";
        btmLtStyle.bottom = "0";
        btmLtStyle.left = "0";
        btmLtStyle.width = "20px";
        btmLtStyle.height = "20px";
        btmLtStyle.backgroundImage = socialImageCSS("lb_corners");
        btmLtStyle.backgroundPosition = "0 -20px";
        var btm = DOC.createElement("div");
        var btmStyle = btm.style;
        btmStyle.position = "absolute";
        btmStyle.bottom = "0";
        btmStyle.left = "20px";
        btmStyle.width = (width - 20) + "px";
        btmStyle.height = "20px";
        btmStyle.backgroundImage = socialImageCSS("lb_border");
        var btmRt = DOC.createElement("div");
        var btmRtStyle = btmRt.style;
        btmRtStyle.position = "absolute";
        btmRtStyle.bottom = "0";
        btmRtStyle.right = "0";
        btmRtStyle.width = "20px";
        btmRtStyle.height = "20px";
        btmRtStyle.backgroundImage = socialImageCSS("lb_corners");
        btmRtStyle.backgroundPosition = "-20px -20px";
        contents.style.position = "relative";
        var elems = [topLt, top, topRt, btmLt, btm, btmRt, mid, contents, closeImg];
        for (var i = 0; i < elems.length; i++) {
            this.containerElem.appendChild(elems[i])
        }
        this.lightboxElem = DOC.createElement("div");
        this.lightboxElem.className = "rpxnow_lightbox";
        var lightboxStyle = this.lightboxElem.style;
        if (IE6) {
            lightboxStyle.position = "absolute"
        } else {
            lightboxStyle.position = "fixed"
        }
        lightboxStyle.display = "none";
        lightboxStyle.top = lightboxStyle.left = "0";
        lightboxStyle.zIndex = 15;
        this.lightboxElem.appendChild(transElem);
        this.lightboxElem.appendChild(this.containerElem);
        if (DOC.body.firstChild) {
            DOC.body.insertBefore(this.lightboxElem, DOC.body.firstChild)
        } else {
            DOC.body.appendChild(this.lightboxElem)
        }
        var that = this;
        Util.addListener("resize", WIN, function () {
            that.resize()
        });
        Util.addListener("click", closeImg, function () {
            that.hide()
        });
        if (IE6) {
            WIN.attachEvent("onscroll", function () {
                that.scroll()
            })
        }
        this.closeListeners = []
    };
    Util.LightBox.currentInstance = null;
    Util.LightBox.prototype = {
        show: function () {
            if (Util.LightBox.currentInstance === null) {
                Util.LightBox.currentInstance = this
            } else {
                return false
            }
            this.containerElem.style.visibility = "hidden";
            this.resize();
            if (IE6) {
                this.scroll()
            }
            this.lightboxElem.style.display = "block";
            return true
        },
        hide: function () {
            var i, listener;
            this.lightboxElem.style.display = "none";
            Util.LightBox.currentInstance = null;
            for (i = 0; i < this.closeListeners.length; i++) {
                listener = this.closeListeners[i];
                listener()
            }
        },
        addCloseListener: function (listener) {
            this.closeListeners.push(listener)
        },
        removeCloseListener: function (listener) {
            this.closeListeners.splice(Util.indexOf(this.closeListeners, listener), 1)
        },
        isVisible: function () {
            return (this.lightboxElem.style.display === "block")
        },
        resize: function () {
            var lightboxStyle = this.lightboxElem.style;
            lightboxStyle.width = Util.getViewportWidth() + "px";
            var vpHeight = Util.getViewportHeight();
            var vpWidth = Util.getViewportWidth();
            lightboxStyle.height = vpHeight + "px";
            var elem = this.containerElem;
            var style = elem.style;
            var rs = function () {
                var padding = IE6 && QUIRKS_MODE ? 0 : 10;
                style.top = (((vpHeight - elem.offsetHeight) / 2) + padding) + "px";
                style.left = (((vpWidth - elem.offsetWidth) / 2) + padding) + "px";
                style.visibility = "visible"
            };
            if (style.visibility === "hidden") {
                WIN.setTimeout(rs, 0)
            } else {
                rs()
            }
        },
        scroll: function () {
            var lightboxStyle = this.lightboxElem.style;
            var qb = qbody();
            lightboxStyle.top = qb.scrollTop + "px";
            lightboxStyle.left = qb.scrollLeft + "px"
        }
    };
    if ((Util.isUndefined(RPXNOW._xdCallbacks)) || !RPXNOW._xdCallbacks) {
        RPXNOW._xdCallbacks = []
    }
    var registerXdCallback = function (callback) {
        var idx = RPXNOW._xdCallbacks.length;
        var callbackName = "RPXNOW._xdCallbacks[" + idx + "]";
        RPXNOW._xdCallbacks.push(function (json) {
            var idx = Util.indexOf(RPXNOW._xdCallbacks, this);
            RPXNOW._xdCallbacks[idx] = null;
            var parsed = Util.parseJSON(json);
            callback(parsed)
        });
        return callbackName
    };
    var xdCall = function (action, args, callback) {
        var callbackName = registerXdCallback(callback);
        var faction = RPXNOW.config.baseUrl + "jsapi/v3/" + action;
        var form = new Util.HiddenForm(faction, args);
        form.setHidden("xdReceiver", RPXNOW.config.xdReceiver);
        form.setHidden("callback", callbackName);
        if (RPXNOW.config.baseUrl === RPXNOW.DEFAULT_BASE_URL) {
            form.setHidden("appId", RPXNOW.config.appId)
        }
        var iframe = new Util.HiddenIframe();
        form.submitTo(iframe)
    };
    if ((Util.isUndefined(RPXNOW.Util)) || !RPXNOW.Util) {
        RPXNOW.Util = Util
    }
    var Auth = {};
    var BaseProvider = function (name, popupWidth, popupHeight) {
        this.name = name;
        this.popupWidth = popupWidth;
        this.popupHeight = popupHeight;
        this.base_params = {}
    };
    BaseProvider.prototype = {
        _start: function (immediate, token_url, callback, params) {
            if (!immediate) {
                Auth.CookieUserStateStore.setLastLoginTab(this.providerName())
            }
            var qb = this.queryBuilder();
            qb.add("token_url", token_url);
            if (params) {
                for (var key in params) {
                    if (Object.hasOwnProperty.call(params, key)) {
                        qb.add(key, params[key])
                    }
                }
            }
            var pw = null;
            var ii = null;
            if (!MOBILE) {
                qb.add("callback", registerXdCallback(function (resp) {
                    if (!Util.isNull(pw)) {
                        WIN.clearInterval(ii);
                        pw.close()
                    }
                    callback(resp)
                }));
                qb.add("callbackScheme", SCHEME)
            }
            var dest = this.startUrl() + "?" + qb.toString();
            if (immediate) {
                var ifrm = new Util.HiddenIframe();
                ifrm.setSrc(dest)
            } else {
                if (MOBILE) {
                    WIN.top.location.href = dest
                } else {
                    pw = new Util.PopupWindow(this.popupWidth, this.popupHeight, this.name);
                    pw.show(dest);
                    ii = WIN.setInterval(function () {
                        if (pw.window.closed) {
                            WIN.clearInterval(ii);
                            callback({
                                stat: "fail",
                                err: {
                                    code: -1
                                }
                            })
                        }
                    }, 1000)
                }
            }
        },
        queryBuilder: function () {
            var qb = new Util.QueryBuilder(this.base_params);
            var args = Util.parseQueryString(WIN.location.href);
            qb.add("flags", args.flags);
            qb.add("openid_proxy_url", args.openid_proxy_url);
            return qb
        },
        startUrl: function () {
            return RPXNOW.config.baseUrl + this.name + "/start"
        },
        providerName: function () {
            return this.name
        }
    };
    Auth.OpenID1Provider = function (providerName, prefix, suffix, popupWidth, popupHeight) {
        BaseProvider.call(this, "openid", popupWidth, popupHeight);
        this.prefix = prefix;
        this.suffix = suffix;
        this._immediate = {};
        this._providerName = providerName
    };
    var oid1Proto = Auth.OpenID1Provider.prototype = new BaseProvider();
    oid1Proto.providerName = function () {
        return this._providerName
    };
    oid1Proto.immediate = function (token_url) {
        if (ACTIVEX) {
            return
        }
        var last = Auth.CookieUserStateStore.getLastSuccessful();
        if (last.providerName == this.providerName()) {
            var ident = this.prefix + last.userInput + this.suffix;
            var that = this;
            this._start(true, token_url, function (resp) {
                if (resp.stat == "ok") {
                    that._immediate.input = last.userInput;
                    that._immediate.url = resp.redirectUrl
                }
            }, {
                openid_identifier: ident,
                immediate: true
            })
        }
    };
    oid1Proto.start = function (user_input, token_url, error_callback) {
        if (!Util.isNull(this._immediate.url) && user_input == this._immediate.input) {
            WIN.top.location.href = this._immediate.url;
            return
        }
        Auth.CookieUserStateStore.setLastUserInput(user_input);
        if (this.prefix.length > 0 || this.suffix.length > 0) {
            user_input = encodeURIComponent(user_input)
        }
        var ident = this.prefix + user_input + this.suffix;
        var cb = function (resp) {
            if (resp.stat == "ok") {
                WIN.setTimeout(function () {
                    WIN.top.location.href = resp.redirectUrl
                }, 1)
            } else {
                error_callback(resp.err)
            }
        };
        this._start(false, token_url, cb, {
            openid_identifier: ident
        })
    };
    Auth.OpenID2Provider = function (providerName, identifierSelectUrl, popupWidth, popupHeight) {
        BaseProvider.call(this, "openid", popupWidth, popupHeight);
        this._providerName = providerName;
        this.identifierSelectUrl = identifierSelectUrl;
        this.immediateUrl = null
    };
    var oid2Proto = Auth.OpenID2Provider.prototype = new BaseProvider();
    oid2Proto.providerName = function () {
        return this._providerName
    };
    oid2Proto.immediate = function (token_url) {
        if (ACTIVEX) {
            return
        }
        var last = Auth.CookieUserStateStore.getLastSuccessful();
        if (last.providerName == this.providerName()) {
            var identifier = Util.Cookies.get(this.providerName() + "_identifier");
            if (identifier) {
                var that = this;
                this._start(true, token_url, function (resp) {
                    if (resp.stat == "ok") {
                        that.immediateUrl = resp.redirectUrl
                    }
                }, {
                    openid_identifier: identifier,
                    immediate: true
                })
            }
        }
    };
    oid2Proto.start = function (token_url, error_callback) {
        if (!Util.isNull(this.immediateUrl)) {
            WIN.top.location.href = this.immediateUrl;
            return
        }
        var identifier = Util.Cookies.get(this.providerName() + "_identifier");
        if (!identifier) {
            identifier = this.identifierSelectUrl
        }
        var cb = function (resp) {
            if (resp.stat == "ok") {
                WIN.setTimeout(function () {
                    WIN.top.location.href = resp.redirectUrl
                }, 1)
            } else {
                error_callback(resp.err)
            }
        };
        this._start(false, token_url, cb, {
            openid_identifier: identifier
        })
    };
    oid2Proto.startFresh = function (token_url, error_callback) {
        var cb = function (resp) {
            if (resp.stat == "ok") {
                WIN.setTimeout(function () {
                    WIN.top.location.href = resp.redirectUrl
                }, 1)
            } else {
                error_callback(resp.err)
            }
        };
        this._start(false, token_url, cb, {
            openid_identifier: this.identifierSelectUrl,
            force_reauth: true
        })
    };
    oid2Proto.queryBuilder = function () {
        var qb = BaseProvider.prototype.queryBuilder.call(this);
        qb.add("display", "popup");
        return qb
    };
    Auth.CustomProvider = function (name, width, height) {
        BaseProvider.call(this, name, width, height)
    };
    var custProto = Auth.CustomProvider.prototype = new BaseProvider();
    custProto.start = function (token_url, error_callback, params) {
        var cb = function (resp) {
            if (resp.stat == "ok") {
                WIN.setTimeout(function () {
                    WIN.top.location.href = resp.redirectUrl
                }, 1)
            } else {
                error_callback(resp.err)
            }
        };
        this._start(false, token_url, cb, params)
    };
    Auth.providers = {
        aol: new Auth.OpenID1Provider("aol", "http://openid.aol.com/", "", 514, 550),
        blogger: new Auth.OpenID1Provider("blogger", "", "", 800, 600),
        livejournal: new Auth.OpenID1Provider("livejournal", "http://", ".livejournal.com/", 800, 600),
        netlog: new Auth.OpenID1Provider("netlog", "http://netlog.com/", "", 800, 600),
        openid: new Auth.OpenID1Provider("openid", "", "", 800, 600),
        wordpress: new Auth.OpenID1Provider("wordpress", "http://", ".wordpress.com/", 800, 600),
        flickr: new Auth.OpenID2Provider("flickr", "http://flickr.com/", 500, 500),
        google: new Auth.OpenID2Provider("google", "https://www.google.com/accounts/o8/id", 450, 500),
        hyves: new Auth.OpenID2Provider("hyves", "http://hyves.nl/", 800, 600),
        myopenid: new Auth.OpenID2Provider("myopenid", "http://myopenid.com/", 800, 600),
        verisign: new Auth.OpenID2Provider("verisign", "http://pip.verisignlabs.com/", 800, 600),
        yahoo: new Auth.OpenID2Provider("yahoo", "http://me.yahoo.com/", 500, 500),
        facebook: new Auth.CustomProvider("facebook", 500, 500),
        live_id: new Auth.CustomProvider("liveid", 750, 550),
        linkedin: new Auth.CustomProvider("linkedin", 750, 550),
        myspace: new Auth.CustomProvider("myspace", 800, 500),
        twitter: new Auth.CustomProvider("twitter", 800, 500)
    };
    Auth.CookieUserStateStore = {
        setLastLoginTab: function (login_tab) {
            var options = {
                expires: new Date(),
                path: "/"
            };
            options.expires.setDate(options.expires.getDate() + 3650);
            Util.Cookies.set("login_tab", login_tab, options)
        },
        setLastUserInput: function (user_input) {
            var options = {
                expires: new Date(),
                path: "/"
            };
            options.expires.setDate(options.expires.getDate() + 3650);
            Util.Cookies.set("user_input", user_input, options)
        },
        getLastSuccessful: function () {
            var result = {
                providerName: Util.Cookies.get("expected_tab"),
                userInput: Util.Cookies.get("expected_user_input"),
                userName: null
            };
            var welcome = Util.Cookies.get("welcome_info");
            if (!Util.isNull(welcome)) {
                try {
                    var parsed = Util.parseJSON(welcome);
                    if (parsed[0] == "welcome_user") {
                        result.userName = parsed[1].name
                    }
                } catch(e) {}
            }
            return result
        }
    };
    if ((Util.isUndefined(RPXNOW.Auth)) || !RPXNOW.Auth) {
        RPXNOW.Auth = Auth
    }
    var divPlusIFrame = function (div, name, width, height, bg_name) {
        div.innerHTML = ('<iframe src="' + (IE6 ? RPXNOW.config.baseUrl + "blank.html" : "") + '" name="' + name + '" id="' + name + '" style="width: ' + width + "px; height: " + height + 'px; background: transparent; position: absolute; top: 0; left: 0; visibility: hidden; display: none;" scrolling="no" frameBorder="0" allowTransparency="true"></iframe>');
        var divStyle = div.style;
        divStyle.backgroundColor = "transparent";
        divStyle.backgroundImage = socialImageCSS(bg_name);
        divStyle.backgroundRepeat = "no-repeat";
        divStyle.backgroundPosition = "top left";
        divStyle.fontSize = "17px";
        divStyle.textAlign = "center";
        divStyle.width = width + "px";
        divStyle.height = height + "px";
        divStyle.overflow = "hidden";
        divStyle.fontFamily = "'lucida grande', Helvetica, Verdana, sans-serif"
    };
    var showIFrameOnLoad = function (ifrm, span) {
        if (ACTIVEX) {
            ifrm.onreadystatechange = function () {
                if (ifrm.readyState === "complete") {
                    span.style.visibility = "hidden";
                    ifrm.style.visibility = "visible";
                    WIN.setTimeout(function () {
                        ifrm.style.display = "block"
                    }, 1500)
                }
            }
        } else {
            ifrm.addEventListener("load", function () {
                ifrm.style.display = "block";
                WIN.setTimeout(function () {
                    span.style.visibility = "hidden";
                    ifrm.style.visibility = "visible"
                }, 1)
            }, false)
        }
    };
    var Social = {
        publishActivity: function (activity, finishCallback) {
            var loadingSpan;
            if (Util.isNull(activity.title)) {
                activity.setTitle(DOC.title)
            }
            var name = "rpx_auth_" + (new Date()).getTime();
            var div = DOC.createElement("div");
            var lightbox = new Util.LightBox(div, 460, 350);
            divPlusIFrame(div, name, 460, 350, "bg_fade");
            if (RPXNOW.config.hasError()) {
                var spacingDiv = DOC.createElement("div");
                var spacingStyle = spacingDiv.style;
                spacingStyle.lineHeight = "324px";
                spacingStyle.padding = "13px";
                spacingDiv.appendChild(DOC.createTextNode("Error: " + RPXNOW.config.error));
                div.appendChild(spacingDiv)
            } else {
                div.style.lineHeight = "350px";
                loadingSpan = DOC.createElement("span");
                loadingSpan.appendChild(DOC.createTextNode("Loading..."));
                div.appendChild(loadingSpan)
            }
            var ifrm = DOC.getElementById(name);
            var callbackName = null;
            if (!Util.isFunction(finishCallback)) {
                finishCallback = function (unused) {}
            }
            var wrapped = function (json) {
                var frm = new Util.HiddenForm(json.resultsUrl);
                frm.setHidden("token", json.token);
                frm.setTarget(name);
                frm.submit();
                var cb = function () {
                    finishCallback(json.publishResults)
                };
                if (!Util.isNull(RPXNOW.config.tokenCallbackUrl) && json.authTokens.length > 0) {
                    var tokensForm = new Util.HiddenForm(RPXNOW.config.tokenCallbackUrl);
                    tokensForm.setHidden("tokens", json.authTokens);
                    var tokensFrame = new Util.HiddenIframe();
                    tokensForm.setTarget(tokensFrame.getName());
                    tokensFrame.addOnloadListener(cb);
                    tokensForm.setMethod("POST");
                    tokensForm.submit()
                } else {
                    WIN.setTimeout(cb, 1)
                }
            };
            callbackName = registerXdCallback(wrapped);
            if (!RPXNOW.config.hasError()) {
                showIFrameOnLoad(ifrm, loadingSpan);
                var sessionCB = function (resp) {
                    var action = RPXNOW.config.baseUrl + "social/publish_activity";
                    var frm = new Util.HiddenForm(action);
                    frm.setMethod("POST");
                    frm.setHidden("activity", Util.toJSON(activity));
                    frm.setHidden("sessid", resp.sessid);
                    frm.setHidden("appId", RPXNOW.config.appId);
                    frm.setHidden("xdReceiver", RPXNOW.config.xdReceiver);
                    frm.setHidden("callback", callbackName);
                    frm.setTarget(name);
                    frm.submit()
                };
                xdCall("popup_session", {}, sessionCB)
            }
            lightbox.show();
            return false
        },
        clearSocialCookies: function (dest) {
            if (!Util.isUndefined(dest)) {
                if (!Util.isNull(dest) && !ABSOLUTE_URL_RE.test(dest)) {
                    throw new Error("The dest must be an absolute URL")
                }
                var domainRe = new RegExp("^https?://" + Util.regexpEscape(DOC.location.host) + "/");
                if (!Util.isNull(dest) && !domainRe.test(dest)) {
                    throw new Error("dest host does not match the current page.")
                }
            }
            var action = RPXNOW.config.baseUrl + "social/logout";
            var form = new Util.HiddenForm(action);
            form.setHidden("appId", RPXNOW.config.appId);
            var iframe = new Util.HiddenIframe();
            form.setTarget(iframe.getName());
            if (!Util.isUndefined(dest)) {
                iframe.addOnloadListener(function () {
                    WIN.top.location.href = dest
                })
            }
            form.submit();
            return false
        }
    };
    Social.Activity = function (share_display, action, url) {
        if (!Util.isString(share_display)) {
            throw new Error("a non-null share_display string is required.")
        }
        this.share_display = share_display;
        if (!Util.isString(action)) {
            throw new Error("a non-null action string must be provided.")
        }
        this.action = action;
        if (!Util.isString(url) || !ABSOLUTE_URL_FRAG_RE.test(url)) {
            throw new Error("a valid url must be provided.")
        }
        this.url = url;
        this.title = null;
        this.description = null;
        this.user_generated_content = null;
        this.properties = {};
        this.action_links = [];
        this.media = null
    };
    Social.Activity.prototype = {
        setTitle: function (title) {
            if (!Util.isString(title)) {
                throw new Error("title must be a string")
            }
            this.title = title
        },
        setDescription: function (description) {
            if (!Util.isString(description)) {
                throw new Error("description must be a string")
            }
            this.description = description
        },
        setUserGeneratedContent: function (user_generated_content) {
            if (!Util.isString(user_generated_content)) {
                throw new Error("user_generated_content must be a string")
            }
            this.user_generated_content = user_generated_content
        },
        addActionLink: function (text, url) {
            if (!Util.isString(url) || !ABSOLUTE_URL_FRAG_RE.test(url)) {
                throw new Error("a valid url must be provided.")
            }
            this.action_links.push({
                text: text,
                href: url
            })
        },
        addTextProperty: function (name, text) {
            if (!Util.isString(name) || !Util.isString(text)) {
                throw new Error("The name and text must be strings")
            }
            this.properties[name] = text
        },
        addLinkProperty: function (name, text, url) {
            if (!Util.isString(name) || !Util.isString(text)) {
                throw new Error("The name and text must be strings")
            }
            if (!Util.isString(url) || !ABSOLUTE_URL_FRAG_RE.test(url)) {
                throw new Error("a valid url must be provided.")
            }
            this.properties[name] = {
                text: text,
                href: url
            }
        },
        setMediaItem: function (mediaItem) {
            this.media = mediaItem.toMediaArray()
        }
    };
    Social.Mp3MediaItem = function (src, title, artist, album) {
        if (!Util.isString(src) || !ABSOLUTE_URL_RE.test(src)) {
            throw new Error("The src must be a valid url")
        }
        this.type = "mp3";
        this.src = src;
        if (Util.isString(title)) {
            this.title = title
        }
        if (Util.isString(artist)) {
            this.artist = artist
        }
        if (Util.isString(album)) {
            this.album = album
        }
    };
    Social.Mp3MediaItem.prototype = {
        toMediaArray: function () {
            return [this]
        },
        setTitle: function (title) {
            this.title = title
        },
        setArtist: function (artist) {
            this.artist = artist
        },
        setAlbum: function (album) {
            this.album = album
        }
    };
    Social.VideoMediaItem = function (video_src, preview_img, video_link, video_title) {
        if (!Util.isString(video_src) || !ABSOLUTE_URL_RE.test(video_src)) {
            throw new Error("video_src must be a valid url")
        }
        if (!Util.isString(preview_img) || !ABSOLUTE_URL_RE.test(preview_img)) {
            throw new Error("preview_img must be a valid url")
        }
        this.type = "video";
        this.video_src = video_src;
        this.preview_img = preview_img;
        if (Util.isString(video_link)) {
            if (!ABSOLUTE_URL_FRAG_RE.test(video_link)) {
                throw new Error("video_link must be a valid url if provided")
            }
        }
        if (Util.isString(video_title)) {
            this.video_title = video_title
        }
    };
    Social.VideoMediaItem.prototype = {
        toMediaArray: function () {
            return [this]
        },
        setVideoLink: function (video_link) {
            if (!Util.isString(video_link) || !ABSOLUTE_URL_FRAG_RE.test(video_link)) {
                throw new Error("video_link must be a valid url")
            }
        },
        setVideoTitle: function (video_title) {
            this.video_title = video_title
        }
    };
    Social.FlashMediaItem = function (swfsrc, imgsrc, width, height, expanded_width, expanded_height) {
        if (!Util.isString(swfsrc) || !ABSOLUTE_URL_RE.test(swfsrc)) {
            throw new Error("swfsrc must be a valid url")
        }
        if (!Util.isString(imgsrc) || !ABSOLUTE_URL_RE.test(imgsrc)) {
            throw new Error("preview_img must be a valid url")
        }
        this.type = "flash";
        this.swfsrc = swfsrc;
        this.imgsrc = imgsrc;
        if (Util.isString(width) || Util.isNumber(width)) {
            this.width = "" + width
        }
        if (Util.isString(height) || Util.isNumber(height)) {
            this.height = "" + height
        }
        if (Util.isString(expanded_width) || Util.isNumber(expanded_width)) {
            this.expanded_width = "" + expanded_width
        }
        if (Util.isString(expanded_height) || Util.isNumber(expanded_height)) {
            this.expanded_height = "" + expanded_height
        }
    };
    Social.FlashMediaItem.prototype = {
        toMediaArray: function () {
            return [this]
        },
        setWidth: function (width) {
            if (!Util.isString(width) && !Util.isNumber(width)) {
                throw new Error("width must be a number")
            }
            this.width = "" + width
        },
        setHeight: function (height) {
            if (!Util.isString(height) && !Util.isNumber(height)) {
                throw new Error("height must be a number")
            }
            this.height = "" + height
        },
        setExpandedWidth: function (expanded_width) {
            if (!Util.isString(expanded_width) && !Util.isNumber(expanded_width)) {
                throw new Error("expanded_width must be a number")
            }
            this.expanded_width = "" + expanded_width
        },
        setExpandedHeight: function (expanded_height) {
            if (!Util.isString(expanded_height) && !Util.isNumber(expanded_height)) {
                throw new Error("expanded_height must be a number")
            }
            this.expanded_height = "" + expanded_height
        }
    };
    Social.ImageMediaCollection = function () {
        this.images = []
    };
    Social.ImageMediaCollection.prototype = {
        toMediaArray: function () {
            return this.images
        },
        addImage: function (src, href) {
            if (this.images.length >= 5) {
                throw new Error("Cannot have more than 5 images.")
            }
            if (!Util.isString(src) || !ABSOLUTE_URL_RE.test(src)) {
                throw new Error("src must be a valid url")
            }
            if (!Util.isString(href) || !ABSOLUTE_URL_FRAG_RE.test(href)) {
                throw new Error("href must be a valid url")
            }
            this.images.push({
                type: "image",
                src: src,
                href: href
            })
        }
    };
    if ((Util.isUndefined(RPXNOW.Social)) || !RPXNOW.Social) {
        RPXNOW.Social = Social
    }
    var Config = function () {
        this.appId = null;
        this.xdReceiver = null;
        this.baseUrl = RPXNOW.DEFAULT_BASE_URL;
        this.error = null;
        this.tokenCallbackUrl = null
    };
    Config.prototype = {
        initialize: function (appId, xdReceiver, tokenCallbackUrl) {
            this.appId = appId;
            this.xdReceiver = xdReceiver;
            this.tokenCallbackUrl = tokenCallbackUrl
        },
        setError: function (msg) {
            this.error = msg
        },
        hasError: function () {
            return !Util.isNull(this.error)
        }
    };
    if ((Util.isUndefined(RPXNOW.config)) || !RPXNOW.config) {
        RPXNOW.config = new Config()
    }
    var baseUrlCallbacks = [];
    var withBaseUrl = function (cb) {
        if (RPXNOW.config.baseUrl === RPXNOW.DEFAULT_BASE_URL) {
            baseUrlCallbacks.push(cb)
        } else {
            cb()
        }
    };
    RPXNOW.loadAndRun = function (moduleNames, callback) {
        withBaseUrl(callback)
    };
    RPXNOW.init = function (params, maybeXdReceiver) {
        var appId, xdReceiver, baseUrl = null,
            tokenCallbackUrl = null;
        var l = DOC.location;
        if (Util.isObject(params)) {
            appId = params.appId;
            xdReceiver = params.xdReceiver;
            baseUrl = params.baseUrl;
            tokenCallbackUrl = params.tokenCallbackUrl
        } else {
            appId = params;
            xdReceiver = maybeXdReceiver
        }
        if (Util.isUndefined(xdReceiver)) {
            xdReceiver = l.protocol + "//" + l.host + "/rpx_xdcomm.html"
        } else {
            if (ABSOLUTE_URL_RE.test(xdReceiver)) {
                var domainRe = new RegExp("^https?://" + Util.regexpEscape(l.host) + "/");
                if (!domainRe.test(xdReceiver)) {
                    throw new Error("RPXNow:init: xdReceiver host does not match.")
                }
            } else {
                if (ABSOLUTE_PATH_RE.test(xdReceiver)) {
                    xdReceiver = l.protocol + "//" + l.host + xdReceiver
                } else {
                    throw new Error("RPXNow:init: xdReceiver must be either an absolute URL or a relative URL path starting with /.")
                }
            }
        }
        if (baseUrl) {
            RPXNOW.config.baseUrl = RPXNOW.DEFAULT_BASE_URL = baseUrl
        }
        RPXNOW.config.initialize(appId, xdReceiver, tokenCallbackUrl);
        var cbs = {
            success: function (unused) {
                RPXNOW.config.initialize(appId, xdReceiver, tokenCallbackUrl);
                RPXNOW._base_cb = function (success, data) {
                    if (success) {
                        RPXNOW.config.baseUrl = data
                    } else {
                        RPXNOW.config.setError(data)
                    }
                    var cb = baseUrlCallbacks.shift();
                    while (Util.isFunction(cb)) {
                        cb();
                        cb = baseUrlCallbacks.shift()
                    }
                };
                var url = RPXNOW.DEFAULT_BASE_URL + "jsapi/v3/base_url";
                url += "?appId=" + appId;
                url += "&xdReceiver=" + WIN.escape(xdReceiver);
                var script = DOC.createElement("script");
                script.src = url;
                script.type = "text/javascript";
                DOC.body.appendChild(script)
            },
            failure: function (unused_code, unused_status, unused_body) {
                RPXNOW.config.setError("unable to load " + xdReceiver)
            }
        };
        Util.XHR.fetch(xdReceiver, cbs)
    };
    RPXNOW.loaded = false;
    RPXNOW.show = function () {
        RPXNOW.show_on_load = true
    };
    RPXNOW.always_open = false;
    RPXNOW.overlay = false;
    RPXNOW.language_preference = "en";
    RPXNOW.default_provider = null;
    RPXNOW.lso_submit_action = null;
    RPXNOW.token_url = null;
    RPXNOW.realm = null;
    RPXNOW.domain = null;
    RPXNOW.flags = null;
    RPXNOW.email = null;
    RPXNOW.openid_proxy_url = null;
    RPXNOW.ssl = null;
    var genSigninUrl = function (token_url, domain) {
        if (!ABSOLUTE_URL_RE.test(token_url)) {
            Util.log("Error - token_url must be an absolute URL with no fragment.")
        }
        var host = RPXNOW.config.baseUrl.split("/")[2];
        var rp_id = null;
        if (RPXNOW.rp_id) {
            rp_id = RPXNOW.rp_id
        } else {
            if (RPXNOW.domain) {
                host = RPXNOW.domain
            } else {
                if (RPXNOW.realm) {
                    if (RPXNOW.realm.match(/\./)) {
                        host = RPXNOW.realm
                    } else {
                        host = RPXNOW.realm + "." + host
                    }
                } else {
                    if (domain) {
                        host = domain
                    }
                }
            }
        }
        var query = new Util.QueryBuilder();
        query.add("token_url", token_url);
        var scheme = Util.isNull(RPXNOW.ssl) ? SCHEME : (RPXNOW.ssl ? "https" : "http");
        var signin_url = scheme + "://" + host + "/openid/embed?";
        if (rp_id) {
            query.add("rp_id", rp_id)
        }
        for (var ofi = 0; ofi < COMMON_UI_PARAMS.length; ofi++) {
            var fieldname = COMMON_UI_PARAMS[ofi];
            if (fieldname != "token_url" && RPXNOW[fieldname]) {
                query.add(fieldname, RPXNOW[fieldname])
            }
        }
        return signin_url + query.toString()
    };
    var loadListener = function () {
        RPXNOW.show = function (token_url, domain) {
            if (Util.LightBox.currentInstance !== null) {
                return false
            }
            if (Util.isUndefined(token_url)) {
                token_url = RPXNOW.token_url
            }
            var loading_str = LOADING_STRINGS[RPXNOW.language_preference];
            if (!loading_str) {
                loading_str = LOADING_STRINGS.pt
            }
            var width = 373;
            var height = 215;
            var name = "framel";
            var div = DOC.createElement("div");
            var lightbox = new Util.LightBox(div, width, height);
            divPlusIFrame(div, name, width, height, "bg_auth");
            div.style.lineHeight = height + "px";
            var loadingSpan = DOC.createElement("span");
            loadingSpan.appendChild(DOC.createTextNode(loading_str + "..."));
            div.appendChild(loadingSpan);
            var ifrm = DOC.getElementById(name);
            ifrm.style.marginTop = "12px";
            showIFrameOnLoad(ifrm, loadingSpan);
            lightbox.show();
            var url = genSigninUrl(token_url, domain);
            ifrm.contentWindow.location.replace(url);
WIN.setTimeout( function () {
document.getElementById('pop').style.zIndex = lightboxStyle.zIndex + 1;
}, 1);
            if (!token_url) {
                Util.log("Error - RPXNOW.token_url is undefined.")
            }
            return false
        };
        var hookPopupToRpxLink = function (element) {
            var token_url, domain;
            var href = element.href;
            if (!RPXNOW.token_url) {
                token_url = Util.parseQueryString(href).token_url
            }
            var domain_match = href.match(/https?:\/\/([^\/]+)/);
            if (domain_match !== null) {
                domain = domain_match[1]
            }
            element.onclick = function () {
document.getElementById('pop').style.display='block';
                RPXNOW.show(token_url, domain);
                return false
            }
        };
        var arrElements = DOC.getElementsByTagName("a");
        var oRegExp = new RegExp("(^|\\s)rpxnow(\\s|$)");
        for (var i = 0; i < arrElements.length; i++) {
            var oElement = arrElements[i];
            if (oRegExp.test(oElement.className)) {
                hookPopupToRpxLink(oElement)
            }
        }
        if (RPXNOW.show_on_load || RPXNOW.always_open) {
            RPXNOW.show();
        }
    };
    WIN.RPXNOW = RPXNOW;
    if (ACTIVEX) {
        WIN.attachEvent("onload", loadListener)
    } else {
        WIN.addEventListener("load", loadListener, false)
    }
})(this);
