(function () {
    var LogFrame = null;
    var GetSession = function () {
            var result, i;
            result = '';
            var guid = new Date().getTime().toString(16).toUpperCase();
            for (var j = 0; j < 32; j++) {
                if (j == 8 || j == 12 || j == 16 || j == 20)
                    result = result + '-';
                if (j < guid.length) i = guid.charAt(j);
                else i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
                result = result + i;
            }
            return result;
    };
    var embed = (navigator.userAgent.toLowerCase().indexOf("iphone") == -1 && navigator.userAgent.toLowerCase().indexOf("ipad") == -1) || !document.createElement('video').canPlayType ? function (container, id, width, height) {
        width = width || 480;
        height = height || 270;
        container.innerHTML = '<embed src="http://www.sehnsuchtdeutschland.tv/player/vPlayer.swf" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  allowfullscreen="true" flashvars="clipID=' + id + '" />';
    } : function (container, id, width, height) {
        width = width || 480;
        height = height || 270;
        self.__SplayTV_SendLog = function (vobj, typ) {
            if (!vobj.tracked) {
                vobj.tracked = {};
                vobj.logParams = { Psession: GetSession(), ClientId: "", Action: "L", Type: "10", VideoId: id };
            }
            if (!typ) {
                if (vobj.currentTime == 0) return;
                var typ = Math.round(100 * vobj.currentTime / vobj.duration);
                if (typ % 10 <= 8) return;
                typ = 200 + (Math.ceil(typ / 10) * 10);
            }
            if (vobj.tracked["L" + typ]) return;
            var src = "http://b2b.splaytv.de/Comp/DH4qFqpY14QINa3nVb4PFW/PlayerComm.ashx?InfoType=" + typ + "&Info=" + vobj.currentTime;
            for (var key in vobj.logParams)
                src += "&" + key + "=" + vobj.logParams[key];
            LogFrame.src = src;
            vobj.tracked["L" + typ] = true;
        };
        container.innerHTML = '<video src="http://www.sehnsuchtdeutschland.tv/Videos/' + id + '.DBig.mp4" style="background-color:#000000" autobuffer="true" onplay="__SplayTV_SendLog(this,1);" ontimeupdate="__SplayTV_SendLog(this);" controls="true" width="' + width + '" height="' + height + '" poster="http://www.sehnsuchtdeutschland.tv/Videos/' + id + '.b.jpg" />';
    };
    var init = function () {

        LogFrame = document.createElement("IFRAME");
        LogFrame.style.position = "absolute";
        LogFrame.style.visibility = "hidden";
        document.body.appendChild(LogFrame);

        var containers = document.getElementsByTagName("DIV");
        for (var i = 0; i < containers.length; i++)
            if (containers[i].getAttribute("vId"))
                embed(containers[i],containers[i].getAttribute("vId"), containers[i].getAttribute("vWidth"), containers[i].getAttribute("vHeight"));
    };
    var win = self;
    var doc = win.document;
    if (typeof win.addEventListener != "undefined") {
        win.addEventListener("load", init, false);
    }
    else if (typeof doc.addEventListener != "undefined") {
        doc.addEventListener("load", init, false);
    }
    else if (typeof win.attachEvent != "undefined") {
        win.attachEvent("onload", init);
    }
    else if (typeof win["onload"] == "function") {
        var fnOld = win["onload"];
        win["onload"] = function (Ev) {
            if (!Ev && window.event) Ev = window.event;
            fnOld(Ev);
            init();
        };
    }
    else {
        win["on" + eventName] = init;
    }

})();

