var AppletObject = {
    version : 0.0,
    _ns : "http://www.w3.org/1999/xhtml",
    _ie : window.ActiveXObject,
    _classid : "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",
    _cab : "http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0",
    _type : "application/x-java-applet",
    _createElement : function (doc, name) {
        if (doc.createElementNS) {
            return doc.createElementNS(this._ns, name);
        }
        return doc.createElement(name);
    },
    _setAttribute : function (el, name, value) {
        if (el.setAttributeNS) {
            el.setAttributeNS(null, name, value);
        } else {
            el.setAttribute(name, value)
        }
    },
    _createParam : function (doc, name, value) {
        var param = this._createElement(doc, "param");
        this._setAttribute(param, "name", name);
        this._setAttribute(param, "value", value);
        return param;
    },
    _getElementsByTagName : function (el, names) {
        if (el.getElementsByTagNameNS) {
            return el.getElementsByTagNameNS(null, names);
        }
        return el.getElementsByTagName(names);
    },
    addParam : function (obj, name, value) {
        return obj.appendChild(this._createParam(obj.ownerDocument, name, value));
    },
    toMarkup : function(el) {
        if (typeof el.outerHTML == "string") {
            return el.outerHTML;
        }
        var holder = this._createElement(el.ownerDocument, "div");
        holder.appendChild(el.cloneNode(true));
        return holder.innerHTML;
    },
    create : function (doc, width, height, params, fallback) {
        var applet = this._createElement(doc, "object");
        if (this._ie) {
            this._setAttribute(applet, "classid", this._classid);
            this._setAttribute(applet, "codebase", this._cab);
        } else {
            this._setAttribute(applet, "type", this._type);
        }
        if (typeof width == "string" || typeof width == "number") {
            this._setAttribute(applet, "width", width);
        }
        if (typeof height == "string" || typeof height == "nummber") {
            this._setAttribute(applet, "height", height);
        }
        if (typeof params == "object") {
            for (var i in params) {
                this.addParam(applet, i, params[i]);
            }
        }
        if (!this._ie) {
            if (typeof fallback == "string") {
                applet.appendChild(doc.createTextNode("fallback"));
            } else if (fallback instanceof Node) {
                applet.appendChild(fallback);
            }
        }
        return applet;
    },
    createMarkup : function(width, height, params, fallback) {
        return this.toMarkup(this.create(document, width, height, params, fallback));
    },
    appendTo : function(el, applet, emptyFirst) {
        if (typeof emptyFirst != "boolean") {
            emptyFirst = false;
        }
        if (emptyFirst) {
            while (el.hasChildNodes()) {
                el.removeChild(el.lastChild);
            }        
        }
        var ref = el.appendChild(applet);
        if (this._ie) {
            ref.outerHTML = ref.outerHTML;
            ref = this._getElementsByTagName(el, "object");
            return ref[ref.length - 1];
        }
        return ref;
    },
    createAndAppendTo : function(el, width, height, params, fallback, emptyFirst) {
        return this.appendTo(el, this.create(el.ownerDocument, width, height, params, fallback), emptyFirst);
    }
};