var Projector = new Object();

/*
    Initialize projector
*/
Projector.Init = function(id, htmlObject)
{
    this.Id = id;
    this.HtmlObject = htmlObject;
    
    this._notifyees = new Array();
}

/*
    Creates the following html code:
        
    <iframe allowtransparency="true" src="[!url]" frameBorder="0" name="[!id]_frame" id="[!id]_frame" class="[!id]_frame">
    </iframe>
*/
Projector.OpenUrl = function(url)
{
    this.CloseCurrentMenuitem();

    // load iframe in the container
    var iframe = document.getElementById(this.Id + "_frame");

    if (iframe == null)
    {
        this.HtmlObject.innerHTML = '<iframe allowtransparency="true" src="' + url + '" frameBorder="0" name="' + this.Id + '_frame" id="' + this.Id + '_frame" class="' + this.Id + '_frame" onload="Projector.FrameLoaded();"></iframe>';
    } else
    {
        iframe.src = url;
    }
}

Projector.OpenPopupDocument = function(url)
{
    window.open(url, "_blank", "channelmode=no, fullscreen=no, directories=yes, scrollbars=yes, location=yes, toolbar=yes, menubar=yes, titlebar=yes, resizable=yes");
}

Projector.CloseCurrentMenuitem = function()
{
    // Close active item
    if (this.ActiveItemId != null)
    {
        // retrieve frame object
        var iframe = document.getElementById(this.id + '_frame');
        
        if (iframe != null) iframe.style.display = "none";

        Navigator.ProjectorLoad(this.ActiveItemId, false);

        this.ActiveItemId = null;
    }
}

/*
    Notifies the Content object that a new page has been loaded into the
    Content frame.
*/
Projector.FrameLoaded = function()
{
    // Close active item
    this.CloseCurrentMenuitem();

    // retrieve frame object
    var fFrame = document.getElementById(this.Id + '_frame');

    // identify loaded content
    var fMenuitemId;
    fMenuitemId = fFrame.contentWindow.MenuitemId;

    if (fMenuitemId == null)
    {
        alert("Unable to identify loaded document. " + fFrame.contentWindow.location);
        return;
    }

    this.ActiveItemId = fMenuitemId;
    
    // notify menus
    Navigator.ProjectorLoad(this.ActiveItemId, true, fFrame.contentWindow.document.body);
}
