// flash callbacks
// *******************************************************************
function audio_status(status) 
{
    switch (status) {
        case 'stop':
            App.Player.stopAudio();
            break;
            
        case 'error':
            break;
    }
}

App.Player = 
{
    currentPlayButton: null,
    playerId: 'flash_player_',
        
    init: function ()
    {
        if (App.isIE) {
            $('object').each(function () {
                this.outerHTML = this.outerHTML;
            });
        }
        
        this.initPlayButtons();
    },

    initPlayButtons: function () 
    {
        $('a:[class*="play-btn"]').each(function () {
            $(this).click(function () {
                if (App.Player.currentPlayButton == this) {
                    // only stop
                    App.Player.stopAudio();
                } else {
                    // stop previuos sound and play the new one
                    App.Player.stopAudio();
                    App.Player.currentPlayButton = this;
                    App.Player.playAudio();
                }
                
                return false;
            });
        });
    },
    
    setFlashVar: function (varName, varValue)
    {
        if (App.isIE) {
            $('#' + this.playerId + 'ie').get(0).SetVariable(varName, varValue);
        } else {
            $('#' + this.playerId + 'moz').get(0).SetVariable(varName, varValue);
        }
    },
    
    playAudio: function ()
    {
        if (this.currentPlayButton != null) {
            $(this.currentPlayButton).addClass('on');
            this.setFlashVar('file', $(this.currentPlayButton).attr('sound'));
        }
    },
    
    stopAudio: function ()
    {
        if (this.currentPlayButton != null) {
            this.setFlashVar('file', '');
            $(this.currentPlayButton).removeClass('on');
            this.currentPlayButton = null;
        }
    }
};

