﻿                                
                                /*    PlayerFuncs.js                 */
                                /*                                  */
                                /*    Author:Yossi Birenboim (4/8/2009) */
                               /*                                                          */ 
                               /*    java script class which deals with   
                                      embedding tegrity player inside viewer
                                      used by: InstructorViewer.aspx,InstructorClassEditor.aspx,IsoTemplate.aspx */
                                
var DEFAULT_WIDTH = 990;
var DEFAULT_HEIGHT = 582;
var PLAYER_WIDTH_PIXELS_TRASHHOLD = 20;


//return positon (x,y) coordinate of an element  
function getPageCoordinates(obj) {

    var coords;
    if (obj)
        coords = { x: 0, y: 0, width: obj.offsetWidth, height: obj.offsetHeight };
    else
        coords = { x: 0, y: 0, width: 0, height: 0 };


    if (obj.offsetParent) {
        coords.x += obj.offsetLeft;
        coords.y += obj.offsetTop;
        while (obj = obj.offsetParent) {
            coords.x += (obj.offsetLeft - obj.scrollLeft + obj.clientLeft);
            coords.y += (obj.offsetTop - obj.scrollTop + obj.clientTop);
        }
    }



    return coords;
} 


function Size(nWidth, nHeight) {
    this.width = Number(nWidth);
    this.height = Number(nHeight);
}

//set size (width,height) of frmPlayer iframe
function SetPlayerSize(frmPlayer, frmPlayerSize, tdPlayer,resizeGeometry) {

    var browser = GetBrowser();

    var playerPos = getPageCoordinates(tdPlayer);

    //IExplorer does not support window.innerWidth,window.innerHeight (other browsers do support)
    var maxWidth = (browser == "IExplorer" ? document.documentElement.clientWidth : window.innerWidth) - playerPos.x - 20;
    var maxHeight = (browser == "IExplorer" ? document.documentElement.clientHeight : window.innerHeight) - playerPos.y;

    var oSize = null;
    //session has 'GetPlayerSize.htm' under its class folder
    if (frmPlayerSize.contentWindow.GetPlayerOptimalSize)
        oSize = frmPlayerSize.contentWindow.GetPlayerOptimalSize(new Size(maxWidth, maxHeight), true);

    if (oSize == null) 
        oSize = new Size(maxWidth, maxHeight);
    
    if (oSize != null) {
        if (oSize.width + PLAYER_WIDTH_PIXELS_TRASHHOLD < maxWidth) {
            frmPlayer.width = maxWidth;
            frmPlayer.height = maxHeight;
        }
        else {
            if (browser == "IExplorer") {
                oSize.width += 4;
                oSize.height += 4;
            }
            frmPlayer.width = oSize.width;
            frmPlayer.height = oSize.height;

            if (resizeGeometry) {
                var factor = (browser == "IExplorer" ? 1 : 10);
                document.getElementById("plrTopSpecialControlArea").style.width = frmPlayer.clientWidth + factor;
                document.getElementById("topDiv").style.width = frmPlayer.clientWidth + factor;
                document.getElementById("logoBorder").style.width = frmPlayer.clientWidth + factor + 6;
            }
        }
    }
}

//called when user clicks on tutorial button when session is being played in local mode (DVD image)
function AlertNotAvailForLocal() {
    alert("Tutorials are not available in DVD mode.");
}