if (typeof (TicTacTi) == 'undefined') {

    TicTacTi = {

        globals: { widgets: [], widgetCount: 0, t3cdn: "http://cdn.tictacti.com/", pageLoaded: false, scriptLoaded: false },

        init: function() {
            try {
                document.write("<script type=\"text/javascript\" src=\"http://cdn.tictacti.com/widgets/js/swfobject.js\"></" + "script>");
            }
            catch (e) {
            }
        },

        renderWidget: function(publisherId, tagType, width, height, t3cfg) {
            try {
                if (this.undef(publisherId) || this.undef(tagType) || this.undef(width) || this.undef(height) || this.undef(t3cfg)) return;
                document.write("<div id=\"t3widget_" + this.globals.widgetCount.toString() + "\" ></div>");
                TicTacTi.globals.widgetCount++;
                TicTacTi.globals.widgets.push({ "publisherId": publisherId, "tagType": tagType, "width": width, "height": height, "t3cfg": t3cfg });
            }
            catch (e) {
            }
        },

        adEvent: function(elm, type, listener, useCapture) {
            if (elm.addEventListener) {
                elm.addEventListener(type, listener, false);
            }
            else if (elm.attachEvent) {
                elm.attachEvent("on" + type, listener);
            }

        },

        remvoeEvent: function(elm, type, listener, useCapture) {
            if (elm.removeEventListener) {
                elm.removeEventListener(type, listener, false);
            }
            else if (elm.detachEvent) {
                elm.detachEvent("on" + type, listener);
            }

        },

        onPageLoaded: function() {
            var flashvars, params, attributes, widget, origHeight, origWidth;
            for (var i = 0; i < TicTacTi.globals.widgets.length; i++) {
                widget = TicTacTi.globals.widgets[i];
                flashvars = { publisherId: widget.publisherId, tagType: widget.tagType, engineId: "gamePlayer_" + i.toString(), widgetName: widget.t3cfg.widgetName, enableDM: widget.t3cfg.config.enableDM };
                if (!TicTacTi.undef(widget.t3cfg.config.isGameFullPath)) {
                    if (widget.t3cfg.config.isGameFullPath.toString().toLowerCase() == "true") {
                        
                        flashvars.TTTWrapperGameUrl = widget.t3cfg.gameUrl;
                    }
                    else
                        flashvars.TTTWrapperGameUrl = TicTacTi.globals.t3cdn + widget.t3cfg.gameUrl;
                }
                else
                    flashvars.TTTWrapperGameUrl = TicTacTi.globals.t3cdn + widget.t3cfg.gameUrl;

                if (!TicTacTi.undef(widget.t3cfg.config.origHeight))
                    flashvars.origHeight = widget.t3cfg.config.origHeight;
                if (!TicTacTi.undef(widget.t3cfg.config.origWidth))
                    flashvars.origWidth = widget.t3cfg.config.origWidth;
                if (!TicTacTi.undef(widget.t3cfg.config.externalId))
                    flashvars.externalId = widget.t3cfg.config.externalId;
                if (!TicTacTi.undef(widget.t3cfg.config.enableCache))
                    flashvars.enableCache = widget.t3cfg.config.enableCache;

                for (var p in widget.t3cfg.config) {
                    if (p.indexOf('widget') > -1) {
                        flashvars[p] = widget.t3cfg.config[p];
                    }
                }

                params = { allowfullscreen: "true", allowScriptAccess: "always", wmode: "window", base: widget.t3cfg.config.gameBaseUrl };
                attributes = { id: "gamePlayer_" + i.toString() };
                swfobject.embedSWF(TicTacTi.globals.t3cdn + widget.t3cfg.wrapperUrl + '?wildKey=' + (new Date()).getMilliseconds(), "t3widget_" + i.toString(), widget.width, widget.height, "9.0.0", false, flashvars, params, attributes);
            }
        },

        undef: function(obj) { return (typeof (obj) == 'undefined'); }
    };

    TicTacTi.adEvent(window, "load", TicTacTi.onPageLoaded, false);
    TicTacTi.init();

}