/*
 * VideoObject (VObject) v1.0: MediaPlayer/QuickTime detection and embed
 * VideoObject (VObject) is (c) 2006 simpson, simpsonwork@gmail.com
 * This product is released under the MIT License: http://www.opensource.org/licenses/mit-license.php
 */

var classid = {
"wm":"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95",
"qt":"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"};
var srcParam = {
"wm":"filename",
"qt":"src"};
var typeParam = {
"wm":"application/x-mplayer",
"qt":"video/quicktime"};

if (typeof simdev == "undefined") var simdev = new Object();
if (typeof simdev.VObjectUtil == "undefined") simdev.VObjectUtil = new Object();
simdev.VObject = function(src, type, id, w, h) {
    if (!document.getElementById) { return; }
    this.params = new Object();
    this.variables = new Object();
    this.attributes = new Array();
    if (src) { this.setAttribute("src", src); }
    if (type) { this.setAttribute("type", type); }
    if (id) { this.setAttribute("id", id); }
    if (w) { this.setAttribute("width", w); }
    if (h) { this.setAttribute("height", h); }
}
simdev.VObject.prototype = {
    setAttribute: function(name, value) { this.attributes[name] = value; },
    getAttribute: function(name) { return this.attributes[name]; },
    addParam: function(name, value) { this.params[name] = value; },
    getParams: function() { return this.params; },
    getHTML: function() {
        var htmlNode = "";
        if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
            htmlNode = '<embed type="' + typeParam[this.getAttribute('type')] + '" src="' + this.getAttribute('src') + '" width="' + this.getAttribute('width') + '" height="' + this.getAttribute('height') + '"';
            htmlNode += ' id="' + this.getAttribute('id') + '" name="' + this.getAttribute('id') + '" ';
            var params = this.getParams();
            for (var key in params) { htmlNode += key + '="' + params[key] + '" '; }
            htmlNode += '/>';
        }
        else {
            htmlNode = '<object id="' + this.getAttribute('id') + '" classid="' + classid[this.getAttribute('type')] + '" width="' + this.getAttribute('width') + '" height="' + this.getAttribute('height') + '">';
            htmlNode += '<param name="' + srcParam[this.getAttribute('type')] + '" value="' + this.getAttribute('src') + '" />';
            var params = this.getParams();
            for (var key in params) { htmlNode += '<param name="' + key + '" value="' + params[key] + '" />'; }
            htmlNode += '</object>';
        }
        return htmlNode;
    },
    write: function(elementId) {
        var elm = (typeof elementId == "string") ? document.getElementById(elementId) : elementId;
        if (elm) {
            elm.innerHTML = this.getHTML();
            return true;
        }
        return false;
    }
}
/* Cleaning up objects */
simdev.VObjectUtil.cleanup = function(elementId) {
    var obj = (typeof elementId == "string") ? document.getElementById(elementId) : elementId;
    obj.parentNode.removeChild(obj);
    return true;
}
simdev.VObjectUtil.preUnload = function() {
    __video_unloadHandler = function(){};
    __video_savedUnloadHandler = function(){};
    if (typeof window.onunload == "function") {
        var oldUnload = window.onunload;
        window.onunload = function() {
            simdev.VObject.cleanup();
            oldUnload();
        }
    }
    else {
        window.onbeforeunload = simdev.VObjectUtil.preUnload;
    }
}
if (typeof window.onbeforeunload == "function") {
    var oldBeforeUnload = window.onbeforeunload;
    window.onbeforeunload = function() {
        simdev.VObjectUtil.preUnload();
        oldBeforeUnload();
    }
}
else {
    window.onbeforeunload = simdev.VObjectUtil.preUnload;
}
/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) {
    Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}
/* Aliases for ease of use */
var VObject = simdev.VObject;
var VideoObject = simdev.VObject;
