﻿/* ABB Library Flash Player JavaScript Handler */
var LibraryFlashPlayer = {

    /*** Properties ***/

    /* Document (flv video) ID */
    documentId: '',

    /* Document (flv video) language ISO code. Default is 'en' */
    languageCode: 'en',

    /* Document (flv video) part ID */
    documentPartId: '',

    /* Document (flv video) revision ID */
    documentRevisionId: '',

    /* Flash player Url (<param name="movie" value=MoviePlayerSourceUrl />) */
    moviePlayerSourceUrl: 'http://search.abb.com/Library/Flash/ABBPlayer.swf',

    /* Determines if full screen mode is allowed for the player. Default is true */
    allowFullScreen: true,

    /* Determines menu should be visible. Default is false  */
    showMenu: false,

    /* Determines if player should play the movie automatically after opening the page. Default is false */
    autoPlay: false,

    /* Presented player width (in px). Default is 400 */
    width: 400,

    /* Presented player height (in px). Default is 340 */
    height: 340,

    realWidth: 400,

    realHeight: 340,

    /* Player background color (as hex value). Default is black, #000000 */
    backgroundColor: '#000000',

    /* "classid" <object> tag parameter for flash video player. 
    Don't change it if you don't know what you are doing */
    playerClassId: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",

    /* "id" <object> tag. Default is "AbbLibraryFlashPlayer" */
    objectId: 'AbbLibraryFlashPlayer',

    /*** Methods ***/

    getMovieUrl: function(escaped) {
        var movieUrl = "http://search.abb.com/library/Download.aspx?";
        movieUrl += "DocumentID=" + this.documentId;
        movieUrl += "&LanguageCode=" + this.languageCode;
        movieUrl += "&DocumentPartId=" + this.documentPartId;
        movieUrl += "&DocumentRevisionId=" + this.documentRevisionId;
        movieUrl += "&Action=PrintMovieUrl";

        return escaped ? escape(movieUrl) : movieUrl;
    },

    getFlashVars: function() {
        return "fileGate=" + this.getMovieUrl(true) + "&autoplay=" + this.autoPlay.toString();
    },

    getParamTag: function(name, value) {
        return "\t<param name='" + name + "' value='" + value + "' />\r\n";
    },

    getEmbedTag: function(name, value) {
        return "\t\t" + name + "='" + value + "'\r\n";
    },

    createFlashPlayerObject: function(realSize) {
        var presentedWidth = (realSize == true ? this.realWidth : this.width);
        var presentedHeight = (realSize == true ? this.realHeight : this.height);
        
        var flashPlayerCode = "<object id='" + this.objectId + "' width='" + presentedWidth + "' height='" + presentedHeight + "' classid='" + this.playerClassId + "' >\r\n";
        flashPlayerCode += this.getParamTag("movie", this.moviePlayerSourceUrl);
        flashPlayerCode += this.getParamTag("allowScriptAccess", "sameDomain");
        flashPlayerCode += this.getParamTag("scale", "noscale");
        flashPlayerCode += this.getParamTag("allowfullscreen", this.allowFullScreen.toString());
        flashPlayerCode += this.getParamTag("bgcolor", this.backgroundColor);
        flashPlayerCode += this.getParamTag("flashvars", this.getFlashVars());
        flashPlayerCode += "\t<embed\r\n";
        flashPlayerCode += this.getEmbedTag("src", this.moviePlayerSourceUrl);
        flashPlayerCode += this.getEmbedTag("width", presentedWidth);
        flashPlayerCode += this.getEmbedTag("height", presentedHeight);
        flashPlayerCode += this.getEmbedTag("scale", "noscale");
        flashPlayerCode += this.getEmbedTag("allowScriptAccess", "sameDomain");
        flashPlayerCode += this.getEmbedTag("type", "application/x-shockwave-flash");
        flashPlayerCode += this.getEmbedTag("menu", this.showMenu);
        flashPlayerCode += this.getEmbedTag("allowfullscreen", this.allowFullScreen.toString());
        flashPlayerCode += this.getEmbedTag("flashvars", this.getFlashVars());
        flashPlayerCode += "\t/>\r\n";
        flashPlayerCode += "</object>\r\n";

        return flashPlayerCode;
    },

    insertFlashPlayerObject: function(containerId) {
        var container = document.getElementById(containerId);
        if (container) {
            container.innerHTML = this.createFlashPlayerObject(false);
        }
    }
};