/***********************************************************************************************
 * name: rsjFlash.js
 * desc: Třída pro správu Flashových objektů.
 * auth: Lukáš Mitvalský
 * Copyright © 2008 Welldone s.r.o.
 *
 * depend: independent
 ***********************************************************************************************/

/* Trida pro spravu Flash playeru. */
function rsoFlashPlayer(id,version,fileName,width,height)
{
    this.m_id = id;
    this.m_version = version;
    this.m_fileName = fileName;
    this.m_width = width;
    this.m_height = height;
    this.m_flashVars = new Array(new Array(2));
    
    // dalsi nastaveni ktere je treba provest explicitne
    this.m_quality = "best";
    this.m_displayMode = "transparent";
    this.m_allowFullScreen = true;
    this.m_allowScriptAccess = true;
    this.m_loop = true;
    this.m_showMenu = true;
    this.m_scaleMode = "default";
    this.m_backgroundColor = "";
    
    /* Vygeneruje HTML kod prehravace. Je pouzit tag OBJECT a v nem zanoreny EMBED pro pripad nouze;). */
    this.generateHTML = function()
    {
        var html = "<object";
        html += " id='" + this.m_id + "'";
        html += " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + this.m_version + "'";
        html += " classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
        if (this.m_width > 0) html += " width='" + this.m_width.toString() + "'";
        if (this.m_height > 0) html += " height='" + this.m_height.toString() + "'";
        html += ">";
        
        html += "<param name='movie' value='" + this.m_fileName + "'>";
        html += "<param name='quality' value='" + this.m_quality + "'>";
        html += "<param name='wmode' value='" + this.m_displayMode + "'>";
        html += "<param name='allowfullscreen' value='" + (this.m_allowFullScreen ? "true" : "false") + "'>";
        html += "<param name='allowscriptaccess' value='" + (this.m_allowScriptAccess ? "always" : "never") + "'>";
        html += "<param name='loop' value='" + (this.m_loop ? "true" : "false") + "'>";
        html += "<param name='menu' value='" + (this.m_showMenu ? "true" : "false") + "'>";
        html += "<param name='scale' value='" + this.m_scaleMode + "'>";
        html += "<param name='bgcolor' value='" + this.m_backgroundColor + "'>";
        html += "<param name='flashvars' value='" + this.FlashVarsToString() + "'>";
        
        html += "<embed src='" + this.m_fileName + "'";
        html += " type='application/x-shockwave-flash'";
        html += " pluginspage='http://www.macromedia.com/go/getflashplayer'";
        html += " quality='" + this.m_quality + "'";
        html += " wmode='" + this.m_displayMode + "'";
        html += " allowfullscreen='" + (this.m_allowFullScreen ? "true" : "false") + "'";
        html += " allowscriptaccess='" + (this.m_allowScriptAccess ? "always" : "never") + "'";
        html += " loop='" + (this.m_loop ? "true" : "false") + "'";
        html += " menu='" + (this.m_showMenu ? "true" : "false") + "'";
        html += " scale='" + this.m_scaleMode + "'";
        html += " bgcolor='" + this.m_backgroundColor + "'";
        if (this.m_width > 0) html += " width='" + this.m_width.toString() + "'";
        if (this.m_height > 0) html += " height='" + this.m_height.toString() + "'";        
        html += " flashvars='" + this.FlashVarsToString() + "'"
        html += ">";
        html += "</embed>";
        
        //html += this.m_noPlayerMessage;
        
        html += "</object>";
    
        document.write(html);
    }
    
    /* Zjisti zda dana pridavna promenna jiz existuje. 
       Vraci index na kterem se promenna nachazi, jinak -1. */
    this.ContainsFlashVar = function(name)
    {
        for (var i = 0; i < this.m_flashVars.length; i++)
        {
            if (this.m_flashVars[i][0] == name) return i;
        }
        return -1;
    }
    
    /* Nastaveni hodnoty pridavne promenne. */
    this.SetFlashVar = function(name,value)
    {
        var index = this.ContainsFlashVar(name);
        if (index >= 0)
        {
            this.m_flashVars[index][1] = value;
        }
        else
        {
            var newIndex = this.m_flashVars.length + 1;
            this.m_flashVars[newIndex][0] = name;
            this.m_flashVars[newIndex][1] = value;
        }
    }
    
    /* Ziskani hodnoty pridavne promenne. Pokud promenna neexistuje varci prazdny string. */
    this.GetFlashVar = function(name)
    {
        var index = this.ContainsFlashVar(name);
        if (index >= 0) return this.m_flashVars[index][1];
        else return "";
    }
    
    /* Vytvori retezec s jednotlivymi pridavnymi promennymi, ktery lze pote pouzit
       jako parametr ve Flash playeru. */
    this.FlashVarsToString = function()
    {
        var retString = "";
        for (var i = 0; i < this.m_flashVars.length; i++)
        {
            if (retString != "") retString += "&";
            var name = this.m_flashVars[i][0];
            var value = this.m_flashVars[i][1];
            retString += name + "=" + value;
        }
        return retString;
    }    
    
}