﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("aorta.playmeweb.webcontrols");

aorta.playmeweb.webcontrols.PlayerTemplate2 = function() {
    aorta.playmeweb.webcontrols.PlayerTemplate2.initializeBase(this);

    this._botaoPlayStop = null;
    this._urlImagemPlay = null;
    this._urlImagemStop = null;
    this._botaoAumentarVolume = null;
    this._botaoAbaixarVolume = null;
    this._isPlaying = false;
    this._player = null;

    this._playDelegate = null;
    this._stopDelegate = null;
    this._playStopClickDelegate = null;
    this._volumeUpClickDelegate = null;
    this._volumeDownClickDelegate = null;
}

aorta.playmeweb.webcontrols.PlayerTemplate2.prototype = {
    initialize: function() {
        aorta.playmeweb.webcontrols.PlayerTemplate2.callBaseMethod(this, 'initialize');

        this._playDelegate = Function.createDelegate(this, this._playHandler);
        this._stopDelegate = Function.createDelegate(this, this._stopHandler);
        this._playStopClickDelegate = Function.createDelegate(this, this._playStopClickHandler);
        this._volumeUpClickDelegate = Function.createDelegate(this, this._volumeUpClickHandler);
        this._volumeDownClickDelegate = Function.createDelegate(this, this._volumeDownClickHandler);

        this.get_player().add_play(this._playDelegate);
        this.get_player().add_stop(this._stopDelegate);

        if (this._botaoPlayStop) {
            $addHandler(this._botaoPlayStop, 'click', this._playStopClickDelegate);
            this.setCursor(this._botaoPlayStop, 'pointer');
        }

        if (this._botaoAumentarVolume) {
            $addHandler(this._botaoAumentarVolume, 'click', this._volumeUpClickDelegate);
            this.setCursor(this._botaoAumentarVolume, 'pointer');
        }

        if (this._botaoAbaixarVolume) {
            $addHandler(this._botaoAbaixarVolume, 'click', this._volumeDownClickDelegate);
            this.setCursor(this._botaoAbaixarVolume, 'pointer');
        }
    },

    dispose: function() {
        aorta.playmeweb.webcontrols.PlayerTemplate2.callBaseMethod(this, 'dispose');

        this.get_player().remove_play(this._playDelegate);
        this.get_player().remove_stop(this._stopDelegate);

        if (this._botaoPlayStop)
            $clearHandlers(this._botaoPlayStop);

        if (this._botaoAumentarVolume)
            $clearHandlers(this._botaoAumentarVolume);

        if (this._botaoAbaixarVolume)
            $clearHandlers(this._botaoAbaixarVolume);
    },

    _playHandler: function() {
        this.setCursor(document.body, 'default');
        this._habilitarPlayStop(false);
        this._isPlaying = true;
    },

    _stopHandler: function() {
        this._habilitarPlayStop(true);
        this._isPlaying = false;
    },

    _playStopClickHandler: function() {
        if (this._isPlaying == true) {
            this.get_player().stop();
        } else {
            this.setCursor(document.body, 'wait');
            this.get_player().play();
        }
    },

    _volumeDownClickHandler: function() {
        this.get_player().volumeDown();
    },

    _volumeUpClickHandler: function() {
        this.get_player().volumeUp();
    },

    _habilitarPlayStop: function(play) {
        if (play) {
            if (this.get_urlImagemPlay()) {
                if (this.get_botaoPlayStop()) {
                    this.get_botaoPlayStop().src = this.get_urlImagemPlay();
                }
            }
        } else {
            if (this.get_urlImagemStop()) {
                if (this.get_botaoPlayStop()) {
                    this.get_botaoPlayStop().src = this.get_urlImagemStop();
                }
            }
        }
    },

    setCursor: function(object, value) {
        var e = Function._validateParams(arguments, [{ name: "object", type: Object }, { name: "value", type: String}]);
        if (e) throw e;
        object.style.cursor = value;
    },

    get_botaoPlayStop: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.botaoPlayStop"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._botaoPlayStop;
    },
    set_botaoPlayStop: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._botaoPlayStop = value;
    },

    get_urlImagemPlay: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.urlImagemPlay"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._urlImagemPlay;
    },
    set_urlImagemPlay: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: String}]);
        if (e) throw e;
        this._urlImagemPlay = value;
    },

    get_urlImagemStop: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.urlImagemStop"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._urlImagemStop;
    },
    set_urlImagemStop: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: String}]);
        if (e) throw e;
        this._urlImagemStop = value;
    },

    get_botaoAumentarVolume: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.botaoAumentarVolume"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._botaoAumentarVolume;
    },
    set_botaoAumentarVolume: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._botaoAumentarVolume = value;
    },

    get_botaoAbaixarVolume: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.botaoAbaixarVolume"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._botaoAbaixarVolume;
    },
    set_botaoAbaixarVolume: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._botaoAbaixarVolume = value;
    },

    get_player: function() {
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.PlayerTemplate2.player"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._player;
    },
    set_player: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Sys.Component}]);
        if (e) throw e;
        this._player = value;
    }
}

aorta.playmeweb.webcontrols.PlayerTemplate2.registerClass('aorta.playmeweb.webcontrols.PlayerTemplate2', Sys.Component);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();