﻿//Silverlight.js v2.0.30511.0
if (!window.Silverlight) window.Silverlight = {}; Silverlight._silverlightCount = 0; Silverlight.__onSilverlightInstalledCalled = false; Silverlight.fwlinkRoot = "http://go2.microsoft.com/fwlink/?LinkID="; Silverlight.__installationEventFired = false; Silverlight.onGetSilverlight = null; Silverlight.onSilverlightInstalled = function() { window.location.reload(false) }; Silverlight.isInstalled = function(b) { if (b == undefined) b = null; var a = false, m = null; try { var i = null, j = false; if (window.ActiveXObject) try { i = new ActiveXObject("AgControl.AgControl"); if (b === null) a = true; else if (i.IsVersionSupported(b)) a = true; i = null } catch (l) { j = true } else j = true; if (j) { var k = navigator.plugins["Silverlight Plug-In"]; if (k) if (b === null) a = true; else { var h = k.description; if (h === "1.0.30226.2") h = "2.0.30226.2"; var c = h.split("."); while (c.length > 3) c.pop(); while (c.length < 4) c.push(0); var e = b.split("."); while (e.length > 4) e.pop(); var d, g, f = 0; do { d = parseInt(e[f]); g = parseInt(c[f]); f++ } while (f < e.length && d === g); if (d <= g && !isNaN(d)) a = true } } } catch (l) { a = false } return a }; Silverlight.WaitForInstallCompletion = function() { if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) { try { navigator.plugins.refresh() } catch (a) { } if (Silverlight.isInstalled(null) && !Silverlight.__onSilverlightInstalledCalled) { Silverlight.onSilverlightInstalled(); Silverlight.__onSilverlightInstalledCalled = true } else setTimeout(Silverlight.WaitForInstallCompletion, 3e3) } }; Silverlight.__startup = function() { navigator.plugins.refresh(); Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null); if (!Silverlight.isBrowserRestartRequired) { Silverlight.WaitForInstallCompletion(); if (!Silverlight.__installationEventFired) { Silverlight.onInstallRequired(); Silverlight.__installationEventFired = true } } else if (window.navigator.mimeTypes) { var b = navigator.mimeTypes["application/x-silverlight-2"], c = navigator.mimeTypes["application/x-silverlight-2-b2"], d = navigator.mimeTypes["application/x-silverlight-2-b1"], a = d; if (c) a = c; if (!b && (d || c)) { if (!Silverlight.__installationEventFired) { Silverlight.onUpgradeRequired(); Silverlight.__installationEventFired = true } } else if (b && a) if (b.enabledPlugin && a.enabledPlugin) if (b.enabledPlugin.description != a.enabledPlugin.description) if (!Silverlight.__installationEventFired) { Silverlight.onRestartRequired(); Silverlight.__installationEventFired = true } } if (!Silverlight.disableAutoStartup) if (window.removeEventListener) window.removeEventListener("load", Silverlight.__startup, false); else window.detachEvent("onload", Silverlight.__startup) }; if (!Silverlight.disableAutoStartup) if (window.addEventListener) window.addEventListener("load", Silverlight.__startup, false); else window.attachEvent("onload", Silverlight.__startup); Silverlight.createObject = function(m, f, e, k, l, h, j) { var d = {}, a = k, c = l; d.version = a.version; a.source = m; d.alt = a.alt; if (h) a.initParams = h; if (a.isWindowless && !a.windowless) a.windowless = a.isWindowless; if (a.framerate && !a.maxFramerate) a.maxFramerate = a.framerate; if (e && !a.id) a.id = e; delete a.ignoreBrowserVer; delete a.inplaceInstallPrompt; delete a.version; delete a.isWindowless; delete a.framerate; delete a.data; delete a.src; delete a.alt; if (Silverlight.isInstalled(d.version)) { for (var b in c) if (c[b]) { if (b == "onLoad" && typeof c[b] == "function" && c[b].length != 1) { var i = c[b]; c[b] = function(a) { return i(document.getElementById(e), j, a) } } var g = Silverlight.__getHandlerName(c[b]); if (g != null) { a[b] = g; c[b] = null } else throw "typeof events." + b + " must be 'function' or 'string'"; } slPluginHTML = Silverlight.buildHTML(a) } else slPluginHTML = Silverlight.buildPromptHTML(d); if (f) f.innerHTML = slPluginHTML; else return slPluginHTML }; Silverlight.buildHTML = function(a) { var b = []; b.push('<object type="application/x-silverlight" data="data:application/x-silverlight,"'); if (a.id != null) b.push(' id="' + Silverlight.HtmlAttributeEncode(a.id) + '"'); if (a.width != null) b.push(' width="' + a.width + '"'); if (a.height != null) b.push(' height="' + a.height + '"'); b.push(" >"); delete a.id; delete a.width; delete a.height; for (var c in a) if (a[c]) b.push('<param name="' + Silverlight.HtmlAttributeEncode(c) + '" value="' + Silverlight.HtmlAttributeEncode(a[c]) + '" />'); b.push("</object>"); return b.join("") }; Silverlight.createObjectEx = function(b) { var a = b, c = Silverlight.createObject(a.source, a.parentElement, a.id, a.properties, a.events, a.initParams, a.context); if (a.parentElement == null) return c }; Silverlight.buildPromptHTML = function(b) { var a = "", d = Silverlight.fwlinkRoot, c = b.version; if (b.alt) a = b.alt; else { if (!c) c = ""; a = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"; a = a.replace("{1}", c); a = a.replace("{2}", d + "108181") } return a }; Silverlight.getSilverlight = function(e) { if (Silverlight.onGetSilverlight) Silverlight.onGetSilverlight(); var b = "", a = String(e).split("."); if (a.length > 1) { var c = parseInt(a[0]); if (isNaN(c) || c < 2) b = "1.0"; else b = a[0] + "." + a[1] } var d = ""; if (b.match(/^\d+\056\d+$/)) d = "&v=" + b; Silverlight.followFWLink("149156" + d) }; Silverlight.followFWLink = function(a) { top.location = Silverlight.fwlinkRoot + String(a) }; Silverlight.HtmlAttributeEncode = function(c) { var a, b = ""; if (c == null) return null; for (var d = 0; d < c.length; d++) { a = c.charCodeAt(d); if (a > 96 && a < 123 || a > 64 && a < 91 || a > 43 && a < 58 && a != 47 || a == 95) b = b + String.fromCharCode(a); else b = b + "&#" + a + ";" } return b }; Silverlight.default_error_handler = function(e, b) { var d, c = b.ErrorType; d = b.ErrorCode; var a = "\nSilverlight error message     \n"; a += "ErrorCode: " + d + "\n"; a += "ErrorType: " + c + "       \n"; a += "Message: " + b.ErrorMessage + "     \n"; if (c == "ParserError") { a += "XamlFile: " + b.xamlFile + "     \n"; a += "Line: " + b.lineNumber + "     \n"; a += "Position: " + b.charPosition + "     \n" } else if (c == "RuntimeError") { if (b.lineNumber != 0) { a += "Line: " + b.lineNumber + "     \n"; a += "Position: " + b.charPosition + "     \n" } a += "MethodName: " + b.methodName + "     \n" } alert(a) }; Silverlight.__cleanup = function() { for (var a = Silverlight._silverlightCount - 1; a >= 0; a--) window["__slEvent" + a] = null; Silverlight._silverlightCount = 0; if (window.removeEventListener) window.removeEventListener("unload", Silverlight.__cleanup, false); else window.detachEvent("onunload", Silverlight.__cleanup) }; Silverlight.__getHandlerName = function(b) { var a = ""; if (typeof b == "string") a = b; else if (typeof b == "function") { if (Silverlight._silverlightCount == 0) if (window.addEventListener) window.addEventListener("onunload", Silverlight.__cleanup, false); else window.attachEvent("onunload", Silverlight.__cleanup); var c = Silverlight._silverlightCount++; a = "__slEvent" + c; window[a] = b } else a = null; return a }; Silverlight.onRequiredVersionAvailable = function() { }; Silverlight.onRestartRequired = function() { }; Silverlight.onUpgradeRequired = function() { }; Silverlight.onInstallRequired = function() { }; Silverlight.IsVersionAvailableOnError = function(d, a) { var b = false; try { if (a.ErrorCode == 8001 && !Silverlight.__installationEventFired) { Silverlight.onUpgradeRequired(); Silverlight.__installationEventFired = true } else if (a.ErrorCode == 8002 && !Silverlight.__installationEventFired) { Silverlight.onRestartRequired(); Silverlight.__installationEventFired = true } else if (a.ErrorCode == 5014 || a.ErrorCode == 2106) { if (Silverlight.__verifySilverlight2UpgradeSuccess(a.getHost())) b = true } else b = true } catch (c) { } return b }; Silverlight.IsVersionAvailableOnLoad = function(b) { var a = false; try { if (Silverlight.__verifySilverlight2UpgradeSuccess(b.getHost())) a = true } catch (c) { } return a }; Silverlight.__verifySilverlight2UpgradeSuccess = function(d) { var c = false, b = "2.0.31005", a = null; try { if (d.IsVersionSupported(b + ".99")) { a = Silverlight.onRequiredVersionAvailable; c = true } else if (d.IsVersionSupported(b + ".0")) a = Silverlight.onRestartRequired; else a = Silverlight.onUpgradeRequired; if (a && !Silverlight.__installationEventFired) { a(); Silverlight.__installationEventFired = true } } catch (e) { } return c }

window.size = function() {
    
    var w = 0;
    var h = 0;
    
    //IE
    if (!window.innerWidth) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
        }
        //quirks mode
        else {
            w = document.body.clientWidth;
            h = document.body.clientHeight;
        }
    }
    
    //w3c
    else {
        w = window.innerWidth;
        h = window.innerHeight;
    }

    return { width: w, height: h };
}

window.center = function() {
    
    var hWnd = (arguments[0] != null) ? arguments[0] : { width: 0, height: 0 };
    var _x = 0;
    var _y = 0;
    var offsetX = 0;
    var offsetY = 0;
    
    //IE
    if (!window.pageYOffset) {
        //strict mode
        if (!(document.documentElement.scrollTop == 0)) {
            offsetY = document.documentElement.scrollTop;
            offsetX = document.documentElement.scrollLeft;
        }
        //quirks mode
        else {
            offsetY = document.body.scrollTop;
            offsetX = document.body.scrollLeft;
        }
    }
    
    //w3c
    else {
        offsetX = window.pageXOffset;
        offsetY = window.pageYOffset;
    }
    
    _x = ((this.size().width - hWnd.width) / 2) + offsetX;
    _y = ((this.size().height - hWnd.height) / 2) + offsetY;
    
    return { x: _x, y: _y };
}

function httpTV_GetElement(id, top, left, width, height, url, repeat) {

    dv = document.createElement('div');
    dv.setAttribute('id', id);
    dv.innerHTML = '&nbsp;';
//    dv.style.behavior = 'url(http://vv.autoplay.co.nz/themes/grey/iepngfix.htc)'

    dv.style.position = 'absolute';
    dv.style.top = top + 'px';
    dv.style.left = left + 'px';

    if (width != undefined) { dv.style.width = width + 'px' };
    if (height != undefined) { dv.style.height = height + 'px' };
    if (url != undefined) { dv.style.backgroundImage = 'url(' + url + ')' };
    if (repeat != undefined) { dv.style.backgroundRepeat = repeat } else { dv.style.backgroundRepeat = 'no-repeat' };

    return dv;
}

function httpTV_Style(el, style) {

    var styleValue = "";
    
    if (document.defaultView && document.defaultView.getComputedStyle) {
        var css = document.defaultView.getComputedStyle(el, null);
        styleValue = css ? css.getPropertyValue(style) : null;
    }
    
    else if (el.currentStyle) {
        style = style.replace(/\-(\w)/g, function(strMatch, p1) {
            return p1.toUpperCase();
        });
        styleValue = el.currentStyle[style];
    }
    
    return styleValue;
}

function httpTV_Draggable(el) {

    var httpPlayer = document.getElementById('httpTV_Player')
    
    var xDelta = 0, yDelta = 0;
    var xStart = 0, yStart = 0;

    function httpTV_EndDrag() {
        document.onmouseup = null;
        document.onmousemove = null;
    }
    
    function httpTV_Drag(e) {
        e = e || window.event;
        xDelta = xStart - parseInt(e.clientX);
        yDelta = yStart - parseInt(e.clientY);
        xStart = parseInt(e.clientX);
        yStart = parseInt(e.clientY);
        var x = parseInt(httpPlayer.style.left) - xDelta; if (x < 10) { x = 10 };
        var y = parseInt(httpPlayer.style.top) - yDelta; if (y < 10) { y = 10 };
        httpPlayer.style.top = y + 'px';
        httpPlayer.style.left = x + 'px';
    }
    
    function httpTV_StartDrag(e) {
        e = e || window.event;
        xStart = parseInt(e.clientX);
        yStart = parseInt(e.clientY);
        httpPlayer.style.top = parseInt(httpTV_Style(httpPlayer, 'top')) + 'px';
        httpPlayer.style.left = parseInt(httpTV_Style(httpPlayer, 'left')) + 'px';
        document.onmouseup = httpTV_EndDrag;
        document.onmousemove = httpTV_Drag;
        return false;
    }

    el.onmousedown = httpTV_StartDrag;
    
}

function httpTV_Video() {

    this.width = 440;
    this.height = 470;
    this.top = 10;
    this.left = 10;
    
    this.portal = 0;
    this.portal_id = 0;
    this.playlist = 'none';
    this.title = "httpTV Virtual video";
    this.logo = '';
    this.theme = 'http://vv.autoplay.co.nz/themes/grey/'
    
    this.Play = httpTV_Play;
}

function httpTV_Play() {

    var point = window.center({ width: 1, height: 1 });
    
    var x = point.x - this.width / 2;
    var y = point.y - this.height / 2;

    if (y > this.top) { this.top = y };
    if (x > this.left) { this.left = x };

    var e1 = httpTV_GetElement('httpTV_Container', 0, 0);
    var e2 = httpTV_GetElement('httpTV_Player', this.top, this.left);
    var e3 = httpTV_GetElement('httpTV_TopLeft', 0, 0, 9, 28, this.theme + 'top-left.png');
    var e4 = httpTV_GetElement('httpTV_Title', 0, 9, 440, 28, this.theme + 'top-middle.png', 'repeat-x');
    var e5 = httpTV_GetElement('httpTV_TopLeft', 0, 449, 15, 28, this.theme + 'top-right.png')
    var e6 = httpTV_GetElement('httpTV_Left', 28, 0, 9, 470, this.theme + 'left.png', 'repeat-y');
    var e7 = httpTV_GetElement('httpTV_Content', 28, 9, 440, 470);
    var e8 = httpTV_GetElement('httpTV_Right', 28, 449, 15, 470, this.theme + 'right.png', 'repeat-y');
    var e9 = httpTV_GetElement('httpTV_BottomLeft', 498, 0, 15, 28, this.theme + 'bottom-left.png');
    var e10 = httpTV_GetElement('httpTV_BottomMiddle', 498, 9, 440, 28, this.theme + 'bottom-middle.png', 'repeat-x');
    var e11 = httpTV_GetElement('httpTV_BottomRight', 498, 449, 15, 28, this.theme + 'bottom-right.png');
    var e12 = httpTV_GetElement('httpTV_Close', 10, 442, 15, 9);

    e1.style.width = '100%';
    e1.style.height = '100%';
    e1.style.display = 'block';
    e1.style.backgroundColor = '#C7C7C7';
    e1.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)';
    e1.style.opacity = '0.5';
    e1.style.zIndex = '9998';

    e2.style.backgroundColor = '#C7C7C7';
    e2.style.zIndex = '9999';

    e4.style.cursor = 'move';
    e4.style.fontFamily = 'Calibri,Verdana,Helvitica';
    e4.style.fontSize = 'medium';
    e4.style.fontWeight = 'bold';
    e4.style.color = '#000000';
    e4.style.textAlign = 'center';
    e4.style.paddingTop = '5px';
    e4.innerHTML = this.title

    e7.style.backgroundColor = '#C7C7C7';

    e12.innerHTML = '<a style="display:block;text-decoration:none;background:url(' + this.theme + 'close2.png) no-repeat;" href="javascript:CloseVideo();"><span>&nbsp;</span></a>';

    document.body.appendChild(e1)
    document.body.appendChild(e2)
    
    e2.appendChild(e3)
    e2.appendChild(e4)
    e2.appendChild(e5)
    e2.appendChild(e6)
    e2.appendChild(e7)
    e2.appendChild(e8)
    e2.appendChild(e9)
    e2.appendChild(e10)
    e2.appendChild(e11)
    e2.appendChild(e12)

    new httpTV_Draggable(document.getElementById('httpTV_Title'));

    var html1 = '<object id="httpTV_Silverlight" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">'
        + '<param name="source" value="http://vv.autoplay.co.nz/ClientBin/httpTV.xap"/>'
      //+ '<param name="source" value="ClientBin/httpTV.xap"/>'
      //+ '<param name="onError" value="httpTV_SilverlightError" />'
        + '<param name="background" value="#C7C7C7" />'
        + '<param name="initParams" value="portal=' + this.portal + ',portal_id=' + this.portal_id + ',playlist=' + this.playlist + ',logo=' + this.logo + '" />'
        + '<param name="windowless" value="true" />'
        + '<param name="minRuntimeVersion" value="3.0.40624.0" />'
        + '<param name="autoUpgrade" value="true" />'
        + '<param name="enableHtmlAccess" value="true" />'
      //+ '<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">'
      //+ '<br /><br /><br /><img src="http://vv.autotv.co.nz/graphics/silverlight.jpg" alt="Get Microsoft Silverlight" style="border-style:none"/>'
      //+ '<br /><br />You will need to install Silverlight to view this video'
      //+ '<br /><br />Click Here To Continue'
      //+ '</a><br />'
        + '<iframe frameborder="0" marginwidth="0" style="height: 100%; width: 100%; top: 0px; left: 0px;" scrolling="no" src="http://vv.autoplay.co.nz/video.aspx?portal=' + this.portal + '&portal_id=' + this.portal_id + '&id=' + this.playlist + '"></iframe>'
        + '</object>';

    var html2 = '<iframe frameborder="0" marginwidth="0" style="height: 100%; width: 100%; top: 0px; left: 0px;" scrolling="no" src="http://vv.autoplay.co.nz/video.aspx?portal=' + this.portal + '&portal_id=' + this.portal_id + '&id=' + this.playlist + '"></iframe>'

    document.getElementById('httpTV_Content').innerHTML = html1;

    return true

}

var myPlayer = httpTV_Video;

function CloseVideo() { document.getElementById('httpTV_Content').innerHTML = '&nbsp'; document.body.removeChild(document.getElementById('httpTV_Player')); document.body.removeChild(document.getElementById('httpTV_Container')); }

function ShowVideo(portal, portal_id, playlist, title, logo, theme) {

    myPlayer = new httpTV_Video
    
    myPlayer.portal = portal;
    myPlayer.portal_id = portal_id;
    myPlayer.playlist = playlist;

    if (title != undefined) { myPlayer.title = title; };
    if (logo != undefined) { myPlayer.logo = logo; };
    if (theme != undefined) { myPlayer.theme = theme; };

    myPlayer.Play();

}

function MoveVideo(t, l) { try { var httpPlayer = document.getElementById('httpTV_Player'); httpPlayer.style.top = t + 'px'; httpPlayer.style.left = l + 'px'; } catch (ex) { } }
