var Fonte = {

    /**
     * Guarda o tamanho original da fonte para ser restaurada quando solicitado.
     */
    _original : null,
    
    _atual : null,
    
    _lastErro : null,

    restaurar : function() {
        return this._set();
    
    },
    
    diminuir : function() {
        return this._set(-0.1);
    },
    
    aumentar : function() {
        return this._set(+0.1);    
    },
    
    /**
     * Altera o tamanho da fonte do documento de acordo com o parâmetro informado.
     *
     * Para restaurar o valor original, não passar parâmetro.
     *     
     * @private
     */     
    _set : function(diferenca) {
    
        try {
        
            // Guardando o valor original na primeira chamada
            if (this._original == null) {                
                this._original = Style.getOriginalStyle(0, "body", "fontSize");
                this._atual    = this._original;
            }
        
            // Restaurando o valor original
            if (!diferenca) {
            
                if (this._original != null) {
                    this._atual = this._original;
                    document.body.style.fontSize = this._original;                    
                    return true;
                }
                else {
                    //todo
                    alert("todo - !diferenca, _original == null");
                    return false;
                }
            }
            
            var atual     = parseFloat(this._atual);
            var novoValor = atual + diferenca + "em";
            
            this._atual = novoValor;
            document.body.style.fontSize = novoValor;
            return true;
        
        }
        catch (e) {
            _lastErro = e;
            return false;
        }
    
    },
    
    getLastError : function() {
        return _lastErro;
    }

};


/**
 *
 */
var MP3Player = {

    _idPrefix : "",
    
    _idSufixObject : "-object",
    
    _idSufixEmbed : "-embed",
    
    _players : [],
    
    add : function(id) {
        this._players[this._players.length] = id;
    },
    
    pauseAll : function() {
        var i;
        var obj1, obj2;
        var id;
        
        for (i = 0; i < this._players.length; i++) {
            id = this._players[i];
            
            obj1 = document.getElementById(id + this._idSufixObject);
            obj2 = document.getElementById(id + this._idSufixEmbed);
            
            if (obj1 && obj1.dewpause) {
                obj1.dewpause();
            }
            
            if (obj2 && obj2.dewpause) {
                obj2.dewpause();
            }
        }
        
    }

};

/**
 * Callback pro ActionScript
 */
function player_mp3_pauseAll() {
    
    // Pausando ou parando a radio
        // Controlando interface nova do WMP, disponivel no IE e Chrome
        try {
            var radioplayer = document.getElementById("radioplayer_object");    
            if (radioplayer) {
                if (radioplayer.playState == 3) {
                    radioplayer.controls.pause();                
                }
                else {
                    radioplayer.controls.stop();
                }
            }
        }
        catch (e) {}
    
        // Interface pra firefox e safari
        try {
            radioplayer = document.getElementById("radioplayer_embed");    
            if (radioplayer) {
                radioplayer.autostart = "0";
                radioplayer.src = radioplayer.src;
            }
        }
        catch (e) {}
    
    
    MP3Player.pauseAll();
    
}


/**
 *
 */
var Style = {

    /**
     *
     */
    getCurrentStyle : function (oElm, strCssRule) {

        var strValue = "";
        
        if (document.defaultView && document.defaultView.getComputedStyle) {
            strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
        }
        else if (oElm.currentStyle){
            strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
                return p1.toUpperCase();
            });
            strValue = oElm.currentStyle[strCssRule];
        }
        return strValue;

    }, 

    /**
     *
     */
    getOriginalStyle : function (styleSheetIndex, rule, property) {

        var sheet = document.styleSheets[styleSheetIndex];
        var rules = sheet.cssRules ? sheet.cssRules: sheet.rules;
        var i;
        var targetRule;
            
        // Localiza a rule desejada
        for (i = 0; i < rules.length; i++) {
            if (rules[i].selectorText.toLowerCase() == rule) {
                targetRule = rules[i];
                break;
            }
        }
        
        // Se nao achar a rule desejada
        if (i == rules.length) {
            return null;
        }
        
        return targetRule.style[property];    

    }

};