﻿// JScript File

// Passed in from document:

// gActiveChannel
// gActiveContent
// gActiveSkin
// ResourceUrl
// MediaServerDisabled
// BandwidthCheckDisabled
// ShowContent
// gSchedUrl
// BaseHostLocation

// Global Vars

var g_BitrateInUse = 0;
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 = 384;

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_ForceFLV = false;
var g_ForceWMP = 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;

function LoadSite()
{

    InitialiseControls();
    DoBrowserCheck();

    g_CurrentChannelID = gActiveChannel;
    g_CurrentSkinID = gActiveSkin;
    g_LastGuideSchedUrl = gSchedUrl;
    g_FirstGuideSchedUrl = gSkinSchedUrl;
    if ((g_IsIE && g_HasWMP) || (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 isWMP = g_HasWMP && !g_ForceFLV;
        
    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 />';
    }
    
    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;
    }
    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';
}

function unhover(itemobj)
{
    if(itemobj.className == 'HoverContentItem')
    itemobj.className = 'ContentItem';
}

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;
    }
}

function ShowItem(ContentItem, timeOffset)
{
    
    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) && (!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)
            {}
        }
        
        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;
    }
    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 = 'http://' + g_FLVStreamServer + '/Encoded/' + ContentItem.getAttribute('FileTimeStamp') + '_' + ContentItem.getAttribute('ID') + '_' + GetStreamLevelInUse() + 'flv.flv';

                if(FSFollowOn)
                {
                
		            getFlashMovieObject('FLVidPlayer').vidPlayNext(vidUrl);
                    flashVidCheckTimer = window.setTimeout('getFlashMovieObject(\'FLVidPlayer\').vidPlay();CheckFlashVideoFile(' + timeOffset + ')', 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="640" height="384" 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="true" />';
                        flvScript += '<embed src="FLVLoaderCS3.swf?VideoStreamPath=' + vidUrl + '" quality="high" bgcolor="#000000" width="640" height="384" name="FLVidPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="true" />';
                        flvScript += '</object>';
                    ContentHolder.innerHTML = flvScript;
                    ContentHolder.style.display = 'inline';
                    LoadingImage.style.display = 'none';
                    CheckFlashVideoHolder(timeOffset);
                }
            }
            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;
    }
}

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 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: 640px; height: 384px; 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)');};
        }
        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)');};
                }
            }
        }
    }
}

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 = getFlashMovieObject('FLVidPlayer');
    try
    {
        var loaded = flvid.PercentLoaded();
    }
    catch(e)
    {
	// TODO: Catch infinite loop here
        flashVidCheckTimer = window.setTimeout('CheckFlashVideoHolder(' + timeOffset + ')', 100);
        return;
    }
    
    if(flvid != null)
    {
        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);    
        }
    }
}

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 = getFlashMovieObject('FLVidPlayer');
    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);
        }
    }
}

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 == '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'))
    {
        SetProgressBarInPercent(100);
        PlayState = 1
        document.getElementById('PlayPause').src = PauseButtonUrl;
        document.getElementById('PlayPause').style.display = 'inline';
    }
    else //if(g_CurrentContentType == 'flash')
    {
    	SetProgressBarInPercent(100);
    }
    
    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;
            }
            break;
        case 'flvideo':
    
            var flvid = getFlashMovieObject('FLVidPlayer');
            if (flvid != null)
            {
                flvid.vidSetPosition(position);
            }
            break;
        case 'rss':
            RssShowTime(position);
            break;
    }
    
    if (!firstrun)
    {
        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();
        }
    }
}

function SetPositionPercent(positionpercent)
{
    var newPos = ((positionpercent / 100.0) * g_CurrentContentDuration);
    SetPositionTime(newPos, false);
}

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 ((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 (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;

    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')
    {
        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);
            }
            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 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 AvailableStreams = new Array(96, 256, 512, 768, 1024);

//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 = 96;
    
    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 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));
}

function ShowNotSupported()
{
    ShowMainPane();
    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);
	}