    /////////////////////////////////////////////////////////////
    // Identify page as enabled for Media Center. This avoids a warning dialog to user.
    function IsMCEEnabled()
    {
        return true
    }

    //    Global Variables
    var g_oNavigation = null;   // The global instance of the Navigation object
    var g_eDta = null;          // A reference to a debug TextArea HTML element
                                // If you drop a text area in your HTML output
                                // and give it an ID of 'debugTextArea1', 
                                // log output will be printed inside.  
                                // This is useful for debugging purposes.

    var fIsHomePage = false;

    /////////////////////////////////////////////////////////////////
    // Initialization
    function Initialize(fHomePage)
    {
        fIsHomePage = fHomePage;
        //SetFocus();
    }

    /////////////////////////////////////////////////////////////////
    // initNavigation
    // Initializes the Global Navigation Object
    function initNavigation()
    {
        try
        {
            g_eDta = document.getElementById("debugTextArea1");
            if (g_eDta != null)
            {
                g_eDta.innerText = "";
            }
            log("initNavigation()");
            g_oNavigation = new Navigation();
        }
        catch(ex)
        {
            logEx("initNavigation()", ex);
        }

    }

    /////////////////////////////////////////////////////////////////
    // Navigation Object Definition
    // Manages Navigatable Items and state of selected items on in an
    // MSHTML document using an array of items.  Used to facilitate
    // navgation via using Remote Control with up, down, left and right
    // arrow buttons

    // Navigation Properties
    Navigation.prototype.items              = null;
    Navigation.prototype.selectedID         = 0;
    Navigation.prototype.isHomePage         = false;
    Navigation.prototype.selectedItem       = null;

    // Navigation Methods
    Navigation.prototype.init               = Navigation_Init;
    Navigation.prototype.select             = Navigation_Select;
    Navigation.prototype.moveUp             = Navigation_MoveUp;
    Navigation.prototype.moveDown           = Navigation_MoveDown;
    Navigation.prototype.moveLeft           = Navigation_MoveLeft;
    Navigation.prototype.moveRight          = Navigation_MoveRight;
    Navigation.prototype.getItemById        = Navigation_GetItemById;

    /////////////////////////////////////////////////////////////////
    // Navigation Constructor Method
    function Navigation()
    {
        this.init(false);
    }

    /////////////////////////////////////////////////////////////////
    // Navigation Constructor Method
    function Navigation(items)
    {
        this.items = items;
        this.init(false);
    }

    /////////////////////////////////////////////////////////////////
    // Navigation Constructor Method
    function Navigation(bIsHomePage)
    {
        this.init(bIsHomePage);
    }

    /////////////////////////////////////////////////////////////////
    // Navigation Constructor Method
    function Navigation(items, bIsHomePage)
    {
        this.items = items;
        this.init(bIsHomePage);
    }

    /////////////////////////////////////////////////////////////////
    // Navigation Initializiation
    // Called by the constructor to initialize the Navigation
    // data.
    function Navigation_Init(bIsHomePage)
    {
        try
        {
            log("Navigation_Init(" + bIsHomePage + ")");
            this.isHomePage = bIsHomePage;
            if (this.items == null)
            {
                // Auto-generate Items here
                this.items = new Array();
                log("Auto-generating items array");
                var iCount = 0;
                for(var i=0; i < document.all.length; i++)
                {
                    var e = document.all[i];
                    if (e != null)
                    {
                        if (e.nodeName != null)
                        {

                            // Author Note:  This is a demo hack that
                            // ignores any tags that have the navitem='false' 
                            // attibute on them
                            if ((e.attributes != null) && (e.attributes["navitem"] != null) && (e.attributes["navitem"].nodeValue == "false"))
                            {
                                log("ignored a tag");
                            }
                            else
                            {

                                if (e.nodeName == "A")
                                {
                                    this.items.push(new NavItem(iCount, e));
                                    iCount++;
                                    log("Anchor found");
                                }
                                else
                                {
                                    if (e.nodeName == "INPUT")
                                    {
                                        if((e.type != null) && (e.type == "hidden"))
                                        {
                                            // ignore hidden element;
                                        }
                                        else
                                        {
                                            this.items.push(new NavItem(iCount, e));
                                            iCount++;
                                            log("Input found");
                                        }
                                    }
                                    else
                                    {
                                        if (e.nodeName == "TEXTAREA")
                                        {
                                            this.items.push(new NavItem(iCount, e));
                                            iCount++;
                                            log("TextArea found");
                                        }
                                        else
                                        {
                                            if (e.nodeName == "SPAN")
                                            {
                                                this.items.push(new NavItem(iCount, e));
                                                iCount++;
                                                log("Span found");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                this.select(0);
            }
        }
        catch(ex)
        {
            logEx("Navigation_Init()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_SelectItem
    // Selects an Item by ID and sets it's Focus class
    function Navigation_Select(id)
    {
        var oldItem = null;
        var newItem = null;

        try
        {
            oldItem = this.items[this.selectedID];
            if (oldItem != null)
            {
                log("deselecting " + this.selectedID);
                oldItem.deselect();
            }

            newItem = this.items[id];
            if (newItem != null)
            {
                log("selecting " + id);
                newItem.select();
                this.selectedID = id;
                this.selectedItem = newItem;
            }

        }
        catch(ex)
        {
            logEx("Navigation_Select(" + id +")", ex);
            if (oldItem != null)
            {
                oldItem.select();
            }
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_GetItemById
    // Selects an Item by ID and but does not set it's Focus class
    function Navigation_GetItemById(id)
    {
        var foundItem = null;
        try
        {
            return this.items[id];
        }
        catch(ex)
        {
            logEx("getItemById(" + id + ")", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_MoveUp
    // Selects the next Item up from the currently selected item
    function Navigation_MoveUp()
    {
        try
        {
            var currentItem = this.items[this.selectedID];
            var newItem = null;
            var tempItem = null;
            var newDistance = 0;
            var d = 0;
            for(var i = 0; i < this.items.length; i++)
            {
                tempItem = this.items[i];
                if (currentItem.top > tempItem.bottom)
                {
                    d = currentItem.distanceFrom(tempItem, "above");
                    if((newDistance == 0) || (d <= newDistance))
                    {
                        newDistance = d;
                        newItem = tempItem;
                    }
                }
            }

            if (newItem != null)
            {
                this.select(newItem.id);
            }
            else
            {
                this.select(this.selectedID);
            }

        }
        catch(ex)
        {
            logEx("Navigation_MoveUp()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_MoveDown
    // Selects the next Item down from the currently selected item
    function Navigation_MoveDown()
    {
        try
        {
            var currentItem = this.items[this.selectedID];
            var newItem = null;
            var tempItem = null;
            var newDistance = 0;
            var d = 0;
            for(var i = 0; i < this.items.length; i++)
            {
                tempItem = this.items[i];
                if (currentItem.bottom < tempItem.top)
                {
                    d = currentItem.distanceFrom(tempItem, "below");
                    if((newDistance == 0) || (d <= newDistance))
                    {
                        newDistance = d;
                        newItem = tempItem;
                    }
                }
            }

            if (newItem != null)
            {
                this.select(newItem.id);
            }
            else
            {
                this.select(this.selectedID);
            }

        }
        catch(ex)
        {
            logEx("Navigation_MoveDown()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_MoveLeft
    // Selects the next Item to the left of the currently selected item
    function Navigation_MoveLeft()
    {
        try
        {
            var currentItem = this.items[this.selectedID];
            var newItem = null;
            var tempItem = null;
            var newDistance = 0;
            var d = 0;
            for(var i = 0; i < this.items.length; i++)
            {
                tempItem = this.items[i];
                if (currentItem.left > tempItem.right)
                {
                    d = currentItem.distanceFrom(tempItem, "left");
                    if((newDistance == 0) || (d <= newDistance))
                    {
                        newDistance = d;
                        newItem = tempItem;
                    }
                }
            }

            if (newItem != null)
            {
                this.select(newItem.id);
            }
            else
            {
                this.select(this.selectedID);
            }

        }
        catch(ex)
        {
            logEx("Navigation_MoveLeft()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_MoveRight
    // Selects the next Item to the right of the currently selected item
    function Navigation_MoveRight()
    {
        try
        {
            var currentItem = this.items[this.selectedID];
            var newItem = null;
            var tempItem = null;
            var newDistance = 0;
            var d = 0;
            for(var i = 0; i < this.items.length; i++)
            {
                tempItem = this.items[i];
                if (currentItem.right < tempItem.left)
                {
                    d = currentItem.distanceFrom(tempItem, "right");
                    if((newDistance == 0) || (d <= newDistance))
                    {
                        newDistance = d;
                        newItem = tempItem;
                    }
                }
            }

            if (newItem != null)
            {
                this.select(newItem.id);
            }
            else
            {
                this.select(this.selectedID);
            }

        }
        catch(ex)
        {
            logEx("Navigation_MoveLeft()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // Navigation_Disable
    // Disables right click
    function Navigation_Disable()
    {
        if (event.button == 2)
            try
            {
                 window.external.MediaCenter.Dialog("right-click disabled","",1,30,true)				 
            }
            catch(e)
            {
                alert("right-click disabled")
            }
    }

    //:~    End Navigation Object Definition

    /////////////////////////////////////////////////////////////////
    // NavItem Object Definition
    // Represents any Html Object that can be navigated via 
    // up/down/left/right using a Remote Control

    // NavItem Properties
    NavItem.prototype.id            = 0;
    NavItem.prototype.element       = null;
    NavItem.prototype.left          = 0;
    NavItem.prototype.right         = 0;
    NavItem.prototype.top           = 0;
    NavItem.prototype.bottom        = 0;

    NavItem.prototype.distanceFrom  = NavItem_DistanceFrom;
    NavItem.prototype.select        = NavItem_Select;
    NavItem.prototype.deselect      = NavItem_Deselect;
    NavItem.prototype.click         = NavItem_Click;

    /////////////////////////////////////////////////////////////////
    // NavItem Constructor Method
    function NavItem(id, e)
    {
        try
        {
            this.id = id;
            this.element = e;
            if (e != null)
            {
                var rect = e.getBoundingClientRect();
                if (rect != null)
                {
                    this.left = rect.left;
                    this.right = rect.right;
                    this.top = rect.top;
                    this.bottom = rect.bottom;
                }
                else
                {
                    throw "Could not determine this NavItems position on the page";
                }
            }
            else
            {
                throw "An unexpected error occured while creating a NavItem.";
            }

        }
        catch(ex)
        {
            logEx("NavItem(" + e + ")", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // NavItem_DistanceFrom
    // Calculates the distance between to NavItems
    function NavItem_DistanceFrom(navItem, direction)
    {
        try
        {
            var d1;
            var d2;
            var d;
            switch (direction)
            {
            case "left" :
                d1 = Math.pow(navItem.right - this.left,2);
                d2 = Math.pow(navItem.top - this.top,2);

                break;
            case "right" :
                d1 = Math.pow(navItem.left - this.right,2);
                d2 = Math.pow(navItem.top - this.top,2);

                break;
            case "above" :
                d1 = Math.pow(navItem.left - this.left,2);
                d2 = Math.pow(navItem.bottom - this.top,2);

                break;
            case "below" :
                d1 = Math.pow(navItem.left - this.left,2);
                d2 = Math.pow(navItem.top - this.bottom,2);

                break;
            default:
                d1 = Math.pow(navItem.left - this.left,2);
                d2 = Math.pow(navItem.top - this.top,2);
                break;
            }
            d = Math.sqrt(d1 + d2);
            return d;

        }
        catch(ex)
        {
            logEx("NavItem_DistanceFrom(" + navItem + ")", ex);
        }

    }

    /////////////////////////////////////////////////////////////////
    // NavItem_Select
    // Fires the onfocus event of the NavItem
    // Return boolean for success or fail
    function NavItem_Select()
    {
        try
        {
            
            if (this.element != null)
            {
                var bSuccess = this.element.fireEvent("onfocus");
                return bSuccess;
            }

        }
        catch(ex)
        {
            logEx("NavItem_Select", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // NavItem_Deselect
    // Fires the onblur event of the NavItem
    // Return boolean for success or fail
    function NavItem_Deselect()
    {
        try
        {
            if (this.element != null)
            {
                var bSuccess = this.element.fireEvent("onblur");
                return bSuccess;
            }
        }
        catch(ex)
        {
            logEx("NavItem_Deselect()", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // NavItem_Click
    // Fires the onclick event of the NavItem
    // Return boolean for success or fail
    function NavItem_Click()
    {
        var bSuccess;
        try
        {
            
            if(this.element != null)
            {
                bSuccess = this.element.fireEvent("onclick");
                if(this.element.nodeName == "A")
                {
                    if(this.element.href != null)
                    {
                        window.navigate(this.element.href);
                    }
                }
                return bSuccess;
            }
        }
        catch(ex)
        {
            logEx("NavItem_Click()", ex);
            return false;
        }

    }

    //:~    End NavCtrl Object Definition

    /////////////////////////////////////////////////////////////////
    // determine which remote control key the user selected
    // and take appropriate action
    function onScaleEvent(vScale)
    {
        try
        {
            document.body.style.zoom=vScale;
        }
        catch(ex)
        {
            logEx("onScaleEvent(" + vScale + ")", ex);
        }
    }

    /////////////////////////////////////////////////////////////////
    // determine which remote control key the user selected
    // and take appropriate action
    function onRemoteEvent(keyChar)
    {
        try
        {
            switch (keyChar)
            {
            case 0x26:  // Up button selected
                g_oNavigation.moveUp();
                break;

            case 0x28:  // Down button selected
                g_oNavigation.moveDown();
                break;

            case 0x25:  // Left button selected
                g_oNavigation.moveLeft();
                break;

            case 0x27:  // Right button selected
                g_oNavigation.moveRight();
                break;

            case 0x0D:    // Enter button selected, execute link to content/page
                g_oNavigation.selectedItem.click();
                break;

            case 0x08:  // VK_BACK
            case 0xA6:    // Browser Back button selected (this is already handled by Media Center)
                
                break;

            default:
                // ignore all other clicks
            }
        }
        catch(ex)
        {
            logEx("onRemoteEvent(" + keyChar + ")", ex);
        }
    }

    function setItemFocus(idxImg)
    {
        eval("document.all.content" + idxImg + ".className='" + focus_classNameArray[idxImg] + "'");
    }

    function clearItemFocus(idxImg)
    {
       eval("document.all.content" + idxImg + ".className='" + nofocus_classNameArray[idxImg] + "'");
    }

    /////////////////////////////////////////////////////////////////
    // Utility Functions
    function logEx(src, e)
    {
        var sMsg = "";
        sMsg += "Source: " + src + "\n";
        sMsg += "Number: " + e.number + "\n";
        sMsg += "Description: " + e.description + "\n";
        log(sMsg);
    }

    function log(sMsg)
    {
        if (g_eDta != null)
        {
            g_eDta.insertAdjacentText("beforeEnd", sMsg + "\n");
        }
    }

    function debug(msg)
    {
        try
        {
           window.external.MediaCenter.Dialog(msg,"",1,30,true)
        }
        catch(e)
        {
            alert (msg)
        }
    }
