﻿// JScript File

// Passed in from document:

// gActiveChannel
// gActiveContent
// gActiveSkin
// ResourceUrl
// MediaServerDisabled
// BandwidthCheckDisabled
// ShowContent
// gSchedUrl
// gHostBase

// Global Vars

var g_BitrateInUse = 512;
var g_DetectedBitrate = 0;

var g_CurrentContentID = '';
var g_CurrentChannelID = '';
var g_CurrentSkinID = '';
var g_CurrentContentType = '';
var g_CurrentContentTitle = '';
var g_CurrentContentDuration = 0;
var g_CurrentContentItem = null;

var g_FirstGuideSchedUrl = '';
var g_LastGuideSchedUrl = '';

var g_LastScheduleDownload = 0;

var g_CurrentContentScheduleItem = '';
var g_CurrentContentTimeID = 0;

var g_CurrentRssItemDuration = 0;
var g_CurrentRssSelectedColor = '';
var g_CurrentRssTotalItems = 0;

var g_CurrentTextlinesDuration = 0;
var g_CurrentTextlinesTotalItems = 0;

var g_CurrentGuideStartTime = 0;

var g_FlipperTime = 0;

var g_ScreenWidth = 640;
var g_ScreenHeight = 360;

var g_GuideVisible = 120;
var g_GuideWidth = 673;

var g_GuideCurrentlyShowing = ''; ;

var g_LastTimeOffset = 0;
var g_WMStreamServer = 'webstream1.solus.co.uk';
var g_FLVStreamServer = 'tv.solus.co.uk';
var g_ContentServer = 'contentsynch.prime-space.com';

var flashCheckTimer = 0;
var flashVidCheckTimer = 0;
var timeFlipTimer = 0;
var videoCheckTimer = 0;
var rssGetTimer = 0;
var textGetTimer = 0;

var g_ItemIDPadding = ('itemdefinition_00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000_').length;

var g_HasFlash = false;
var g_HasWMP = false;
var g_HasXML = false;
var g_IsIE = false;
var g_HasHTML5 = false;
var g_UsingHTML5 = false;

var g_ForceFLV = false;
var g_ForceWMP = false;
var g_ForceHTML5 = false;

var g_UseYouTube = false;

var g_LoadStart = 0;
var g_ProgressMade = false;

var g_FlashFullScreen = false;
var g_WMVFullScreen = false;

var Schedule = null;
var ContentItems = null;

var ZoneSchedule = null;
var ZoneContentHolder = null;
var g_audioAllowed = false;

var ContentItem = null;

var ytplayer = null;

function LoadSite() {

    InitialiseControls();
    DoBrowserCheck();

    g_CurrentChannelID = gActiveChannel;
    g_CurrentSkinID = gActiveSkin;
    g_LastGuideSchedUrl = gSchedUrl;
    g_FirstGuideSchedUrl = gSkinSchedUrl;

    //(g_IsIE && g_HasWMP)
    if ((g_HasHTML5) || (g_HasFlash)) {
        if (BandwidthCheckDisabled == '1') {
            ParseGuide(2000);
        }
        else {
            BitrateTest_StartTest(ParseGuide);
        }
    }
    else {
        ShowNotSupported();
    }
}

function SetupSettingsPanel() {

    var fmtList = getObj('SettingsFormatList');
    var bwList = getObj('SettingsBandwidthList');

    fmtList.innerHTML = '';
    bwList.innerHTML = '';

    //var isFlash = g_ForceFLV || !g_HasWMP;
    var isFlash = g_HasFlash && !g_ForceHTML5;
    var isWMP = g_HasWMP && !g_ForceFLV;

    var isHTML5 = g_HasHTML5 && !g_ForceFLV && !isFlash;

    //    if (g_HasWMP && g_IsIE)
    //    {
    //        fmtList.innerHTML += '<input type="radio" name="videoformat" value="WMV" id="videoformat_WMV"' + (isWMP ? 'checked="checked"' : '') + ' /><label for="videoformat_WMV">Windows Media</label><br />'
    //    }

    if (g_HasFlash) {
        fmtList.innerHTML += '<input type="radio" name="videoformat" value="FLV" id="videoformat_FLV" ' + (isFlash ? 'checked="checked"' : '') + ' /><label for="videoformat_FLV">Flash Video</label><br />';
    }

    if (g_HasHTML5) {
        fmtList.innerHTML += '<input type="radio" name="videoformat" value="HTML5" id="videoformat_HTML5" ' + (isHTML5 ? 'checked="checked"' : '') + ' /><label for="videoformat_HTML5">HTML5 Video</label><break />';
    }

    var currLevel = GetStreamLevelInUse();
    var detLevel = GetDetectedStreamLevel();
    var actualRate = g_DetectedBitrate;

    for (var rateIndex = 0; rateIndex < AvailableStreams.length; rateIndex++) {
        var br = AvailableStreams[rateIndex];

        var bitStyle = ((br <= detLevel) ? 'BitrateGood' : ((br <= actualRate) ? 'BitrateWarning' : 'BitrateCritical'));
        var bitSelected = ((br == currLevel) ? 'checked="checked"' : '');
        var bitRecommended = ((br == detLevel) ? ' (Recommended)' : '');

        var rateString = '<input type="radio" name="videobw" value="' + br + '" id="videobw_' + br + '" ' + bitSelected + ' /><label for="videobw_' + br + '" class="' + bitStyle + '"> ' + br + ' Kbps' + bitRecommended + '</label><br />'
        bwList.innerHTML += rateString;
    }

    getObj('spnBWResult').innerHTML = actualRate + ' kbps';

}

function SaveSettings() {
    if (getObj('videoformat_FLV') != null && getObj('videoformat_FLV').checked) {
        g_ForceFLV = true;
        g_ForceWMP = false;
        g_ForceHTML5 = false;
    }
    else if (getObj('videoformat_HTML5') != null && getObj('videoformat_HTML5').checked) {
        g_ForceHTML5 = true;
        g_ForceFLV = false;
        g_ForceWMP = false;
    }
    //    else if (getObj('videoformat_WMV') != null && getObj('videoformat_WMV').checked)
    //    {
    //        g_ForceFLV = false;
    //        g_ForceWMP = true;
    //    }

    var bwList = getObj('SettingsBandwidthList');
    for (var index = 0; index < bwList.childNodes.length; index++) {
        var item = bwList.childNodes[index];
        if (item.name != null && item.name == 'videobw' && item.checked) {
            g_BitrateInUse = item.value;
        }
    }

    itemclick(g_CurrentContentID);
    ShowGuidePane();

}

function ReCheckBW() {
    EndContent();
    getObj('MainPanel').style.display = 'none';

    getObj('spnBWResult').innerHTML = '';
    getObj('BandCheckPanel').style.display = '';
    SetPreloadTitle('Checking Bandwidth');


    if (BandwidthCheckDisabled == '1') {
        PostReCheck(1800);
    }
    else {
        BitrateTest_StartTestWithOverride(PostReCheck);
    }
}

function PostReCheck(bitrate) {

    g_DetectedBitrate = bitrate;
    g_BitrateInUse = GetDetectedStreamLevel();
    SetPreloadTitle('Bandwidth: ' + bitrate + ' kbps');

    ShowMainPanel();
    ShowSettings();
    itemclick(g_CurrentContentID);

}

function ParseGuide(bitrate) {
    g_DetectedBitrate = bitrate;
    g_BitrateInUse = GetDetectedStreamLevel();
    SetPreloadTitle('Bandwidth: ' + bitrate + ' kbps');
    SetTitle('Bandwidth: ' + bitrate + ' kbps');

    if (g_HasXML) {
        DownloadSchedule();
        RevertFeedLinks();
        ShowMainPanel();
        if (Schedule != null && Schedule.childNodes.length > 0) {
            itemclick(Schedule.childNodes.item(0).getAttribute('ID'));
        }
        else {
            var GuideC = document.getElementById('V3GuideContent');
            GuideC.innerHTML = 'Channels currently off-air';

            var infoBar = document.getElementById('V3InfoPane');
            infoBar.innerHTML = 'Channels currently off-air';

            HideAllVideoControls();
            SetTitle('Off-air');
        }
    }
    else {
        ShowMainPanel();
        //TODO: Put an "Upgrade your browser" message on
        var GuideC = document.getElementById('V3GuideContent');
        GuideC.innerHTML = 'Channels currently off-air';

        var infoBar = document.getElementById('V3InfoPane');
        infoBar.innerHTML = 'Channels currently off-air';

        HideAllVideoControls();
        SetTitle('Browser upgrade required');
    }

}

function RevertFeedLinks() {
    getObj('PodLinkItem').href = BasePodLocation + 'Rss.aspx?sid=' + g_CurrentSkinID;
    getObj('FeedLinkItem').href = 'Rss.aspx?sid=' + g_CurrentSkinID;
}

function ModifyFeedLinks(chid) {
    getObj('PodLinkItem').href = BasePodLocation + 'Rss.aspx?sid=' + g_CurrentSkinID + '&chid=' + chid;
    getObj('FeedLinkItem').href = 'Rss.aspx?sid=' + g_CurrentSkinID + '&chid=' + chid;
}

function BackToMainContent() {
    HidePanes();
    gSchedUrl = g_FirstGuideSchedUrl;

    g_LastGuideSchedUrl = gSchedUrl;
    DownloadSchedule();
    if (Schedule != null && Schedule.childNodes.length > 0) {
        itemclick(Schedule.childNodes.item(0).getAttribute('ID'));
    }

    RevertFeedLinks();
    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_Act.png';
    getObj('V3GuideContent').className = 'GuideWithoutSearch';
}

function ChangeChannel(id) {
    HidePanes();
    gSchedUrl = 'Schedule.aspx?sid=' + g_CurrentSkinID + '&chid=' + id + '&ctid=00000000-0000-0000-0000-000000000000';
    ModifyFeedLinks(id);
    g_LastGuideSchedUrl = gSchedUrl;
    DownloadSchedule();
    if (Schedule != null && Schedule.childNodes.length > 0) {
        itemclick(Schedule.childNodes.item(0).getAttribute('ID'));
    }
    else {
        ShowEmptyGuide();
    }

    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_Act.png';
    getObj('V3GuideContent').className = 'GuideWithoutSearch';
}

function ShowEmptyGuide() {
    var nextLine = '';
    var GuideC = getObj('V3GuideContent');

    GuideC.innerHTML = 'No items found';
}

function ShowMostRecent() {
    HidePanes();
    gSchedUrl = 'ScheduleDynamic.aspx?sid=' + g_CurrentSkinID + '&type=recent';
    RevertFeedLinks();
    g_LastGuideSchedUrl = gSchedUrl;
    DownloadSchedule();
    if (Schedule != null && Schedule.childNodes.length > 0) {
        itemclick(Schedule.childNodes.item(0).getAttribute('ID'));
    }

    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_Act.png';
    getObj('V3GuideContent').className = 'GuideWithoutSearch';
}

function ShowMostViewed() {
    HidePanes();
    gSchedUrl = 'ScheduleDynamic.aspx?sid=' + g_CurrentSkinID + '&type=mostviewed';
    RevertFeedLinks();
    g_LastGuideSchedUrl = gSchedUrl;
    DownloadSchedule();

    if (Schedule != null && Schedule.childNodes.length > 0) {
        itemclick(Schedule.childNodes.item(0).getAttribute('ID'));
    }

    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_Act.png';
    getObj('V3GuideContent').className = 'GuideWithoutSearch';
}

function ShowSearch() {
    HidePanes();
    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideContent').className = 'GuideWithSearch';
    getObj('V3SearchPane').style.display = 'inline';
    getObj('V3SearchButton').src = ResourceUrl + 'PSTV-Search_Act.png';
    getObj('SearchBar').value = '';
    ClearGuide();
    var GuideC = getObj('V3GuideContent');
    GuideC.innerHTML = 'Please enter keywords above';
}

function ShowSettings() {
    HidePanes();
    SetupSettingsPanel();
    getObj('V3SettingsPane').style.display = 'inline';
    getObj('V3SettingsButton').src = ResourceUrl + 'PSTV-Settings_Act.png';
}

function ShowGuidePane() {
    HidePanes();
    gSchedUrl = g_LastGuideSchedUrl;
    DownloadSchedule();
    PopulateGuide();
    HighlightCurrentItem();

    getObj('V3GuideContent').style.display = 'inline';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_Act.png';
    getObj('V3GuideContent').className = 'GuideWithoutSearch';
}

function ShowFeedback() {
    HidePanes();
    getObj('V3FeedbackPane').style.display = 'inline';
    getObj('V3FeedbackButton').src = ResourceUrl + 'PSTV-Feedback_Act.png';
}

function HidePanes() {

    getObj('V3FeedbackPane').style.display = 'none';
    getObj('V3FeedbackButton').src = ResourceUrl + 'PSTV-Feedback_En.png';
    getObj('V3GuideContent').style.display = 'none';
    getObj('V3GuideButton').src = ResourceUrl + 'PSTV-Guide_En.png';
    getObj('V3SettingsPane').style.display = 'none';
    getObj('V3SettingsButton').src = ResourceUrl + 'PSTV-Settings_En.png';
    getObj('V3SearchPane').style.display = 'none';
    getObj('V3SearchButton').src = ResourceUrl + 'PSTV-Search_En.png';
}

function DoSearch() {
    var searchterm = getObj('SearchBar').value;
    if (searchterm.length >= 2) {
        gSchedUrl = 'Search.aspx?sid=' + g_CurrentSkinID + '&q=' + searchterm;
        DownloadSchedule();
        PopulateGuide();

        HighlightCurrentItem();

    }
    else {
        ClearGuide();
        var GuideC = getObj('V3GuideContent');

        GuideC.innerHTML = 'Please enter keywords above';


    }
}

function DownloadSchedule() {
    var xm = null;
    if (window.XMLHttpRequest) {
        xm = new XMLHttpRequest();
    }
    else {
        xm = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xm.open("GET", gSchedUrl + '&bandwidth=' + g_DetectedBitrate + '&random=' + (new Date()).getTime(), false);
    xm.send(null);

    if ((xm.responseXML != null) && (xm.responseXML.documentElement != null) && (xm.responseXML.documentElement.nodeName == 'Network')) {
        if (xm.responseXML.documentElement.getElementsByTagName('Schedule') != null)
            Schedule = xm.responseXML.documentElement.getElementsByTagName('Schedule').item(0);
        if (xm.responseXML.documentElement.getElementsByTagName('Content') != null)
            ContentItems = xm.responseXML.documentElement.getElementsByTagName('Content').item(0);

        g_WMStreamServer = xm.responseXML.documentElement.getAttribute('WMStreamServer');
        g_FLVStreamServer = xm.responseXML.documentElement.getAttribute('FLVStreamServer');

        g_LastScheduleDownload = Math.floor(new Date().valueOf() / 1000);
    }
}

function DownloadZoneSchedule() {
    var xm = null;
    if (window.XMLHttpRequest) {
        xm = new XMLHttpRequest();
    }
    else {
        xm = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xm.open("GET", zoneSchedUrl, false);
    xm.send(null);

    if ((xm.responseXML != null) && (xm.responseXML.documentElement != null) && (xm.responseXML.documentElement.nodeName == 'Zone')) {
        if (xm.responseXML.documentElement.getElementsByTagName('Schedule') != null) {
            ZoneSchedule = xm.responseXML.documentElement.getElementsByTagName('Schedule').item(0);
        }

        g_ContentServer = xm.responseXML.documentElement.getAttribute('ContentServer');
        g_WMStreamServer = xm.responseXML.documentElement.getAttribute('WMStreamServer');
        g_FLVStreamServer = xm.responseXML.documentElement.getAttribute('FLVStreamServer');
    }
}

function getContentDetails() {
    var xm = null;
    if (window.XMLHttpRequest) {
        xm = new XMLHttpRequest();
    }
    else {
        xm = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xm.open("GET", contentDetailsUrl, false);
    xm.send(null);

    if ((xm.responseXML != null) && (xm.responseXML.documentElement != null)) { //&& (xm.responseXML.documentElement.nodeName == 'ContentItem')) {
        ContentItem = xm.responseXML.documentElement;

        g_ContentServer = xm.responseXML.documentElement.getAttribute('ContentServer');
        g_WMStreamServer = xm.responseXML.documentElement.getAttribute('WMStreamServer');
        g_FLVStreamServer = xm.responseXML.documentElement.getAttribute('FLVStreamServer');
    }
}

function ClearGuide() {
    var GuideC = document.getElementById('V3GuideContent');
    GuideC.innerHTML = '';
}

// Given the Schedule document, create the TV Guide
function PopulateGuide() {
    var nextLine = '';
    var GuideC = getObj('V3GuideContent');

    GuideC.innerHTML = '';

    var nowtime = Math.floor(new Date().valueOf() / 1000);

    if ((nowtime - g_LastScheduleDownload) > (30 * 60)) {
        DownloadSchedule();
    }

    if ((Schedule != null) && (Schedule.childNodes != null) && (Schedule.childNodes.length > 0)) {
        var thisChannel = Schedule;
        var GuideCode = '';

        for (var j = 0; j < thisChannel.childNodes.length; j++) {
            var thisItem = thisChannel.childNodes.item(j);
            var thisID = thisItem.getAttribute('ID');
            var thisTitle = thisItem.getAttribute('Title');
            var thisDuration = thisItem.getAttribute('Duration');
            var thisDescription = thisItem.getAttribute('Description');
            var ItemCode = '<div onselect="return false;" onselectstart="return false;" class="OuterGuideItem" id="outeritemdefinition_' + thisID + '"><img class="GuideItemTopSlice" width="227" height="5" src="' + ResourceUrl + 'PSTV-GuideItem_Top_En.png" border="0" /><div id="itemdefinition_' + thisID + '" class="ContentItem" onclick="itemclick(\'' + thisID + '\');" onmouseover="hover(this);" onmouseout="unhover(this);"" ><div class="ContentInner"><div class="ContentDescription"><img border="1" align="left" class="ContentThumb" src="thumbimage.aspx?ctid=' + thisID + '" width="80" height="48" /><span class="ContentTitle">' + thisTitle + '</span><br />' + thisDescription + '</div></div></div><img class="GuideItemBottomSlice" width="227" height="16" src="' + ResourceUrl + 'PSTV-GuideItem_Bottom_En.png" border="0" /></div>';

            GuideCode += ItemCode;

        }
        GuideC.innerHTML = GuideCode;
    }
    else {
        GuideC.innerHTML = 'No items found';
    }
}

function hover(itemobj) {
    if (itemobj.className == 'ContentItem') {
        itemobj.className = 'HoverContentItem';
    }
    else if (itemobj.className == 'EmbedContentItem') {
        itemobj.className = 'EmbedHoverContentItem';
        var parentdiv = document.getElementById('outer' + itemobj.id);
        parentdiv.style.backgroundColor = '#ffffff';
    }
}

function unhover(itemobj) {
    if (itemobj.className == 'HoverContentItem') {
        itemobj.className = 'ContentItem';
    }
    else if (itemobj.className == 'EmbedHoverContentItem') {
        itemobj.className = 'EmbedContentItem';
        var parentdiv = document.getElementById('outer' + itemobj.id);
        parentdiv.style.backgroundColor = '';
    }
}

function RWItem() {
    EndContent();
    GetPrevItem();
}

function FFItem() {
    EndContent();
    GetNextItem();
}

function zoneItemClick(ctid) {
    var thisItem = null;
    if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ZoneSchedule.childNodes.length; ctIndex++) {
            if (ZoneSchedule.childNodes.item(ctIndex).getAttribute('CTID') == ctid) {
                thisItem = ZoneSchedule.childNodes.item(ctIndex);
            }
        }
    }

    zoneShowItem(thisItem);
}

function itemclick(ctid) {

    PopulateGuide();

    var timeOffset = 0;
    g_LastTimeOffset = 0;

    // Stop showing the previous item if its still playing
    EndContent();

    // Remove all highlighting on Channels & Items
    var GuideC = document.getElementById('V3GuideContent');
    for (var itIndex = 0; itIndex < GuideC.childNodes.length; itIndex++) {
        if (GuideC.childNodes.item(itIndex).getAttribute('ID') != null && GuideC.childNodes.item(itIndex).getAttribute('ID').indexOf('outeritemdefinition_') == 0) {
            var innerItem = GuideC.childNodes.item(itIndex)

            for (var it2Index = 0; it2Index < innerItem.childNodes.length; it2Index++) {
                var inner2Item = innerItem.childNodes.item(it2Index);
                if (inner2Item.getAttribute('ID') != null && inner2Item.getAttribute('ID').indexOf('itemdefinition_') == 0) {
                    inner2Item.className = 'ContentItem';
                }
            }
        }
    }

    // Get a reference to the content item in the XML document
    var thisItem = null;
    if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
            if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == ctid) {
                thisItem = ContentItems.childNodes.item(ctIndex);
            }
        }
    }

    // Highlight current Item
    HighlightItem(ctid);

    // Play the Item
    ShowItem(thisItem, timeOffset);
}

function HighlightCurrentItem() {
    HighlightItem(g_CurrentContentID);
}

function HighlightItem(ctid) {
    var thisSchedItem = document.getElementById('itemdefinition_' + ctid);
    if (thisSchedItem != null) {
        thisSchedItem.className = 'SelectedContentItem';
        g_CurrentContentScheduleItem = 'itemdefinition_' + ctid;

        var OuterScheduleItem = document.getElementById('outeritemdefinition_' + ctid);

        if (OuterScheduleItem.childNodes.item(0).className == 'GuideItemTopSlice') {
            OuterScheduleItem.childNodes.item(0).src = ResourceUrl + 'PSTV-GuideItem_Top_Sel.png';
        }

        if (OuterScheduleItem.childNodes.item(2).className == 'GuideItemBottomSlice') {
            OuterScheduleItem.childNodes.item(2).src = ResourceUrl + 'PSTV-GuideItem_Bottom_Sel.png';
        }
    }
}

function zoneShowItem(contentItem) {
    var prevCType = g_CurrentContentType;

    g_CurrentContentItem = contentItem;
    g_CurrentContentID = contentItem.getAttribute('CTID');
    g_CurrentContentType = contentItem.getAttribute('SimpleType');
    g_CurrentContentDuration = contentItem.getAttribute('Duration');
    g_CurrentContentTitle = contentItem.getAttribute('ContentName');

    var audioAllowed = contentItem.getAttribute('AudioAllowed');
    var volume = 0;

    if (audioAllowed == "True") {
        // for some reason setting mute doesn't work so use volume instead
        g_audioAllowed = true;
        volume = 50;
    }

    var FSFollowOn = ((prevCType == 'flvideo') && (g_CurrentContentType == 'video') && (document.getElementById('FLVidPlayer') != null));
    var WMFollowOn = ((prevCType == 'video') && (g_CurrentContentType == 'video') && (document.getElementById('VidPlayer') != null));

    if ((!FSFollowOn) && (!WMFollowOn)) {
        if (prevCType == 'flvideo' && (document.getElementById('FLVidPlayer') != null)) {
            try {
                document.getElementById('FLVidPlayer').vidExitFS();
            }
            catch (e)
            { }
        }

        if (prevCType == 'video' && (document.getElementById('VidPlayer') != null)) {
            try {
                document.getElementById('VidPlayer').fullScreen = false;
                g_WMVFullScreen = false;
            }
            catch (e)
            { }
        }
    }

    switch (contentItem.getAttribute('SimpleType')) {
        case "video":
            if (g_HasWMP) {
                var vidUrl = "http://" + g_ContentServer + "/Content/" + contentItem.getAttribute('TimeStamp') + '_' + g_CurrentContentID + '_' + contentItem.getAttribute('FileName');

                if (WMFollowOn) {
                    document.getElementById('VidPlayer').URL = vidUrl;
                    document.getElementById('VidPlayer').controls.play();
                }
                else {
                    ZoneContentHolder.innerHTML = '<object id="VidPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="autoStart" value="true" /><param name="URL" value="' + vidUrl + '" /><param name="uiMode" value="none" /><param name="stretchToFit" value="true" /><param name="enableContextMenu" value="false" /><param name="Volume" value="' + volume + '" /><embed id="VidPlayer" src="' + vidUrl + '" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" autostart="true" showcontrols="false"></embed></object>';
                }

                CheckZoneVideo();
            }
            else if (g_HasFlash) {
                g_CurrentContentType = 'flvideo';

                var vidUrl = "http://" + g_FLVStreamServer + "/Encoded/" + contentItem.getAttribute('TimeStamp') + g_CurrentContentID + contentItem.getAttribute('FileName') + GetStreamLevelInUse() + ".flv";

                // check file exists
                var xm = null;
                if (window.XMLHttpRequest) {
                    xm = new XMLHttpRequest();
                }
                else {
                    xm = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xm.open("HEAD", vidUrl, false);
                xm.send(null);

                if (xm.status != 200) {
                    // try WM version
                    g_HasWMP = true;
                    zoneShowItem(contentItem);
                }

                if (FSFollowOn) {
                    getFlashMovieObject('FLVidPlayer').vidPlayNext(vidUrl);
                    flashVidCheckTimer = window.setTimeout('getFlashMovieObject(\'FLVidPlayer\').vidPlay();CheckZoneFlashVideoFile()', 500);
                }
                else {
                    var flvScript = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" id="FLVidPlayer" align="middle">';
                    flvScript += '<param name="allowScriptAccess" value="sameDomain" />'
                    flvScript += '<param name="Movie" value="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="false" /> />';
                    flvScript += '<embed src="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" quality="high" bgcolor="#000000" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FLVidPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="false" />';
                    flvScript += '</object>';
                    ZoneContentHolder.innerHTML = flvScript;
                    ZoneContentHolder.style.display = 'inline';
                    CheckZoneFlashVideo();

                    var flvid = getFlashMovieObject('FLVidPlayer');

                    if (flvid != null) {
                        if (!g_audioAllowed) {
                            flvid.vidSetVolume(0);
                        }
                        else {
                            flvid.vidSetVolume(50);
                        }
                    }
                }
            }
            else {
                ZoneContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                g_CurrentContentType = 'image';
            }
            break;
        case "image":
            ZoneContentHolder.innerHTML = '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
            ZoneCompletedLoading();
            break;
        case "dvbstream":
            ZoneContentHolder.innerHTML = '<b style="color:White">DVB content items are not available for web preview</b>';
            break;
        case "rss":
            window.setTimeout('DoZoneRss("' + g_CurrentContentID + '");', 10);
            break;
        case "url":
            ZoneContentHolder.innerHTML = '<b style="color:White">Web content items are not available for web preview</b>';
            break;
        case "html":
            ZoneContentHolder.innerHTML = '<b style="color:White">HTML content items are not available for web preview</b>';
            break;
        case "flash":
            if (g_HasFlash) {
                ZoneContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '"><param name="quality" value="high"><embed onload="ZoneCompletedLoading();" src="data.aspx?ctid=' + g_CurrentContentID + '" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
                ZoneContentHolder.style.display = 'inline';
                ZoneContentHolder.style.visibility = 'hidden';
                ZoneCheckFlash();
            }
            else {
                ZoneContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                g_CurrentContentType = 'image';
            }
            break;
        case "ppt":
            if (g_HasFlash) {
                g_CurrentContentType = 'flash';
                ZoneContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '&type=flash"><param name="quality" value="high"><embed onload="ZoneCompletedLoading();" src="data.aspx?ctid=' + g_CurrentContentID + '&type=flash" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
                ZoneContentHolder.style.display = 'inline';
                ZoneContentHolder.style.visibility = 'hidden';
                ZoneCheckFlash();
            }
            else {
                ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                g_CurrentContentType = 'image';
            }
            break;
        case "textlines":
            window.setTimeout('DoZoneText("' + g_CurrentContentID + '");', 10);
            break;
        case "wmstream":
            if (g_HasWMP) {
                var vidUrl = contentItem.getAttribute('ContentText');

                if (WMFollowOn) {
                    document.getElementById('VidPlayer').URL = vidUrl;
                    document.getElementById('VidPlayer').controls.play();
                }
                else {
                    ZoneContentHolder.innerHTML = '<object id="VidPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="autoStart" value="true" /><param name="URL" value="' + vidUrl + '" /><param name="uiMode" value="none" /><param name="stretchToFit" value="true" /><param name="enableContextMenu" value="false" /><param name="Volume" value="' + volume + '" /><embed id="VidPlayer" src="' + vidUrl + '" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" autostart="true" showcontrols="false"></embed></object>';
                }

                CheckZoneVideo();
            }
            break;
    }
}

var globalFlag = false;

function ShowItem(ContentItem, timeOffset) {
    hideVideoControls(false);

    SetTitle('Loading: 0%');

    var prevCType = g_CurrentContentType;

    g_CurrentContentItem = ContentItem;
    g_CurrentContentID = ContentItem.getAttribute('ID');
    g_CurrentContentType = ContentItem.getAttribute('SimpleType');
    g_CurrentContentDuration = ContentItem.getAttribute('Duration');
    g_CurrentContentTitle = ContentItem.getAttribute('WebTitle');
    if (g_CurrentContentTitle == '') {
        g_CurrentContentTitle = ContentItem.getAttribute('ContentName');
    }

    if (document.getElementById('V3PlayAgainImage') != null && document.getElementById('V3PlayAgainImage').style.display == 'inline') {
        document.getElementById('V3PlayAgainImage').style.display = 'none';
    }

    var ContentHolder = document.getElementById('ActualContentHolder');
    var LoadingImage = document.getElementById('V3LoadingImage');
    var FSFollowOn = ((prevCType == 'flvideo') && (g_CurrentContentType == 'video') && (document.getElementById('FLVidPlayer') != null));
    //var WMFollowOn = ((prevCType == 'video') && (g_CurrentContentType == 'video') && (document.getElementById('VidPlayer') != null) );

    if ((!FSFollowOn)) {
        if (prevCType == 'flvideo' && (document.getElementById('FLVidPlayer') != null)) {
            try {
                document.getElementById('FLVidPlayer').vidExitFS();
            }
            catch (e)
            { }
        }

        //        if(prevCType == 'video' && (document.getElementById('VidPlayer') != null))
        //        {
        //            try
        //            {
        //                document.getElementById('VidPlayer').fullScreen = false;
        //                g_WMVFullScreen = false;
        //            }
        //            catch(e)
        //            {}
        //        }

        LoadingImage.style.display = 'inline';
        ContentHolder.style.display = 'none';


        if ((ContentItem.getAttribute('BackColour') != '') && (ContentItem.getAttribute('BackColour').length == 7) && (ContentItem.getAttribute('BackColour').indexOf('#') == 0)) {
            ContentHolder.style.backgroundColor = ContentItem.getAttribute('BackColour');
        }
    }

    g_LoadStart = Math.floor(new Date().valueOf() / 1000);
    g_ProgressMade = false;

    var InfoPane = document.getElementById('V3InfoPane');
    var InfoBarContent = '';

    if (ContentItem.getAttribute('WebInfoBar') != '')
        InfoBarContent = ContentItem.getAttribute('WebInfoBar') + '<br /><br />';
    else if (ContentItem.getAttribute('WebDescription') != '')
        InfoBarContent = ContentItem.getAttribute('WebDescription') + '<br /><br />';

    if (ContentItem.getAttribute('WebURL') != '') {
        // Put i button viewer & hook up code here
        var infolink = document.getElementById('InfoLinkItem');
        if (infolink == null) {
            InfoBarContent += '<strong><a href="LinkUrl.aspx?ctid=' + g_CurrentContentID + '" target="_blank" class="WebLink">More Details</a></strong><br /><br />';
        }
        else {
            infolink.href = 'LinkUrl.aspx?ctid=' + g_CurrentContentID;
            document.getElementById('InfoButton').style.display = 'inline';
        }
    }
    else {
        if (document.getElementById('InfoButton') != null && document.getElementById('InfoButton').style.display == 'inline') {
            document.getElementById('InfoButton').style.display = 'none';
        }
    }

    if ((ContentItem.getAttribute('ContentDataLength') > 0) && (ContentItem.getAttribute('AllowDownload') == 'True')) {
        InfoBarContent += '<strong><a class="WebLink" href="data.aspx?ctid=' + g_CurrentContentID + '&attach=1">Download File</a></strong>';
    }

    InfoPane.innerHTML = InfoBarContent;

    if ((ContentItem.getAttribute('ReadyState') != 'True') || (ContentItem.getAttribute('ServerReadyState') != '1')) {
        ContentHolder.innerHTML = '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NotReady.png" />';
        g_CurrentContentType = 'image';
        SetLoadingOnImage(ContentHolder, timeOffset);

        return;
    }

    //    if (ContentItem.getAttribute('UseYouTube') == '1') {
    //        g_UseYouTube = true;
    //    }
    //    else {
    //        g_UseYouTube = false;
    //    }

    g_UseYouTube = (ContentItem.getAttribute('UseYouTube') == '1');

    switch (ContentItem.getAttribute('SimpleType')) {
        case 'video':
            //            if ((g_HasWMP) && !(g_ForceFLV))
            //            {
            //                ShowFullScreen(true);

            //                var vidUrl = (ContentItem.getAttribute('WebVisible') == 'True' && ContentItem.getAttribute('ReadyState') == 'True' && MediaServerDisabled == '0') ? 'mms://' + g_WMStreamServer + '/Encoded/' + ContentItem.getAttribute('FileTimeStamp') + '_' + g_CurrentContentID + '_' + GetStreamLevelInUse() + 'wmv.wmv' : 'data.aspx?ctid=' + g_CurrentContentID + '&bitrate=' + GetStreamLevelInUse() + '&filename=this.wmv';

            //                if(WMFollowOn)
            //                {
            //                    document.getElementById('VidPlayer').URL = vidUrl;
            //		            document.getElementById('VidPlayer').controls.play();
            //                }
            //                else
            //                {
            //                
            //                    ContentHolder.innerHTML = '<object id="VidPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="autoStart" value="true" /><param name="URL" value="' + vidUrl + '" /><param name="uiMode" value="none" /><param name="stretchToFit" value="true" /><param name="enableContextMenu" value="false" /><embed id="VidPlayer" src="' + vidUrl + '" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" autostart="true" showcontrols="false"></embed></object>';
            //                }
            //                CheckVideo(timeOffset);
            //            }
            //            else if(g_HasFlash)
            //            {
            // Hide the button, as its inside the Flash file
            HideFullScreen();

            //g_CurrentContentType = 'flvideo';


            var vidUrl = getItemLocation(g_CurrentContentID, g_CurrentContentType, ContentItem);


            var vidUrlOgg = 'http://localhost/soluspromo640.ogv';

            if (FSFollowOn) {

                getFlashMovieObject('FLVidPlayer').vidPlayNext(vidUrl);
                flashVidCheckTimer = window.setTimeout('getFlashMovieObject(\'FLVidPlayer\').vidPlay();CheckFlashVideoFile(' + timeOffset + ')', 500);
            }
            else {
                var vidScript = '';

                if (!g_UseYouTube) {
                    if (g_HasFlash && !g_ForceHTML5) {
                        vidScript = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" id="FLVidPlayer" align="middle">';
                        vidScript += '<param name="allowScriptAccess" value="sameDomain" />';
                        vidScript += '<param name="Movie" value="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" />';
                        vidScript += '<param name="wmode" value="transparent" />';
                        vidScript += '<embed src="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" quality="high" bgcolor="#000000" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FLVidPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="true" />';
                        vidScript += '</object>';
                    }
                    else if (g_HasHTML5) {
                        vidScript = '<video id="Html5VideoPlayer" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" autobuffer x-webkit-airplay="allow"><source src="' + vidUrl + '"type="video/mp4"><source src="' + vidUrlOgg + '" type="video/ogg">';
                        vidScript += '</video>';
                    }
                    else {
                        vidScript = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                        g_CurrentContentType = 'image';
                    }
                }
                else {
                    var ytid = ContentItem.getAttribute('YouTubeID');

                    if (ytid != null) {
                        ContentHolder.innerHTML = '<div id="ytplayer"><p>You must have Flash installed to view this content</p></div>';

                        var params = { allowScriptAccess: 'always', allowFullScreen: 'true' };

                        swfobject.embedSWF('http://www.youtube.com/v/' + ytid + '&enablejsapi=1&playerapiid=ytplayer&rel=0&autoplay=1&fs=1',
                            'ytplayer', g_ScreenWidth + '', g_ScreenHeight + '', '8', null, null, params);
                    }
                    else {
                        vidScript = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                        window.setTimeout('GetNextItem()', 10000);
                    }

                    hideVideoControls(true);
                }

                if (!g_UseYouTube) {
                    ContentHolder.innerHTML = vidScript;
                }
                ContentHolder.style.display = 'inline';
                LoadingImage.style.display = 'none';
                CheckFlashVideoHolder(timeOffset);

                var vid = document.getElementById('Html5VideoPlayer');
                if (vid != null) {
                    vid.load();
                    vid.addEventListener('progress', videoUpdateProgress, false);
                }

            }
            //}
            //else
            //            {
            //TODO: Perhaps with option to download MP4 file?
            //ContentHolder.innerHTML = '<map name="FPMapNoPlugin"><area href="http://www.microsoft.com/windows/windowsmedia/default.mspx" shape="rect" coords="58, 35, 297, 379"><area href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" shape="rect" coords="358, 36, 598, 379"></map><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="images/NoWMPorFlash.jpg" usemap="#FPMapNoPlugin" /></a>';
            //                ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
            //                g_CurrentContentType = 'image';
            //                SetLoadingOnImage(ContentHolder, timeOffset);
            //            }
            break;
        case 'image':

            ShowFullScreen(false);
            ContentHolder.innerHTML = '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
            SetLoadingOnImage(ContentHolder, timeOffset);
            break;
        case 'flash':
            ShowFullScreen(false);
            if (g_HasFlash) {
                ContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '"><param name="quality" value="high"><embed onload="CompletedLoading(' + timeOffset + ');" src="data.aspx?ctid=' + g_CurrentContentID + '" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
                ContentHolder.style.display = 'inline';
                ContentHolder.style.visibility = 'hidden';
                CheckFlash(timeOffset);
            }
            else {
                ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                g_CurrentContentType = 'image';
                SetLoadingOnImage(ContentHolder, timeOffset);
            }
            break;
        case 'ppt':
            ShowFullScreen(false);
            if (g_HasFlash) {
                g_CurrentContentType = 'flash';
                ContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '&type=flash"><param name="quality" value="high"><embed onload="CompletedLoading(' + timeOffset + ');" src="data.aspx?ctid=' + g_CurrentContentID + '&type=flash" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
                ContentHolder.style.display = 'inline';
                ContentHolder.style.visibility = 'hidden';
                CheckFlash(timeOffset);
            }
            else {
                ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                g_CurrentContentType = 'image';
                SetLoadingOnImage(ContentHolder, timeOffset);
            }
            break;
        case 'text':
            ShowFullScreen(false);
            var TextSettings = ContentItem.childNodes.item(0);
            var TextSize = TextSettings.getAttribute('FontSize') * 0.5;
            var TextStyle = GetTextStyle(TextSettings.getAttribute('FontStyle'));

            if (ContentItem.getAttribute('ContentDataLength') > 0) {
                ContentHolder.innerHTML = '<table width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="width: ' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px; overflow: hidden; position: absolute; top: 0px; left: 0px;z-index: 151" cellpadding="0" cellspacing="0"><tr valign="middle" align="center"><td valign="middle" align="center" id="TextCell" style="color: ' + TextSettings.getAttribute('ForeColour') + '; font-family: ' + TextSettings.getAttribute('FontFamily') + ';' + TextStyle + ' ">' + ContentItem.getAttribute('ContentText') + '</td></tr></table>';
                ContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0"  src="data.aspx?ctid=' + g_CurrentContentID + '" />';
                SetLoadingOnImage(ContentHolder, timeOffset);
            }
            else {
                ContentHolder.innerHTML = '<table width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="background-color: ' + ContentItem.getAttribute('BackColour') + '; width: ' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px; overflow: hidden; position: absolute; top: 0px; left: 0px;z-index: 151" cellpadding="0" cellspacing="0"><tr valign="middle" align="center"><td valign="middle" align="center" id="TextCell" style="color: ' + TextSettings.getAttribute('ForeColour') + '; font-family: ' + TextSettings.getAttribute('FontFamily') + ';' + TextStyle + ' ">' + ContentItem.getAttribute('ContentText') + '</td></tr></table>';

                CompletedLoading(timeOffset);
            }


            break;
        case 'rss':
            ShowFullScreen(false);
            window.setTimeout('DoRss("' + g_CurrentContentID + '", ' + timeOffset + ');', 10);

            break;
        case 'url':
            ShowFullScreen(false);
            ContentHolder.innerHTML = '<iframe scrolling="no" frameborder="0" style="width: ' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px;" src="' + ContentItem.getAttribute('ContentText') + '" onload="CompletedLoading(' + timeOffset + ');" />';
            break;
        case 'html':
            ShowFullScreen(false);
            ContentHolder.innerHTML = '<iframe scrolling="no" frameborder="0" style="width: ' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px;" src="data.aspx?ctid=' + g_CurrentContentID + '" onload="CompletedLoading(' + timeOffset + ');" />';
            break;
        case 'textlines':
            ShowFullScreen(false);
            window.setTimeout('DoEmbedText("' + g_CurrentContentID + '", ' + timeOffset + ');', 10);
            break;
    }
}

function onYouTubePlayerReady() {
    ytplayer = document.getElementById('ytplayer');
    ytplayer.addEventListener('onStateChange', 'onytplayerStateChange');
}

function onytplayerStateChange(newState) {
    if (newState == 0) {
        swfobject.removeSWF('ytplayer');

        if (!IsEmbedded) {
            GetNextItem();
        }
        else {
            showRelatedItems(true);
        }
    }
}

function hideVideoControls(hide) {
    var vidControls = document.getElementById('V3VideoControls');

    if (vidControls != null) {
        if (hide) {
            vidControls.style.display = 'none';
        }
        else {
            vidControls.style.display = 'inline';
        }
    }
}

function getItemLocation(ContentID, ContentType, ContentItem) {
    var vidUrl = 'http://' + g_FLVStreamServer + '/Encoded/' + ContentItem.getAttribute('FileTimeStamp') + '_' + ContentID + '_' + GetStreamLevelInUse() + 'h264.mp4';

    return vidUrl;
}

function DoEmbedText(ContentID, timeOffset) {
    if (textGetTimer != 0) {
        window.clearTimeout(textGetTimer);
        textGetTimer = 0;
    }

    if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
            if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == ContentID) {
                ContentItem = ContentItems.childNodes.item(ctIndex);
                break;
            }
        }
    }

    var index = ContentItem.childNodes.item(0).childNodes.length - 1;
    var TextSettings = ContentItem.childNodes.item(0).childNodes.item(index);
    var textColour = TextSettings.getAttribute('TextColour');
    var textFont = TextSettings.getAttribute('TextFont');
    var textFontSize = TextSettings.getAttribute('TextFontSize') * 0.5;
    var textFontStyle = TextSettings.getAttribute('TextFontStyle');
    var textPositionX = TextSettings.getAttribute('TextPositionX') * 0.5;
    var textPositionY = TextSettings.getAttribute('TextPositionY') * 0.5;
    var textSizeW = TextSettings.getAttribute('TextSizeW') * 0.5;
    var textSizeH = TextSettings.getAttribute('TextSizeH') * 0.5;

    g_CurrentTextlinesTotalItems = index;
    g_CurrentTextlinesDuration = ContentItem.childNodes.item(0).childNodes.item(0).getAttribute('Duration');

    var firstTextItem = ContentItem.childNodes.item(0).childNodes.item(0).childNodes.item(0).nodeValue;

    var ContentHolder = document.getElementById('SolusActualContentHolder');

    var embedded = true;

    if (ContentHolder == null) {
        ContentHolder = document.getElementById('ActualContentHolder');
        ContentHolder.style.display = 'inline';
        embedded = false;
    }

    ContentHolder.innerHTML = '<div style="position: absolute; z-index: 151; left: 0px; top: 0px; width: ' + textSizeW + 'px; height: ' + textSizeH + 'px; overflow: hidden; "><div id="textMessage" ' + 'style= "color: ' + textColour + '; font-family: ' + textFont + '; font-size: ' + textFontSize + 'pt; font-weight: ' + textFontStyle + '; position: absolute; left: ' + textPositionX + 'px; top: ' + textPositionY + 'px;">' + firstTextItem + '</div>';

    if (ContentItem.getAttribute('FileName') != null && ContentItem.getAttribute('FileName') != "") {
        ContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
    }

    if (!embedded) {
        CompletedLoading(timeOffset);
    }
}

function DoZoneText(ContentID) {
    if (textGetTimer != 0) {
        window.clearTimeout(textGetTimer);
        textGetTimer = 0;
    }

    var ContentItem = null;

    if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ZoneSchedule.childNodes.length; ctIndex++) {
            if (ZoneSchedule.childNodes.item(ctIndex).getAttribute('CTID') == ContentID) {
                ContentItem = ZoneSchedule.childNodes.item(ctIndex);
            }
        }
    }

    var index = ContentItem.childNodes.item(0).childNodes.length - 1;
    var TextSettings = ContentItem.childNodes.item(0).childNodes.item(index);
    var textColour = TextSettings.getAttribute('TextColour');
    var textFont = TextSettings.getAttribute('TextFont');
    var textFontSize = TextSettings.getAttribute('TextFontSize') * 0.5;
    var textFontStyle = TextSettings.getAttribute('TextFontStyle');
    var textPositionX = TextSettings.getAttribute('TextPositionX') * 0.5;
    var textPositionY = TextSettings.getAttribute('TextPositionY') * 0.5;
    var textSizeW = TextSettings.getAttribute('TextSizeW') * 0.5;
    var textSizeH = TextSettings.getAttribute('TextSizeH') * 0.5;

    g_CurrentTextlinesTotalItems = index;
    g_CurrentTextlinesDuration = ContentItem.childNodes.item(0).childNodes.item(0).getAttribute('Duration');

    var firstTextItem = ContentItem.childNodes.item(0).childNodes.item(0).childNodes.item(0).nodeValue;

    ZoneContentHolder.innerHTML = '<div style="position: absolute; z-index: 151; left: 0px; top: 0px; width: ' + textSizeW + 'px; height: ' + textSizeH + 'px; overflow: hidden; "><div id="textMessage" ' + 'style= "color: ' + textColour + '; font-family: ' + textFont + '; font-size: ' + textFontSize + 'pt; font-weight: ' + textFontStyle + '; position: absolute; left: ' + textPositionX + 'px; top: ' + textPositionY + 'px;">' + firstTextItem + '</div>';

    if (ContentItem.getAttribute('FileName') != null && ContentItem.getAttribute('FileName') != "") {
        ZoneContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
        ZoneCompletedLoading();
    }
    else {
        ZoneCompletedLoading();
    }
}

function DoEmbedRss(ContentID) {
    if (rssGetTimer != 0) {
        window.clearTimeout(rssGetTimer);
        rssGetTimer = 0;
    }

    var ContentItem = null;

    if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
            if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == ContentID) {
                ContentItem = ContentItems.childNodes.item(ctIndex);
            }
        }
    }

    var ContentHolder = document.getElementById('SolusActualContentHolder');

    var RssSettings = ContentItem.childNodes.item(0);
    var MaxRssItems = RssSettings.getAttribute('MaxItems');

    g_CurrentRssItemDuration = RssSettings.getAttribute('DetailViewDuration');
    g_CurrentRssSelectedColor = RssSettings.getAttribute('SelectedItemColour');

    var xmlrss = null;
    if (window.XMLHttpRequest) {
        xmlrss = new XMLHttpRequest();
    }
    else {
        xmlrss = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlrss.open("GET", 'RssProxy.aspx?url=' + escape(ContentItem.getAttribute('ContentText')), true);

    xmlrss.onreadystatechange = function () {
        var done = 4, ok = 200;

        if (ContentID == g_CurrentContentID && xmlrss.readyState == done && xmlrss.status == ok) {
            if ((xmlrss.responseXML != null) && (xmlrss.responseXML.documentElement != null) && (xmlrss.responseXML.documentElement.nodeName == 'rss')) {
                var channel = xmlrss.responseXML.documentElement.getElementsByTagName('channel').item(0);

                var ItemSize = RssSettings.getAttribute('ItemFontSize') * 0.5;
                var ItemStyle = GetTextStyle(RssSettings.getAttribute('ItemFontStyle'));

                var DetailSize = RssSettings.getAttribute('DetailFontSize') * 0.5;
                var DetailStyle = GetTextStyle(RssSettings.getAttribute('DetailFontStyle'));

                var LastModSize = RssSettings.getAttribute('LastModFontSize') * 0.5;
                var LastModStyle = GetTextStyle(RssSettings.getAttribute('LastModFontStyle'));

                var rssHeader = '<div style="position: absolute; z-index: 151; left: 0px; top: 0px; width:' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px; overflow: hidden;"><ul id="rssHeaderList" style="list-style-type:disc;font-family: ' + RssSettings.getAttribute('ItemFont') + '; font-weight:' + ItemStyle + '; font-size:' + ItemSize + 'pt; color:' + RssSettings.getAttribute('ItemColour') + '; position: absolute; top:' + (RssSettings.getAttribute('ItemPositionY') * 0.5) + 'px; left:' + (RssSettings.getAttribute('ItemPositionX') * 0.5) + 'px;width: ' + (RssSettings.getAttribute('ItemSizeW') * 0.5) + 'px; height: ' + (RssSettings.getAttribute('ItemSizeH') * 0.5) + 'px;z-index: 151; margin: 0; padding: 0;">'
                var rssDetailItems = '<div id="rssDetailView" style="margin:0; padding:0; font-family:' + RssSettings.getAttribute('DetailFont') + ';width:' + (RssSettings.getAttribute('DetailSizeW') * 0.5) + 'px;z-index:151;height:' + (RssSettings.getAttribute('DetailSizeH') * 0.5) + 'px;color:' + RssSettings.getAttribute('DetailColour') + '; font-style:' + DetailStyle + '; top:' + (RssSettings.getAttribute('DetailPositionY') * 0.5) + 'px;position:absolute;left:' + (RssSettings.getAttribute('DetailPositionX') * 0.5) + 'px;font-size:' + DetailSize + 'pt;' + ((DetailSize < 4) ? 'display:none;' : '') + '"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr valign="middle" align="center"><td valign="middle" align="center">';

                var rssItems = channel.getElementsByTagName('item');
                for (var rssIndex = 0; ((rssIndex < rssItems.length) && (rssIndex < MaxRssItems)); rssIndex++) {
                    rssHeader += '<li>' + rssItems.item(rssIndex).getElementsByTagName('title').item(0).firstChild.nodeValue + '</li>';
                    rssDetailItems += '<div id="detailviewitem' + rssIndex + '" style="display: none; color: ' + RssSettings.getAttribute('DetailColour') + ';">' + rssItems.item(rssIndex).getElementsByTagName('description').item(0).firstChild.nodeValue + '</div>';
                }

                rssHeader += '</ul></div>';
                rssDetailItems += '</td></tr></table></div>';

                var dt = new Date();
                var dtString = dt.toLocaleString();
                g_CurrentRssTotalItems = rssIndex;
                ContentHolder.innerHTML = rssHeader + ' ' + rssDetailItems + ' ' + '<span id="rssLastMod" style="font-family:' + RssSettings.getAttribute('LastModFont') + ';text-align:center;width:100%;z-index:152;' + LastModStyle + ' color:' + RssSettings.getAttribute('LastModColour') + ';left:0px;position:absolute;top:365px;font-size:' + LastModSize + 'pt;">Last Updated: ' + dtString + '</span>';
            }

            if (ContentItem.getAttribute('FileName') != null && ContentItem.getAttribute('FileName') != '') {
                ContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
            }
        }
    };
    xmlrss.send(null);
}

function clickAlert() {
    alert('Click click!');
}

function DoZoneRss(ContentID) {
    if (rssGetTimer != 0) {
        window.clearTimeout(rssGetTimer);
        rssGetTimer = 0;
    }

    var ContentItem = null;

    if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ZoneSchedule.childNodes.length; ctIndex++) {
            if (ZoneSchedule.childNodes.item(ctIndex).getAttribute('CTID') == ContentID) {
                ContentItem = ZoneSchedule.childNodes.item(ctIndex);
            }
        }
    }

    var RssSettings = ContentItem.childNodes.item(0);
    var MaxRssItems = RssSettings.getAttribute('MaxItems');

    g_CurrentRssItemDuration = RssSettings.getAttribute('DetailViewDuration');
    g_CurrentRssSelectedColor = RssSettings.getAttribute('SelectedItemColour');

    var xmlrss = null;
    if (window.XMLHttpRequest) {
        xmlrss = new XMLHttpRequest();
    }
    else {
        xmlrss = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlrss.open("GET", 'RssProxy.aspx?url=' + escape(ContentItem.getAttribute('ContentText')), true);

    xmlrss.onreadystatechange = function () {
        var done = 4, ok = 200;

        if (ContentID == g_CurrentContentID && xmlrss.readyState == done && xmlrss.status == ok) {
            if ((xmlrss.responseXML != null) && (xmlrss.responseXML.documentElement != null) && (xmlrss.responseXML.documentElement.nodeName == 'rss')) {
                var channel = xmlrss.responseXML.documentElement.getElementsByTagName('channel').item(0);

                var ItemSize = RssSettings.getAttribute('ItemFontSize') * 0.5;
                var ItemStyle = GetTextStyle(RssSettings.getAttribute('ItemFontStyle'));

                var DetailSize = RssSettings.getAttribute('DetailFontSize') * 0.5;
                var DetailStyle = GetTextStyle(RssSettings.getAttribute('DetailFontStyle'));

                var LastModSize = RssSettings.getAttribute('LastModFontSize') * 0.5;
                var LastModStyle = GetTextStyle(RssSettings.getAttribute('LastModFontStyle'));

                var rssHeader = '<div style="position: absolute; z-index: 151; left: 0px; top: 0px; width: 100%; height: 100%; overflow: hidden;"><ul id="rssHeaderList" style="list-style-type:disc;font-family: ' + RssSettings.getAttribute('ItemFont') + '; font-weight:' + ItemStyle + '; font-size:' + ItemSize + 'pt; color:' + RssSettings.getAttribute('ItemColour') + '; position: absolute; top:' + (RssSettings.getAttribute('ItemPositionY') * 0.5) + 'px; left:' + (RssSettings.getAttribute('ItemPositionX') * 0.5) + 'px;width: ' + (RssSettings.getAttribute('ItemSizeW') * 0.5) + 'px; height: ' + (RssSettings.getAttribute('ItemSizeH') * 0.5) + 'px;z-index: 151; margin: 0; padding: 0;">'
                var rssDetailItems = '<div id="rssDetailView" style="margin:0; padding:0; font-family:' + RssSettings.getAttribute('DetailFont') + ';width:' + (RssSettings.getAttribute('DetailSizeW') * 0.5) + 'px;z-index:151;height:' + (RssSettings.getAttribute('DetailSizeH') * 0.5) + 'px;color:' + RssSettings.getAttribute('DetailColour') + '; font-style:' + DetailStyle + '; top:' + (RssSettings.getAttribute('DetailPositionY') * 0.5) + 'px;position:absolute;left:' + (RssSettings.getAttribute('DetailPositionX') * 0.5) + 'px;font-size:' + DetailSize + 'pt;' + ((DetailSize < 4) ? 'display:none;' : '') + '"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr valign="middle" align="center"><td valign="middle" align="center">';

                var rssItems = channel.getElementsByTagName('item');
                for (var rssIndex = 0; ((rssIndex < rssItems.length) && (rssIndex < MaxRssItems)); rssIndex++) {
                    rssHeader += '<li>' + rssItems.item(rssIndex).getElementsByTagName('title').item(0).firstChild.nodeValue + '</li>';
                    rssDetailItems += '<div id="detailviewitem' + rssIndex + '" style="display: none; color: ' + RssSettings.getAttribute('DetailColour') + ';">' + rssItems.item(rssIndex).getElementsByTagName('description').item(0).firstChild.nodeValue + '</div>';
                }

                rssHeader += '</ul></div>';
                rssDetailItems += '</td></tr></table></div>';

                var dt = new Date();
                var dtString = dt.toLocaleString();
                g_CurrentRssTotalItems = rssIndex;
                ZoneContentHolder.innerHTML = rssHeader + ' ' + rssDetailItems + ' ' + '<span id="rssLastMod" style="font-family:' + RssSettings.getAttribute('LastModFont') + ';text-align:center;width:100%;z-index:152;' + LastModStyle + ' color:' + RssSettings.getAttribute('LastModColour') + ';left:0px;position:absolute;top:365px;font-size:' + LastModSize + 'pt;">Last Updated: ' + dtString + '</span>';
            }

            if (ContentItem.getAttribute('FileName') != null && ContentItem.getAttribute('FileName') != '') {
                ZoneContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
                ZoneCompletedLoading();
            }
            else {
                ZoneCompletedLoading();
            }
        }
    };
    xmlrss.send(null);
}

function DoRss(ContentID, timeOffset) {
    if (rssGetTimer != 0) {
        window.clearTimeout(rssGetTimer);
        rssGetTimer = 0;
    }

    var ContentHolder = getObj('ActualContentHolder');
    var thisCTID = ContentID;
    var ContentItem = null;
    if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
        for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
            if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == ContentID) {
                ContentItem = ContentItems.childNodes.item(ctIndex);
            }
        }
    }
    var RssSettings = ContentItem.childNodes.item(0);
    var MaxRssItems = RssSettings.getAttribute('MaxItems');

    g_CurrentRssItemDuration = RssSettings.getAttribute('DetailViewDuration');
    g_CurrentRssSelectedColor = RssSettings.getAttribute('SelectedItemColour');

    var xmlrss = null;
    if (window.XMLHttpRequest) {
        xmlrss = new XMLHttpRequest();
    }
    else {
        xmlrss = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlrss.open("GET", 'RssProxy.aspx?url=' + escape(ContentItem.getAttribute('ContentText')), true);

    xmlrss.onreadystatechange = function () {
        var done = 4, ok = 200;

        if (thisCTID == g_CurrentContentID && xmlrss.readyState == done && xmlrss.status == ok) {
            if ((xmlrss.responseXML != null) && (xmlrss.responseXML.documentElement != null) && (xmlrss.responseXML.documentElement.nodeName == 'rss')) {
                var channel = xmlrss.responseXML.documentElement.getElementsByTagName('channel').item(0);

                var ItemSize = RssSettings.getAttribute('ItemFontSize') * 0.5;
                var ItemStyle = GetTextStyle(RssSettings.getAttribute('ItemFontStyle'));

                var DetailSize = RssSettings.getAttribute('DetailFontSize') * 0.5;
                var DetailStyle = GetTextStyle(RssSettings.getAttribute('DetailFontStyle'));

                var LastModSize = RssSettings.getAttribute('LastModFontSize') * 0.5;
                var LastModStyle = GetTextStyle(RssSettings.getAttribute('LastModFontStyle'));

                var rssHeader = '<div style="position: absolute; z-index: 151; left: 0px; top: 0px; width: ' + g_ScreenWidth + 'px; height: ' + g_ScreenHeight + 'px; overflow: hidden;"><ul id="rssHeaderList" style="list-style-type:circle;font-family: ' + RssSettings.getAttribute('ItemFont') + ';' + ItemStyle + ' font-size:' + ItemSize + 'pt; color:' + RssSettings.getAttribute('ItemColour') + '; position: absolute; top:' + (RssSettings.getAttribute('ItemPositionY') * 0.5) + 'px; left:' + (RssSettings.getAttribute('ItemPositionX') * 0.5) + 'px;width: ' + (RssSettings.getAttribute('ItemSizeW') * 0.5) + 'px; height: ' + (RssSettings.getAttribute('ItemSizeH') * 0.5) + 'px;z-index: 151;">'
                var rssDetailItems = '<div id="rssDetailView" style="font-family:Verdana;width:' + (RssSettings.getAttribute('DetailSizeW') * 0.5) + 'px;z-index:151;height:' + (RssSettings.getAttribute('DetailSizeH') * 0.5) + 'px;color:' + RssSettings.getAttribute('DetailColour') + ';' + ItemStyle + ' top:' + (RssSettings.getAttribute('DetailPositionY') * 0.5) + 'px;position:absolute;left:' + (RssSettings.getAttribute('DetailPositionX') * 0.5) + 'px;font-size:' + DetailSize + 'pt;' + ((DetailSize < 4) ? 'display:none;' : '') + '"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr valign="middle" align="center"><td valign="middle" align="center">';

                var rssItems = channel.getElementsByTagName('item');
                for (var rssIndex = 0; ((rssIndex < rssItems.length) && (rssIndex < MaxRssItems)); rssIndex++) {
                    rssHeader += '<li>' + rssItems.item(rssIndex).getElementsByTagName('title').item(0).firstChild.nodeValue + '</li>';
                    rssDetailItems += '<div id="detailviewitem' + rssIndex + '" style="display:none"><a target="_blank" class="RSSDetailLink" style="color:' + RssSettings.getAttribute('DetailColour') + ';" href="' + rssItems.item(rssIndex).getElementsByTagName('link').item(0).firstChild.nodeValue + '">' + rssItems.item(rssIndex).getElementsByTagName('description').item(0).firstChild.nodeValue + '</a></div>';
                }

                rssHeader += '</ul></div>';
                rssDetailItems += '</td></tr></table></div>';

                var dt = new Date();
                var dtString = dt.toLocaleString();
                g_CurrentRssTotalItems = rssIndex;
                ContentHolder.innerHTML = rssHeader + ' ' + rssDetailItems + ' ' + '<span id="rssLastMod" style="font-family:Verdana;text-align:center;width:100%;z-index:152;' + LastModStyle + ' color:' + RssSettings.getAttribute('LastModColour') + ';left:0px;position:absolute;top:365px;font-size:' + LastModSize + 'pt;">Last Updated: ' + dtString + '</span>';


            }

            if (ContentItem.getAttribute('ContentDataLength') > 0) {
                ContentHolder.innerHTML += '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" style="position: absolute; top: 0px; left: 0px; z-index: 140" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
                SetLoadingOnImage(ContentHolder, timeOffset);

            }
            else {
                CompletedLoading(timeOffset);
            }
        }
    };
    xmlrss.send(null);
}

function SetLoadingOnImage(ContentHolder, timeOffset) {

    for (var picIndex = 0; picIndex < ContentHolder.childNodes.length; picIndex++) {
        if ((ContentHolder.childNodes.item(picIndex).nodeName == 'IMG' || ContentHolder.childNodes.item(picIndex).nodeName == 'img')) {
            //ContentHolder.childNodes.item(picIndex).onload = function() {eval('CompletedLoading(timeOffset)');};
            CompletedLoading(timeOffset);
        }
        else if ((ContentHolder.childNodes.item(picIndex).nodeName == 'A' || ContentHolder.childNodes.item(picIndex).nodeName == 'a')) {

            for (var pic2Index = 0; pic2Index < ContentHolder.childNodes.item(picIndex).childNodes.length; pic2Index++) {
                var innerObj = ContentHolder.childNodes.item(picIndex).childNodes.item(pic2Index);
                if ((innerObj.nodeName == 'IMG' || innerObj.nodeName == 'img')) {
                    //innerObj.onload = function() {eval('CompletedLoading(timeOffset)');};
                    CompletedLoading(timeOffset);
                }
            }
        }
    }
}

function ZoneCheckFlash() {
    if (document.getElementById('FlashPlayer') != null) {
        try {
            var FlashObj = getFlashMovieObject('FlashPlayer');

            if ((FlashObj.PercentLoaded() == 100) || (FlashObj.PercentLoaded() < 0)) {
                ZoneCompletedLoading();
            }
            else {
                flashCheckTimer = window.setTimeout('ZoneCheckFlash()', 100);
            }
        }
        catch (e) {
            ZoneCompletedLoading();
        }
    }
}

function CheckFlash(timeOffset) {
    if (document.getElementById('FlashPlayer') != null) {

        try {
            var FlashObj = getFlashMovieObject('FlashPlayer');

            if ((FlashObj.PercentLoaded() == 100) || (FlashObj.PercentLoaded() < 0)) {
                CompletedLoading(timeOffset);
            }
            else {
                SetTitle('Loading: ' + FlashObj.PercentLoaded() + '%');
                flashCheckTimer = window.setTimeout('CheckFlash(' + timeOffset + ')', 100);
            }
        }
        catch (e) {
            CompletedLoading(timeOffset);

        }
    }
}

function getFlashMovieObject(movieName) {

    if (window.document[movieName]) {
        return window.document[movieName];
    }

    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

function GetVideoProgress() {
    var newprogress = -1;
    if ((document.getElementById('VidPlayer').network != null) && (document.getElementById('VidPlayer').network.downloadProgress != null)) {
        newprogress = document.getElementById('VidPlayer').network.downloadProgress;
    }

    if ((document.getElementById('VidPlayer').network != null) && (document.getElementById('VidPlayer').network.bufferingProgress != null)) {
        newprogress = document.getElementById('VidPlayer').network.bufferingProgress;
    }
    return newprogress;
}

function CheckZoneVideo() {
    if (document.getElementById('VidPlayer') != null) {

        ZoneCompletedLoading();

        if (document.getElementById('VidPlayer').playState == 3) {
            ZoneCompletedLoading();
        }
        else {
            var vidProgress = GetVideoProgress();

            if (vidProgress >= 0 && vidProgress != 100) {
                g_ProgressMade = true;
            }

            // should do something if no progress made
            videoCheckTimer = window.setTimeout('CheckZoneVideo();', 500);
        }
    }
}

function CheckVideo(timeOffset) {
    if (document.getElementById('VidPlayer') != null) {
        if (document.getElementById('VidPlayer').playState == 3) {
            document.getElementById('VidPlayer').fullScreen = g_WMVFullScreen;
            CompletedLoading(timeOffset);
        }
        else {
            var vidprogress = GetVideoProgress();

            if (vidprogress >= 0 && vidprogress != 100) {
                g_ProgressMade = true;
                SetTitle('Loading: ' + vidprogress + '%');
                SetProgressBarInPercent(vidprogress);
            }

            var currentTime = Math.floor(new Date().valueOf() / 1000);

            if (((currentTime - g_LoadStart) > 20) && (!g_ProgressMade)) {
                if (!g_ForceWMP) {
                    g_ForceFLV = true;
                    itemclick(g_CurrentContentID);
                }
                else {
                    var ContentHolder = document.getElementById('ActualContentHolder');
                    ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
                    g_CurrentContentType = 'image';
                    SetLoadingOnImage(ContentHolder, timeOffset);
                }
            }
            else {
                videoCheckTimer = window.setTimeout('CheckVideo(' + timeOffset + ');', 500);
            }
        }
    }
}

function CheckZoneFlashVideo() {
    if (flashVidCheckTimer != 0) {
        window.clearTimeout(flashVidCheckTimer);
    }

    flashVidCheckTimer = 0;

    var flvid = getFlashMovieObject('FLVidPlayer');

    try {
        var loaded = flvid.PercentLoaded();
    }
    catch (e) {
        flashVidCheckTimer = window.setTimeout('CheckZoneFlashVideo()', 100);
        return;
    }

    if (flvid != null) {
        try {
            var flLoaded = flvid.PercentLoaded();

            if (flLoaded >= 100) {
                g_ProgressMade = false;

                flashVidCheckTimer = window.setTimeout('getFlashMovieObject(\'FLVidPlayer\').vidPlay();CheckZoneFlashVideoFile()', 1000);
            }
            else {
                flashVidCheckTimer = window.setTimeout('CheckZoneFlashVideo()', 100);
            }
        }
        catch (e) {
            ZoneCompletedLoading();
        }
    }
}

function CheckFlashVideoHolder(timeOffset) {
    if (flashVidCheckTimer != 0)
        window.clearTimeout(flashVidCheckTimer);
    flashVidCheckTimer = 0;

    var flvid = null;

    flvid = getFlashMovieObject('FLVidPlayer');

    try {
        if (flvid != null /*&& flvid.readyState*/) {
            var loaded = flvid.PercentLoaded();
        }
    }
    catch (e) {
        // TODO: Catch infinite loop here
        flashVidCheckTimer = window.setTimeout('CheckFlashVideoHolder(' + timeOffset + ')', 100);
        return;
    }

    if (flvid != null /*&& flvid.readyState*/) {
        try {
            var flLoaded = flvid.PercentLoaded();
            if (flLoaded >= 100) {
                g_LoadStart = Math.floor(new Date().valueOf() / 1000);
                g_ProgressMade = false;

                flashVidCheckTimer = window.setTimeout('getFlashMovieObject(\'FLVidPlayer\').vidPlay();CheckFlashVideoFile(' + timeOffset + ')', 1000);
            }
            else {
                if (flLoaded > 0) {
                    SetTitle('Loading: ' + flLoaded + '%');
                }
                flashVidCheckTimer = window.setTimeout('CheckFlashVideoHolder(' + timeOffset + ')', 100);
            }
        }
        catch (e) {
            CompletedLoading(timeOffset);
        }
    }
    else {
        try {
            var vid = document.getElementById('Html5VideoPlayer');

            if (vid != null) {
                //var vLoaded = parseInt(((vid.buffered.end(vid.buffered.length - 1) / vid.duration) * 100));

                if (vid.readyState == 4) {
                    g_LoadStart = Math.floor(new Date().valueOf() / 1000);
                    g_ProgressMade = false;

                    //vid.play();

                    flashVidCheckTimer = window.setTimeout('document.getElementsByTagName(\'video\')[0].play();CheckFlashVideoFile(' + timeOffset + ')', 1000);
                    //flashVidCheckTimer = window.setTimeout('CheckFlashVideoFile(' + timeOffset + ')', 1000);
                }
                else {
                    //                    if (vLoaded > 0) {
                    //                        SetTitle('Loading: ' + vLoaded + '%');
                    //                    }
                    flashVidCheckTimer = window.setTimeout('CheckFlashVideoHolder(' + timeOffset + ')', 100);
                }
            }
        }
        catch (e) {
            CompletedLoading(timeOffset);
        }
    }
}

function CheckZoneFlashVideoFile() {
    if (flashCheckTimer != 0) {
        window.clearTimeout(flashCheckTimer);
    }

    flashCheckTimer = 0;

    var flvid = getFlashMovieObject('FLVidPlayer');

    if (flvid.vidGetState() == 3) {
        g_ProgressMade = true;
        window.setTimeout('ZoneCompletedLoading()', 100);
    }
    else {
        // should do something if no progress has been made
        flashVidCheckTimer = window.setTimeout('CheckZoneFlashVideoFile()', 100);
    }
}

function CheckFlashVideoFile(timeOffset) {

    if (flashVidCheckTimer != 0)
        window.clearTimeout(flashVidCheckTimer);
    flashVidCheckTimer = 0;

    var flvid = null;

    flvid = getFlashMovieObject('FLVidPlayer');

    if (flvid != null /*&& flvid.readyState*/) {
        if (flvid.vidGetState() == 3) {
            g_ProgressMade = true;
            window.setTimeout('CompletedLoading(' + timeOffset + ')', 100);
        }
        else {
            var currentTime = Math.floor(new Date().valueOf() / 1000);
            if (((currentTime - g_LoadStart) > 30) && (!g_ProgressMade)) {
                var ContentHolder = document.getElementById('ActualContentHolder');
                ContentHolder.innerHTML = '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'FlashNA.png" />';
                g_CurrentContentType = 'image';
                SetLoadingOnImage(ContentHolder, timeOffset);
            }
            else {
                if (flvid.vidGetBytesLoaded() > 0) {
                    g_ProgressMade = true;
                }
                SetProgressBarInPercent((100 * flvid.vidGetBytesLoaded()) / flvid.vidGetBytesTotal());
                flashVidCheckTimer = window.setTimeout('CheckFlashVideoFile(' + timeOffset + ')', 100);
            }
        }
    }
    else {
        var vid = document.getElementById('Html5VideoPlayer');

        if (vid != null) {
            //console.log(vid.readyState);
            if (vid.readyState == 4) {
                g_ProgressMade = true;
                window.setTimeout('CompletedLoading(' + timeOffset + ')', 100);
            }
            else {
                var downloaded = parseInt(((vid.buffered.end(0) / vid.duration) * 100));

                if (downloaded > 0) {
                    g_ProgressMade = true
                }

                SetProgressBarInPercent(downloaded);
                flashVidCheckTimer = window.setTimeout('CheckFlashVideoFile(' + timeOffset + ')', 100);
            }
        }
    }
}

function ZoneCompletedLoading() {
    g_FlipperTime = -1;
    FlipZoneTimer();

    ZoneContentHolder.style.display = 'inline';
    ZoneContentHolder.style.visibility = '';
}

function CompletedLoading(timeOffset) {

    SetTitle(g_CurrentContentTitle);
    var ContentHolder = document.getElementById('ActualContentHolder');
    var LoadingImage = document.getElementById('V3LoadingImage');

    if ((g_CurrentContentType == 'video') && (document.getElementById('VidPlayer') != null) && (document.getElementById('VidPlayer').controls != null) && (document.getElementById('VidPlayer').controls.currentPosition != null)) {
        if (timeOffset > 0) {
            SetPositionTime(timeOffset, true);
        }
        document.getElementById('FullScreenButton').style.display = 'inline';
        document.getElementById('PlayPause').src = PauseButtonUrl;
        document.getElementById('PlayPause').style.display = 'inline';

        UpdateVolume();
    }
    else if (g_CurrentContentType == 'video') {
        var flvid = getFlashMovieObject('FLVidPlayer');

        if (flvid != null /*&& flvid.readyState*/) {
            if (timeOffset > 0) {
                var flvid = getFlashMovieObject('FLVidPlayer');
                if (parseFloat(flvid.vidGetPosition()) < timeOffset);
                {
                    SetPositionTime(timeOffset, true);
                }
            }

            document.getElementById('PlayPause').src = PauseButtonUrl;
            document.getElementById('PlayPause').style.display = 'inline';

            UpdateVolume();
        }
        else {
            var vid = document.getElementById('Html5VideoPlayer');

            if (vid != null) {
                if (timeOffset > 0) {
                    if (parseFloat(vid.currentTime) < timeOffset) {
                        SetPositionTime(timeOffset, true);
                    }
                }
            }

            document.getElementById('PlayPause').src = PauseButtonUrl;
            document.getElementById('PlayPause').style.display = 'inline';

            UpdateVolume();
        }
    }
    else if ((g_CurrentContentType == 'flvideo') && (g_HasFlash)) {
        if (timeOffset > 0) {
            var flvid = getFlashMovieObject('FLVidPlayer');
            if (parseFloat(flvid.vidGetPosition()) < timeOffset);
            {
                SetPositionTime(timeOffset, true);
            }
        }

        document.getElementById('PlayPause').src = PauseButtonUrl;
        document.getElementById('PlayPause').style.display = 'inline';

        UpdateVolume();
    }
    else if (g_CurrentContentType == 'rss') {
        SetPositionTime(timeOffset, true);
        document.getElementById('PlayPause').src = PauseButtonUrl;
        document.getElementById('PlayPause').style.display = 'inline';

        PlayState = 1;
        SetProgressBarInPercent(100);
    }
    else if ((g_CurrentContentType == 'image') || (g_CurrentContentType == 'url') || (g_CurrentContentType == 'html')
        || (g_CurrentContentType == 'flash') || (g_CurrentContentType == 'textlines')) {
        SetProgressBarInPercent(100);
        PlayState = 1
        document.getElementById('PlayPause').src = PauseButtonUrl;
        document.getElementById('PlayPause').style.display = 'inline';
    }

    g_FlipperTime = timeOffset - 1;
    FlipTimer();

    document.getElementById('PosBall').style.display = 'inline';

    LoadingImage.style.display = 'none';
    ContentHolder.style.display = 'inline';
    ContentHolder.style.visibility = '';

    LogItem(g_CurrentContentID, g_CurrentChannelID, g_CurrentSkinID, g_BitrateInUse);
}

function SetPositionTime(position, firstrun) {
    switch (g_CurrentContentType) {
        case 'video':
            //            if (document.getElementById('VidPlayer') != null)
            //            {
            //                document.getElementById('VidPlayer').controls.currentPosition = position;
            //            }
            var flvid = null;

            flvid = getFlashMovieObject('FLVidPlayer');

            if (flvid != null /*&& flvid.readyState*/) {
                flvid.vidSetPosition(position);
            }
            else {
                var vid = document.getElementById('Html5VideoPlayer');
                vid.currentTime = position;
            }

            break;
        case 'flvideo':

            var flvid = getFlashMovieObject('FLVidPlayer');
            if (flvid != null) {
                flvid.vidSetPosition(position);
            }
            break;
        case 'rss':
            RssShowTime(position);
            break;
        case 'flash':
            var flPlayer = getFlashMovieObject('FlashPlayer');
            if (flPlayer != null) {
                var frameRate = 0;

                if (g_IsIE) {
                    frameRate = flPlayer.TotalFrames / g_CurrentContentDuration;
                }
                else {
                    frameRate = flPlayer.TotalFrames() / g_CurrentContentDuration;
                }

                var frame = Math.round(position * frameRate);
                flPlayer.GotoFrame(frame);
                flPlayer.Play();
            }
            break;
    }

    //if (!firstrun) {
    if (!IsEmbedded) {
        if (timeFlipTimer != 0) {
            window.clearTimeout(timeFlipTimer);
            timeFlipTimer = 0;
        }

        g_FlipperTime = Math.round(position) - 1;

        if (g_CurrentContentType == 'rss' && PlayState == 0) {
            g_FlipperTime++;
            var flipSecs = g_FlipperTime % 60;
            SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
        }
        else {
            FlipTimer();
        }
    }
    else {
        if (timeEmbedTimer != 0) {
            window.clearTimeout(timeEmbedTimer);
            timeEmbedTimer = 0;
        }

        g_FlipperTime = Math.round(position) - 1;

        if (PlayState == 1) {
            EmbedTimer();
        }
    }
    //}

}

function SetPositionPercent(positionpercent) {
    var newPos = ((positionpercent / 100.0) * g_CurrentContentDuration);
    SetPositionTime(newPos, true);
}

function alrt(str) {
    document.getElementById('HeadlineSponsor').innerHTML = document.getElementById('HeadlineSponsor').innerHTML + str + '<br />';
}

function leftTrim(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

function GetTextStyle(TextStyleItem) {
    switch (TextStyleItem) {
        case 'bold':
            return ' font-weight: bold;';

        case 'italic':
            return ' font-style: italic;';

        case 'strikeout':
            return ' text-decoration: line-through;';

        case 'underline':
            return ' text-decoration: underline;';

        default:
            return '';
    }
}

function TextShowItem(next) {
    if (document.getElementById('textMessage') == null) {
        return null;
    }

    var ContentItem = null;

    if (!IsEmbedded && ZoneSchedule != null) {
        if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
            for (var ctIndex = 0; ctIndex < ZoneSchedule.childNodes.length; ctIndex++) {
                if (ZoneSchedule.childNodes.item(ctIndex).getAttribute('CTID') == g_CurrentContentID) {
                    ContentItem = ZoneSchedule.childNodes.item(ctIndex);
                }
            }
        }
        //        if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
        //            for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
        //                if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == g_CurrentContentID) {
        //                    ContentItem = ContentItems.childNodes.item(ctIndex);
        //                }
        //            }
        //        }
    }
    else {
        if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
            for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
                if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == g_CurrentContentID) {
                    ContentItem = ContentItems.childNodes.item(ctIndex);
                }
            }
        }
    }

    if (next < 1) {
        return;
    }

    if (next < g_CurrentTextlinesTotalItems) {
        var textItem = ContentItem.childNodes.item(0).childNodes.item(next).childNodes.item(0).nodeValue;

        var textMessage = document.getElementById('textMessage');

        textMessage.childNodes.item(0).nodeValue = textItem;
    }
    else {
        return;
    }
}

function RssShowItem(next) {
    if (document.getElementById('rssHeaderList') == null) {
        return;
    }
    for (var rsIndex = 0; rsIndex < g_CurrentRssTotalItems; rsIndex++) {
        document.getElementById('rssHeaderList').childNodes.item(rsIndex).style.color = '';
        document.getElementById('detailviewitem' + rsIndex).style.display = 'none';
    }

    if (document.getElementById('detailviewitem' + next) != null) {
        // set display active
        document.getElementById('detailviewitem' + next).style.display = 'inline';
    }
    if ((document.getElementById('rssHeaderList') != null) && (document.getElementById('rssHeaderList').childNodes != null) && (document.getElementById('rssHeaderList').childNodes.length > 0) && (document.getElementById('rssHeaderList').childNodes.item(next) != null)) {
        // set list item to selected color
        document.getElementById('rssHeaderList').childNodes.item(next).style.color = g_CurrentRssSelectedColor;
    }
}

function TextShowZoneTime(timePos) {
    var currentItem = (timePos - (timePos % g_CurrentTextlinesDuration)) / g_CurrentTextlinesDuration;

    TextShowItem(currentItem);
}

function RssShowZoneTime(timePos) {
    var currentItem = (timePos - (timePos % g_CurrentRssItemDuration)) / g_CurrentRssItemDuration;

    if (g_CurrentRssTotalItems == 0) {
        return;
    }

    while (currentItem >= g_CurrentRssTotalItems) {
        currentItem = currentItem - g_CurrentRssTotalItems;
    }

    if (currentItem < 0) {
        currentItem = 0;
    }

    RssShowItem(currentItem);
}

function RssShowTime(timePos) {
    var currentItem = (timePos - (timePos % g_CurrentRssItemDuration)) / g_CurrentRssItemDuration;
    while (currentItem >= g_CurrentRssTotalItems) {
        currentItem = currentItem - g_CurrentRssTotalItems;
    }
    if (currentItem < 0) currentItem = 0;
    RssShowItem(currentItem);
}

function FlipZoneTimer() {
    if (timeFlipTimer != 0) {
        window.clearTimeout(timeFlipTimer);
    }

    timeFlipTimer = 0;

    if (g_CurrentContentType == 'video') {
        g_FlipperTime = Math.floor(document.getElementById('VidPlayer').controls.currentPosition);

        if ((g_FlipperTime > g_CurrentContentDuration) || (document.getElementById('VidPlayer').playState == 1)) {
            EndZoneContent();
            GetNextZoneItem();
        }
        else {
            timeFlipTimer = window.setTimeout('FlipZoneTimer()', 250);
        }
    }
    else if (g_CurrentContentType == 'flvideo') {
        var flvid = getFlashMovieObject('FLVidPlayer');

        if (flvid != null) {
            g_FlipperTime = Math.floor(parseFloat(flvid.vidGetPosition()));

            if ((g_FlipperTime >= g_CurrentContentDuration) || (flvid.vidGetState() == 1)) {
                EndZoneContent();
                GetNextZoneItem();
            }
            else {
                timeFlipTimer = window.setTimeout('FlipZoneTimer()', 250);
            }
        }
    }
    else {
        g_FlipperTime++;

        if (g_FlipperTime > g_CurrentContentDuration) {
            EndZoneContent();
            GetNextZoneItem();
        }
        else {
            if (g_CurrentContentType == 'rss') {
                RssShowZoneTime(g_FlipperTime);
            }
            else if (g_CurrentContentType == 'textlines') {
                TextShowZoneTime(g_FlipperTime);
            }

            timeFlipTimer = window.setTimeout('FlipZoneTimer()', 1000);
        }
    }
}

function FlipTimer() {
    if (timeFlipTimer != 0)
        window.clearTimeout(timeFlipTimer);
    timeFlipTimer = 0;
    if (g_CurrentContentType == 'video') {
        var flvid = null;

        flvid = getFlashMovieObject('FLVidPlayer');

        if (flvid != null /*&& flvid.readyState*/) {
            g_FlipperTime = Math.floor(parseFloat(flvid.vidGetPosition()));

            if ((g_FlipperTime >= g_CurrentContentDuration) || (flvid.vidGetState() == 1)) {
                EndContent();
                GetNextItem();
            }
            else {
                SetProgressBarInPercent((100 * flvid.vidGetBytesLoaded()) / flvid.vidGetBytesTotal());
                var flipSecs = g_FlipperTime % 60;
                SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
                SetDragPosition((100 * g_FlipperTime) / g_CurrentContentDuration);
                timeFlipTimer = window.setTimeout('FlipTimer()', 250);
            }
        }
        else {
            var vid = document.getElementById('Html5VideoPlayer');

            if (vid != null) {
                g_FlipperTime = Math.floor(parseFloat(vid.currentTime));

                if ((g_FlipperTime >= g_CurrentContentDuration) || vid.ended) {
                    EndContent();
                    GetNextItem();
                }
                else {
                    if (vid.buffered) {
                        SetProgressBarInPercent((100 * vid.buffered.end(0)) / vid.duration)
                    }

                    var flipSecs = g_FlipperTime % 60;
                    SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
                    SetDragPosition((100 * g_FlipperTime) / g_CurrentContentDuration);
                    timeFlipTimer = window.setTimeout('FlipTimer()', 250);
                }
            }
        }
        //        if ((document.getElementById('VidPlayer') != null) && (document.getElementById('VidPlayer').controls != null) && (document.getElementById('VidPlayer').controls.currentPosition != null))
        //        {
        //            g_FlipperTime = Math.floor(document.getElementById('VidPlayer').controls.currentPosition);
        //            
        //            if((g_FlipperTime > g_CurrentContentDuration) || (document.getElementById('VidPlayer').playState == 1))
        //            {
        //                EndContent();
        //                GetNextItem();
        //            }
        //            else
        //            {
        //                var vidProgress = GetVideoProgress();
        //                vidProgress = (vidProgress == 0) ? 100 : vidProgress;
        //                SetProgressBarInPercent(vidProgress);
        //                var flipSecs = g_FlipperTime % 60;
        //                SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
        //                SetDragPosition((100 * g_FlipperTime) / g_CurrentContentDuration);
        //                timeFlipTimer = window.setTimeout('FlipTimer()', 250);
        //            }
        //        }
    }
    else if (g_CurrentContentType == 'flvideo') {
        var flvid = getFlashMovieObject('FLVidPlayer');
        if (flvid != null) {
            g_FlipperTime = Math.floor(parseFloat(flvid.vidGetPosition()));
            if ((g_FlipperTime >= g_CurrentContentDuration) || (flvid.vidGetState() == 1)) {
                EndContent();
                GetNextItem();
            }
            else {
                SetProgressBarInPercent((100 * flvid.vidGetBytesLoaded()) / flvid.vidGetBytesTotal());
                var flipSecs = g_FlipperTime % 60;
                SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
                SetDragPosition((100 * g_FlipperTime) / g_CurrentContentDuration);
                timeFlipTimer = window.setTimeout('FlipTimer()', 250);
            }
        }
    }
    else {
        g_FlipperTime++;
        if (g_FlipperTime >= g_CurrentContentDuration) {
            EndContent();
            GetNextItem();
        }
        else {
            if (g_CurrentContentType == 'rss') {
                RssShowTime(g_FlipperTime);
            }
            else if (g_CurrentContentType == 'textlines') {
                TextShowZoneTime(g_FlipperTime);
            }

            var flipSecs = g_FlipperTime % 60;
            SetTimePosition(padZero(Math.floor(g_FlipperTime / 60)) + ':' + padZero(flipSecs));
            SetDragPosition((100 * g_FlipperTime) / g_CurrentContentDuration);
            timeFlipTimer = window.setTimeout('FlipTimer()', 1000);
        }
    }
}

function videoUpdateProgress(evt) {
    SetProgressBarInPercent((evt.loaded / evt.total) * 100);
}

function EndZoneContent() {
    if (timeFlipTimer != 0) {
        window.clearTimeout(timeFlipTimer);
        timeFlipTimer = 0;
    }

    if (flashVidCheckTimer != 0) {
        window.clearTimeout(flashVidCheckTimer);
        flashVidCheckTimer = 0;
    }

    if (g_CurrentContentType == 'flvideo') {
        var flvid = getFlashMovieObject('FLVidPlayer');
        var state = 0;
        if (flvid != null) {
            try { state = flvid.vidGetState(); } catch (e) { }
            if (state == 3) {
                flvid.vidPause();
            }
        }
    }
    else if (g_CurrentContentType == 'video') {
        if ((document.getElementById('VidPlayer') != null) && (document.getElementById('VidPlayer').controls != null) && (document.getElementById('VidPlayer').controls.currentPosition != null)) {
            document.getElementById('VidPlayer').controls.stop();
        }
    }
}

function EndContent() {
    //TODO: If its a video, "stop()" the video

    if (timeFlipTimer != 0) {
        window.clearTimeout(timeFlipTimer);
        timeFlipTimer = 0;
    }

    if (flashVidCheckTimer != 0) {
        window.clearTimeout(flashVidCheckTimer);
        flashVidCheckTimer = 0;
    }

    if (rssGetTimer != 0) {
        window.clearTimeout(rssGetTimer);
        rssGetTimer = 0;
    }

    if (wmpfschecker != 0) {
        window.clearTimeout(wmpfschecker);
        wmpfschecker = 0;
    }

    // SetTitle, SetTimePosition
    SetTitle('');
    SetTimePosition('--:--');
    SetProgressBarInPercent(0);
    SetDragPosition(0);

    CancelDrag();

    if (g_CurrentContentType == 'flvideo') {
        var flvid = getFlashMovieObject('FLVidPlayer');
        var state = 0;
        if (flvid != null) {
            try { state = flvid.vidGetState(); } catch (e) { }
            if (state == 3) {
                flvid.vidPause();
            }
        }
    }
    else if (g_CurrentContentType == 'video') {
        //        if ((document.getElementById('VidPlayer') != null) && (document.getElementById('VidPlayer').controls != null) && (document.getElementById('VidPlayer').controls.currentPosition != null))
        //        {
        //            document.getElementById('VidPlayer').controls.stop();
        //        }
        var flvid = getFlashMovieObject('FLVidPlayer');
        var state = 0;
        if (flvid != null && flvid.readyState) {
            try { state = flvid.vidGetState(); } catch (e) { }
            if (state == 3) {
                flvid.vidPause();
            }
        }
        else if (g_UseYouTube) {
            swfobject.removeSWF('ytplayer');
        }
        else {
            var vid = document.getElementById('Html5VideoPlayer');

            if (vid != null) {
                if (!vid.paused) {
                    vid.pause();
                }
            }
        }
    }

}

function endEmbedContent() {
    if (timeEmbedTimer != 0) {
        window.clearTimeout(timeEmbedTimer);
        timeEmbedTimer = 0;
    }

    if (rssGetTimer != 0) {
        window.clearTimeout(rssGetTimer);
        rssGetTimer = 0;
    }

    if (textGetTimer != 0) {
        window.clearTimeout(textGetTimer);
        textGetTimer = 0;
    }

    if (g_CurrentContentType == 'video') {
        var flvid = getFlashMovieObject('FLVidPlayer');
        var state = 0;
        if (flvid != null && flvid.readyState) {
            try { state = flvid.vidGetState(); } catch (e) { }
            if (state == 3) {
                flvid.vidPause();
            }
        }
        else {
            var vid = document.getElementById('Html5VideoPlayer');

            if (vid != null) {
                if (!vid.paused) {
                    vid.pause();
                }
            }
        }
    }
}

var AvailableStreams = new Array(512, 768, 1024, 1200);

//Take into account detected bandwidth, return highest available stream that is less than 75% of available bandwidth.
function GetDetectedStreamLevel() {
    var preferredBitrate = 0.75 * g_DetectedBitrate;
    var bitrateToUse = 512;

    for (var rateIndex = 0; rateIndex < AvailableStreams.length; rateIndex++) {
        if (AvailableStreams[rateIndex] < preferredBitrate) {
            bitrateToUse = AvailableStreams[rateIndex];
        }
    }

    return bitrateToUse;
}

function GetStreamLevelInUse() {
    return g_BitrateInUse;
}

function GetPreviousZoneItem() {
    if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
        if (ZoneSchedule.childNodes.length == 1 && ZoneSchedule.childNodes.item[0].getAttribute('CTID') == g_CurrentContentID) {
            // only 1 item scheduled so show it again
            zoneShowItem(ZoneSchedule.childNodes[0]);
        }
        else {
            var ctid = null;

            for (var i = ZoneSchedule.childNodes.length - 1; i >= 0; i--) {
                if (ZoneSchedule.childNodes[i].getAttribute('CTID') == g_CurrentContentID) {
                    if (i == 0) {
                        // content item is start of schedule so do nothing
                        return;
                    }
                    else {
                        // get the previous item
                        ctid = ZoneSchedule.childNodes[i - 1].getAttribute('CTID');
                        break;
                    }
                }
            }

            if (ctid != null) {
                zoneItemClick(ctid);
            }
        }
    }
}

function GetNextZoneItem() {
    if ((ZoneSchedule != null) && (ZoneSchedule.childNodes.length > 0)) {
        if (ZoneSchedule.childNodes.length == 1 && ZoneSchedule.childNodes.item(0).getAttribute('CTID') == g_CurrentContentID) {
            // only 1 item scheduled so show it again
            zoneShowItem(ZoneSchedule.childNodes[0]);
        }
        else {
            var ctid = null;

            for (var i = 0; i < ZoneSchedule.childNodes.length; i++) {
                if (ZoneSchedule.childNodes[i].getAttribute('CTID') == g_CurrentContentID) {
                    if ((i + 1) == ZoneSchedule.childNodes.length) {
                        // end of schedule so go back to start
                        ctid = ZoneSchedule.childNodes[0].getAttribute('CTID');
                        break;
                    }
                    else {
                        // get next item
                        ctid = ZoneSchedule.childNodes[i + 1].getAttribute('CTID');
                        break;
                    }
                }
            }

            if (ctid != null) {
                zoneItemClick(ctid);
            }
        }
    }
}

function GetNextItem() {
    // Find next item from Schedule doc
    var ctid = null;
    var lastItem = null;

    if ((Schedule != null) && (Schedule.childNodes.length > 0)) {
        if (Schedule.childNodes.length == 1 && Schedule.childNodes.item(0).getAttribute('ID') == g_CurrentContentID) {
            // Show "Play Again" screen as there is only one item in the Guide
            SetTitle('Finished');
            document.getElementById('V3PlayAgainImage').style.display = 'inline';
            document.getElementById('V3PlayAgainImage').style.cursor = 'pointer';
            document.getElementById('V3PlayAgainImage').onclick = function () {
                document.getElementById('V3PlayAgainImage').style.display = 'none';
                ShowItem(g_CurrentContentItem, 0);
            }
            document.getElementById('V3LoadingImage').style.display = 'none';
            document.getElementById('ActualContentHolder').style.display = 'none';
        }
        else {
            var chanElement = Schedule;

            for (var schIndexContent = 0; schIndexContent < chanElement.childNodes.length; schIndexContent++) {
                if (chanElement.childNodes.item(schIndexContent).getAttribute('ID') == g_CurrentContentID) {
                    lastItem = chanElement.childNodes.item(schIndexContent);
                }
            }

            if ((lastItem != null) && (lastItem.nextSibling != null)) {
                ctid = lastItem.nextSibling.getAttribute('ID');
            }
            else {
                ctid = chanElement.childNodes.item(0).getAttribute('ID');
                var GuideC = document.getElementById('V3GuideContent');
                GuideC.scrollTop = 0;
            }

            SetTitle('Loading: 0%');
            itemclick(ctid);
        }
    }
}

/*


*/

function GetPrevItem() {
    // Find previous item from Schedule doc
    var ctid = null;
    var lastItem = null;

    if ((Schedule != null) && (Schedule.childNodes.length > 0)) {
        var chanElement = Schedule;

        for (var schIndexContent = 0; schIndexContent < chanElement.childNodes.length; schIndexContent++) {
            if (chanElement.childNodes.item(schIndexContent).getAttribute('ID') == g_CurrentContentID) {
                lastItem = chanElement.childNodes.item(schIndexContent);
            }
        }

        if ((lastItem != null) && (lastItem.previousSibling != null)) {
            ctid = lastItem.previousSibling.getAttribute('ID');
        }
        else {
            ctid = chanElement.childNodes.item(chanElement.childNodes.length - 1).getAttribute('ID');
            var GuideC = document.getElementById('V3GuideContent');
            GuideC.scrollTop = 0;
        }

        doMouseClick(document.getElementById('itemdefinition_' + ctid));
    }
}

function setSmallPlayerCSS() {
    document.getElementById('EmbedControlsBackground').className = 'EmbedControlsBackgroundS';
    document.getElementById('EmbedItemLabel').className = 'EmbedItemLabelS';
    document.getElementById('EmbedTimeLabel').className = 'EmbedTimeLabelS';
    document.getElementById('EmbedProgressBarBase').className = 'EmbedProgressBarBaseS';
    document.getElementById('EmbedProgressBar').className = 'EmbedProgressBarS';
    document.getElementById('EmbedPosBall').className = 'EmbedControlItem dragme EmbedPosBallS';
    document.getElementById('EmbedPosReading').className = 'EmbedControlItem EmbedPosReadingS';

    document.getElementById('EmbedPlayPause').className = 'EmbedControlItem EmbedPlayPauseS';
    document.getElementById('EmbedMuteButton').className = 'EmbedControlItem EmbedMuteButtonS';
    document.getElementById('EmbedVolBall').className = 'EmbedControlItem dragme EmbedVolBallS';
    document.getElementById('EmbedVolSlider').className = 'EmbedControlItem EmbedVolSliderS';
    document.getElementById('EmbedRelated').className = 'EmbedControlItem EmbedRelatedS';
    document.getElementById('EmbedMoreInfo').className = 'EmbedControlItem EmbedMoreInfoS';

    document.getElementById('SolusRelatedContent').className = 'EmbedRelatedFrameS';
}

function setupEmbeddedPlayer(isSmallPlayer) {
    DoBrowserCheck();
    DownloadSchedule();

    var webPlayer = document.getElementById('SolusWebPlayer');
    webPlayer.style.width = g_ScreenWidth + 'px';
    webPlayer.style.height = g_ScreenHeight + 'px';

    if (isSmallPlayer) {
        setSmallPlayerCSS();
        var controlsBackground = document.getElementById('EmbedControlsBackground');
        controlsBackground.width = '320';
        controlsBackground.height = '30';
    }

    if (!g_HasFlash && !g_HasHTML5) {
        showPlayOverlay(isSmallPlayer);
        getEmbeddedItem(g_CurrentContentID, false, isSmallPlayer);
    }
    else {
        getEmbeddedItem(g_CurrentContentID, false, isSmallPlayer);
    }
}

var _ContentItemInUse = null;
var _IndexInUse = 0;
var _SmallPlayerInUse = false;

function getEmbeddedItem(ContentID, playNow, isSmallPlayer) {
    showRelatedItems(false);
    _ContentItemInUse = null;
    _IndexInUse = 0;
    _SmallPlayerInUse = isSmallPlayer;

    if (ContentID == '00000000-0000-0000-0000-000000000000') {
        _ContentItemInUse = ContentItems.childNodes.item(0);
        _IndexInUse = 0;
    }
    else {
        if ((ContentItems != null) && (ContentItems.childNodes.length > 0)) {
            for (var ctIndex = 0; ctIndex < ContentItems.childNodes.length; ctIndex++) {
                if (ContentItems.childNodes.item(ctIndex).getAttribute('ID') == ContentID) {
                    _ContentItemInUse = ContentItems.childNodes.item(ctIndex);
                    _IndexInUse = ctIndex;
                    break;
                }
            }
        }
    }

    //    if (Schedule != null && Schedule.childNodes.length > 0) {
    //        for (var ctIndex = 0; ctIndex < Schedule.childNodes.length; ctIndex++) {
    //            if (Schedule.childNodes.item(ctIndex).getAttribute('ID') == ContentID) {
    //                showEmbeddedItem(Schedule.childNodes.item(ctIndex), playNow);
    //                getRelatedItems(ctIndex, isSmallPlayer);
    //                break;
    //            }
    //       }
    //    }

    window.setTimeout('showCurrentEmbeddedItem(' + playNow + ');', 100);

}

function showCurrentEmbeddedItem(playNow) {
    showEmbeddedItem(_ContentItemInUse, playNow);
    getRelatedItems(_IndexInUse, _SmallPlayerInUse);
    if (playNow) {
        document.getElementById('EmbedPlayPause').style.display = '';
        document.getElementById('EmbedPlayPause').src = PauseButtonUrl;
    }
    else {
        showPlayOverlay(_SmallPlayerInUse);
    }

    window.setTimeout('EmbedTimer()', 250);
}

function showEmbeddedItem(ContentItem, playNow) {
    hideEmbedControls(false);
    var ContentHolder = document.getElementById('SolusActualContentHolder');

    g_CurrentContentItem = ContentItem;
    g_CurrentContentID = ContentItem.getAttribute('ID');
    g_CurrentContentType = ContentItem.getAttribute('SimpleType');
    g_CurrentContentDuration = ContentItem.getAttribute('Duration');
    g_CurrentContentTitle = ContentItem.getAttribute('WebTitle');

    if (ContentItem.getAttribute('WebURL') != '') {
        $('#EmbedMoreInfo').show();
    }
    else {
        $('#EmbedMoreInfo').hide();
    }


    g_UseYouTube = (ContentItem.getAttribute('UseYouTube') == '1');

    switch (g_CurrentContentType) {
        case 'video':
            var vidUrl = getItemLocation(g_CurrentContentID, g_CurrentContentType, ContentItem);
            var play = '';

            if (playNow) {
                play = 'autoplay';
            }

            if (g_ForceHTML5 && g_HasHTML5)
                g_UsingHTML5 = true;
            else if (!g_HasFlash && g_HasHTML5)
                g_UsingHTML5 = true;
            else
                g_UsingHTML5 = false;

            var vidScript = '';

            if (!g_UseYouTube) {
                if (g_UsingHTML5) {
                    vidScript = '<video id="Html5VideoPlayer" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" ' + play + '>';
                    vidScript += '<source src="' + vidUrl + '" type="video/mp4">';
                    vidScript += '<source src="http://10.1.1.119/soluspromo640.ogv" type="video/ogg">';
                    vidScript += '</video>';
                }
                else if (g_HasFlash) {
                    if (playNow) {
                        vidScript += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" id="FLVidPlayer" align="middle">';
                        vidScript += '<param name="allowScriptAccess" value="sameDomain" />';
                        vidScript += '<param name="Movie" value="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" />';
                        vidScript += '<param name="wmode" value="transparent" />';
                        vidScript += '<embed src="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" quality="high" bgcolor="#000000" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FLVidPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="true" wmode="transparent"/></object>';
                    }
                }
                else {
                    vidScript = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';

                    var overlay = document.getElementById('SolusPlayOverlay');

                    if (overlay != null && overlay.style.display != 'none') {
                        overlay.style.display = 'none';
                    }

                    hideEmbedControls(true);
                }
            }
            else {
                var ytid = ContentItem.getAttribute('YouTubeID');

                if (ytid != null) {

                    //                    vidScript = '<object width="' + g_ScreenWidth + '" height="' + (g_ScreenHeight + 25) + '" id="player"><param name="movie" value="http://www.youtube.com/v/'
                    //                        + ytid + '&hl=en_GB&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'
                    //                        + ytid + '&hl=en_GB&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'
                    //                        + g_ScreenWidth + '" height="' + (g_ScreenHeight + 25) + '" id="player"></embed></object>';

                    ContentHolder.innerHTML = '<div id="ytplayer"><p>You need Flash installed to view this content</p></div>';
                    var autoplay = '';

                    if (playNow) {
                        autoplay = '&autoplay=1';
                    }

                    var params = { allowScriptAccess: "always", allowFullScreen: "true" };

                    swfobject.embedSWF('http://www.youtube.com/v/' + ytid + '&enablejsapi=1&playerapiid=ytplayer&rel=0&fs=1' + autoplay,
                            'ytplayer', g_ScreenWidth + '', (g_ScreenHeight + 25) + '', '8', null, null, params);

                    hideEmbedControls(true);
                }
                else {
                    vidScript = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';

                    var overlay = document.getElementById('SolusPlayOverlay');

                    if (overlay != null && overlay.style.display != 'none') {
                        overlay.style.display = 'none';
                    }

                    hideEmbedControls(true);
                    window.setTimeout('showRelatedItems(true)', 10000);
                }
            }

            if (!g_UseYouTube) {
                ContentHolder.innerHTML = vidScript;
            }

            firstTimePlay = true;

            var vid = document.getElementById('Html5VideoPlayer');
            if (vid != null) {
                vid.load();
                vid.addEventListener('progress', videoUpdateProgress, false);
            }

            break;
        case 'image':
            ContentHolder.innerHTML = '<img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="data.aspx?ctid=' + g_CurrentContentID + '" />';
            SetProgressBarInPercent(100);
            PlayState = 1;
            break;
        case 'flash':
            ContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '"><param name="quality" value="high"><embed src="data.aspx?ctid=' + g_CurrentContentID + '" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
            SetProgressBarInPercent(100);
            PlayState = 1;
            break;
        case 'ppt':
            g_CurrentContentType = 'flash';
            ContentHolder.innerHTML = '<object id="FlashPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '"><param name="movie" value="data.aspx?ctid=' + g_CurrentContentID + '&type=flash"><param name="quality" value="high"><embed src="data.aspx?ctid=' + g_CurrentContentID + '&type=flash" quality="high" bgcolor="#FFFFFF" width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" name="FlashPlayer" id="FlashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
            SetProgressBarInPercent(100);
            PlayState = 1;
            break;
        case 'html':
            ContentHolder.innerHTML = '<b style="color: white;">HTML content items are unavailable in the embedded SOLUS player</b>';
            g_CurrentContentDuration = 10;
            break;
        case 'url':
            ContentHolder.innerHTML = '<b style="color: white;">Web content items are unavailable in the embedded SOLUS player</b>';
            g_CurrentContentDuration = 10;
            break;
        case 'textlines':
            PlayState = 1;
            window.setTimeout('DoEmbedText("' + g_CurrentContentID + '", ' + 0 + ');', 10);
            SetProgressBarInPercent(100);
            break;
        case 'rss':
            PlayState = 1;
            window.setTimeout('DoEmbedRss("' + g_CurrentContentID + '");', 10);
            SetProgressBarInPercent(100);
            break;
        default:
            break;
    }

    setEmbedTitle(g_CurrentContentTitle);
    SetTimePosition('00:00');
    SetDragPosition(0);

    g_FlipperTime = -1;
}

function getRelatedItems(CurrentItemNumber, isSmallPlayer) {
    var relatedContentHolder = document.getElementById('SolusRelatedContent');
    if (!isSmallPlayer) {
        relatedContentHolder.innerHTML = '<h3 class="EmbedRelatedTitleN">Guide</h3>';
    }
    else {
        relatedContentHolder.innerHTML = '<h4 class="EmbedRelatedTitleS">Guide</h4>';
    }

    var itemCounter = 0;

    for (var i = 0; i < Schedule.childNodes.length; i++) {
        //if (i != CurrentItemNumber) {
        itemCounter++;

        var thisID = Schedule.childNodes.item(i).getAttribute('ID');
        var thisTitle = Schedule.childNodes.item(i).getAttribute('Title');
        var thisDescription = Schedule.childNodes.item(i).getAttribute('Description');

        if (itemCounter > 12) {
            // only display up to 12 related items
            break;
        }
        else if (itemCounter > 6 && isSmallPlayer) {
            // or 6 related items for the small player
            break;
        }

        var relatedItem = '';

        if (!isSmallPlayer) {
            relatedItem = '<div onselect="return false;" onselectstart="return false;" id="outeritemdefinition_'
                    + thisID + '" style="position: relative; border-style: solid; border-width: 1px; border-color: gray; float: left; width: 33%; margin-top: 15px; overflow: hidden;">'
                    + '<div id="itemdefinition_' + thisID + '" class="EmbedContentItem" onclick="getEmbeddedItem(\'' + thisID
                    + '\', true, false);" onmouseover="hover(this);" onmouseout="unhover(this);"" ><div class="EmbedContentInner"><div class="EmbedContentDescription"><img border="1" align="left" class="EmbedContentThumb" src="thumbimage.aspx?ctid='
                    + thisID + '" width="80" height="48" /><span class="EmbedContentTitle">' + thisTitle + '</span><br />'
                    + thisDescription + '</div></div></div>' /*+ '</div>'*/;
        }
        else {
            // add margin to first item in a row
            var marginStyle = '';
            if (itemCounter % 3 == 1) {
                marginStyle = 'margin-left: 10px;';
            }

            relatedItem = '<div onselect="return false;" onselectstart="return false;" id="outeritemdefinition_'
                    + thisID + '" style="position: relative; border-style: solid; border-width: 1px; border-color: gray; float: left; width: 95px; height: 90px; font-size: x-small; text-align: center; overflow: hidden;' + marginStyle + '">'
                    + '<div id="itemdefinition_' + thisID
                    + '" class="EmbedContentItem" onclick="getEmbeddedItem(\'' + thisID
                    + '\', true, true);" onmouseover="hover(this);" onmouseout="unhover(this);"" ><div class="EmbedContentSmall">'
                    + '<img border="1" align="center" src="thumbimage.aspx?ctid='
                    + thisID + '" width="80" height="48" /><span class="EmbedContentTitle">' + thisTitle + '</span></div></div>' /*+ '</div>'*/;
        }

        relatedContentHolder.innerHTML += relatedItem;
        //}
    }

    if (!isSmallPlayer) {
        relatedContentHolder.innerHTML += '<a href="javascript:void(0);" onclick="replayItem();" class="ReplayLinkN">Replay<img style="width: 10px;" src="' + PlayButtonUrl + '" alt="Play"/></a>';
    }
    else {
        relatedContentHolder.innerHTML += '<a href="javascript:void(0);" onclick="replayItem();" class="ReplayLinkS" >Replay<img style="width: 10px;" src="' + PlayButtonUrl + '" alt="Play"/></a>';
    }
}

function showPlayOverlay(isSmallPlayer) {
    var ContentHolder = document.getElementById('SolusActualContentHolder');

    var playOverlay = document.createElement('div');
    playOverlay.setAttribute('id', 'SolusPlayOverlay');

    if (!isSmallPlayer) {
        playOverlay.setAttribute('class', 'SolusPlayOverlayN');
    }
    else {
        playOverlay.setAttribute('class', 'SolusPlayOverlayS');
    }

    playOverlay.setAttribute('onclick', 'hidePlayOverlay();');

    var bgimg = "url('thumbimage.aspx?ctid=" + g_CurrentContentID + "&width=" + g_ScreenWidth + "&height=" + g_ScreenHeight + "')";
    if (g_HasFlash) {
        playOverlay.style.backgroundImage = bgimg;
    }

    var playButton = document.createElement('img');
    playButton.setAttribute('id', 'SolusPlayButton');
    playButton.setAttribute('src', 'images/PlayBut-Tr.png');
    playButton.setAttribute('alt', '');

    if (!isSmallPlayer) {
        playButton.setAttribute('class', 'SolusPlayButtonN');
    }
    else {
        playButton.setAttribute('class', 'SolusPlayButtonS');
    }

    playButton.setAttribute('onmouseover', 'changePlayButton(true);');
    playButton.setAttribute('onmouseout', 'changePlayButton(false);');

    ContentHolder.appendChild(playOverlay);
    playOverlay.appendChild(playButton);
    document.getElementById('EmbedPlayPause').style.display = 'none';
    _OverlayShowing = true;
}

function replayItem() {
    document.getElementById('SolusMainContentHolder').style.display = 'inline';
    document.getElementById('SolusVideoControls').style.display = 'inline';
    document.getElementById('SolusRelatedContent').style.display = 'none';

    g_FlipperTime = -1;

    // set delay to prevent the position bar for Flash in Firefox from not working
    window.setTimeout('replayItem2();', 100);
}

function replayItem2() {
    PauseVideo();

    PlayState = 1;
    var playButton = document.getElementById('EmbedPlayPause');
    playButton.src = PauseButtonUrl;
    playButton.style.display = '';

    // Flash doesn't always start playing
    if (g_CurrentContentType == 'flash') {
        getFlashMovieObject('FlashPlayer').Play();
    }

    window.setTimeout('EmbedTimer();', 250);
}

function btnhover(thisobj) {
    if (thisobj.src.indexOf('_En.png') > 0) {
        thisobj.src = thisobj.src.replace('_En.png', '_Hov.png');
    }
}

function btnunhover(thisobj) {
    if (thisobj.src.indexOf('_Hov.png') > 0) {
        thisobj.src = thisobj.src.replace('_Hov.png', '_En.png');
    }
}

function DoBrowserCheck() {
    // Check to see if Flash / WMP / XML supported.
    // Set global vars which can then be used by ShowItem to act accordingly

    g_HasFlash = DetectFlashVer(9, 0, 0);
    g_HasWMP = windowsmedia.ver9;
    g_HasXML = CheckXMLHTTPRequest();
    g_IsIE = ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version >= 6));
    g_HasHTML5 = supportsHtml5Video();
}

function supportsHtml5Video() {
    return ((!!document.createElement('video').canPlayType) || (g_IsIE && BrowserDetect.version >= 9));
}

function ShowNotSupported() {
    //ShowMainPane();
    document.getElementById('MainPanel').style.display = 'inline';
    document.getElementById('BandCheckPanel').style.display = 'none';

    var InfoPane = document.getElementById('V3InfoPane');

    InfoPane.innerHTML = 'Not currently supported';

    var ContentHolder = document.getElementById('ActualContentHolder');
    var LoadingImage = document.getElementById('V3LoadingImage');

    ContentHolder.innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img width="' + g_ScreenWidth + '" height="' + g_ScreenHeight + '" border="0" src="' + ResourceUrl + 'NoFlash.png" /></a>';
    LoadingImage.style.display = 'none';
    ContentHolder.style.display = 'inline';
    SetTitle('Not supported');
}

function doMouseClick(obj) {
    obj.onclick();
}

function findSWF(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

var hoverAppend = '_hover';

function Highlight(obj) {
    if (obj.className.indexOf(hoverAppend) < 0)
        obj.className = obj.className + hoverAppend;
}

function Unhighlight(obj) {
    if (obj.className.indexOf(hoverAppend) >= 0) {
        var hovName = obj.className
        obj.className = hovName.substring(0, hovName.length - hoverAppend.length);
    }
}

function LogError(message, url, line) {
    try {
        var xm = null;
        if (window.XMLHttpRequest) {
            xm = new XMLHttpRequest();
        }
        else {
            xm = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xm.open("GET", 'Log.aspx?logtype=error&message=' + message + '&url=' + url + '&line=' + line + '&viewtype=&random=' + (new Date()).getTime(), true);
        xm.send(null);
    }
    catch (e) {
        //
    }
}

function LogItem(ctid, chid, skinid, bitrate) {

    var xm = null;
    if (window.XMLHttpRequest) {
        xm = new XMLHttpRequest();
    }
    else {
        xm = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xm.open("GET", 'Log.aspx?logtype=view&ctid=' + ctid + '&chid=' + chid + '&skinid=' + skinid + '&bitrate=' + bitrate + '&random=' + (new Date()).getTime(), true);
    xm.send(null);
}

function FlashIsFullScreen(bFull) {
    g_FlashFullScreen = bFull;
}

function ShowMainPanel() {
    getObj('MainPanel').style.display = '';
    getObj('BandCheckPanel').style.display = 'none';
}
function SetPreloadTitle(title) {
    getObj('BWCheckText').innerHTML = title;
}

function getObj(id) {
    return document.getElementById(id);
}
