﻿/**
* WMObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/WMObject/
*
* WMObject is (c) 2007 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if (typeof deconcept.WMObjectUtil == "undefined") { deconcept.WMObjectUtil = new Object(); }

deconcept.WMObject = function(id, width, height, bgcolor, _7, _8, _9, _a) {
    if (!document.getElementById) { return; }
    this.params = new Object();
    this.variables = new Object();
    this.attributes = new Array();
    if (id) { this.setAttribute("id", id); }
    if (width) { this.setAttribute("width", width); }
    if (height) { this.setAttribute("height", height); }
    if (bgcolor) { this.addParam("bgcolor", bgcolor); }
    var q = _7 ? _7 : "high";
    this.addParam("quality", q);
    this.setAttribute("useExpressInstall", false);
    this.setAttribute("doExpressInstall", false);
    var _c = (_8) ? _8 : window.location;
    this.setAttribute("xiRedirectUrl", _c);
    this.setAttribute("redirectUrl", "");
    if (_9) { this.setAttribute("redirectUrl", _9); }
};

deconcept.WMObject.prototype = {

    useExpressInstall: function(_d) {
        this.xiWMVPath = !_d ? "expressinstallwmv" : _d;
        this.setAttribute("useExpressInstall", true);
    },

    setAttribute: function(_e, _f) { this.attributes[_e] = _f; },

    getAttribute: function(_10) { return this.attributes[_10]; },

    addParam: function(name, value) { this.params[name] = value; },

    getParams: function() { return this.params; },

    addVariable: function(_13, _14) { this.variables[_13] = _14; },

    getVariable: function(_15) { return this.variables[_15]; },

    getVariables: function() { return this.variables; },

    getVariablePairs: function() {
        var _16 = new Array();
        var key;
        var _18 = this.getVariables();
        for (key in _18) {
            _16[_16.length] = key + "=" + _18[key];
        }
        return _16;
    },

    getWMVHTML: function() {
        var _19 = "";
        if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
            _19 = "<embed type=\"application/x-mplayer2\" src=\"" +
                this.getParams()["FileName"] +
                "\" width=\"" + this.getAttribute("width") +
                "\" height=\"" + this.getAttribute("height") +
                "\" style=\"" + this.getAttribute("style") + "\"";
            _19 += " id=\"" + this.getAttribute("id") +
                "\" name=\"" + this.getAttribute("id") + "\" ";
            var _1a = this.getParams();
            for (var key in _1a) {
                _19 += [key] + "=\"" + _1a[key] + "\" ";
            }
            var _1c = this.getVariablePairs().join("&");
            if (_1c.length > 0) {
                _19 += "flashvars=\"" + _1c + "\"";
            }
            _19 += "/>";
        } else {
            if (this.getAttribute("doExpressInstall")) {
                this.addVariable("MMplayerType", "ActiveX");
                this.setAttribute("WMV", this.xiWMVPath);
            }
            
            var clsid = "6BF52A52-394A-11d3-B153-00C04F79FAA6";
            try
            {
                var windowsPlayer = new ActiveXObject("MediaPlayer.MediaPlayer.1");
                clsid = "22D6F312-B0F6-11D0-94AB-0080C74C7E95";
            } catch(err){}
            _19 = "<object id=\"" + this.getAttribute("id") +
                "\" classid=\"CLSID:" + clsid + "\" width=\"" + this.getAttribute("width") +
                "\" height=\"" + this.getAttribute("height") +
                "\" style=\"" + this.getAttribute("style") + "\">";
            _19 += "<param name=\"movie\" value=\"" + this.getAttribute("WMV") + "\" />";
            var _1d = this.getParams();
            for (var key in _1d) {
                _19 += "<param name=\"" + key + "\" value=\"" + _1d[key] + "\" />";
            }
            var _1f = this.getVariablePairs().join("&");
            if (_1f.length > 0) {
                _19 += "<param name=\"flashvars\" value=\"" + _1f + "\" />";
            }
            _19 += "</object>";
        } return _19;
    },

    write: function(div) {
    var n = (typeof div == "string") ? document.getElementById(div) : div;
        n.innerHTML = this.getWMVHTML();
        return true;
    }
};

deconcept.WMObjectUtil.cleanupWMVs = function() {
    var _2f = document.getElementsByTagName("OBJECT");
    for (var i = _2f.length - 1; i >= 0; i--) {
        _2f[i].style.display = "none";
        for (var x in _2f[i]) {
            if (typeof _2f[i][x] == "function") {
                _2f[i][x] = function() { };
            }
        }
    }
};

if (deconcept.WMObject.doPrepUnload) {
    if (!deconcept.unloadSet) {
        deconcept.WMObjectUtil.prepUnload = function() {
            __flash_unloadHandler = function() { };
            __flash_savedUnloadHandler = function() { };
            window.attachEvent("onunload", deconcept.WMObjectUtil.cleanupWMVs);
        };
        window.attachEvent("onbeforeunload", deconcept.WMObjectUtil.prepUnload);
        deconcept.unloadSet = true;
    }
}

var WindowsMediaObject = deconcept.WMObject;
var WMObject = deconcept.WMObject;

function startWMVideo(channel) {
    var w1 = new WMObject("play_video", "360", "350", "#000000");
    w1.addParam("FileName", "/streams.aspx?channel=" + channel);
    w1.addParam("Url", "/streams.aspx?channel=" + channel);
    w1.addParam("FileAutoStartName", "true");
    w1.addParam("ShowTracker", "true");
    w1.addParam("ShowStatusBar", "true");
    w1.addParam("ShowControls", "true");
    var div = document.getElementById("video");
    w1.write(div);
}
