﻿// Declare a namespace.
Type.registerNamespace("MyComponents");

MyComponents.UpdPanel = function() { 
    MyComponents.UpdPanel.initializeBase(this);
    
    this._panels = null;
    this._sounds = null;
}

///Create prototype
MyComponents.UpdPanel.prototype = {

    initialize : function()
    {
        MyComponents.UpdPanel.callBaseMethod(this, 'initialize');
        
        //Sys.Debug.trace("created");
    },
    
    dispose : function()
    {
        MyComponents.UpdPanel.callBaseMethod(this, 'dispose');
    },

    get_Panels : function() {
        return this._panels;
    },

    set_Panels : function(value) {
        if (this._panels !== value) {
            this._panels = value;
            this.raisePropertyChanged('Panels');
        }
    },
    
    get_Sounds : function() {
        return this._sounds;
    },

    set_Sounds : function(value) {
        if (this._sounds !== value) {
            this._sounds = value;
            this.raisePropertyChanged('Sounds');
        }
    },
    
    UpdatePanelsByKeys : function(keys)
    {
        for(j = 0;j < this._panels.length;j++)
        {
            var p = this._panels[j];
            var has_key = false;
            for(i = 0;i < keys.length;i++)
            {
                //Sys.Debug.trace("(j,i):" + j + "," + i);
                var key = keys[i];
                if (p.key == key)
                {
                    has_key = true;
                    if (!p.updated)
                    {
                        p.updated = true;
                        //Sys.Debug.trace("update");
                        UpdatePanel(p.handlerId,p.panelId,"");
                        //if (p.sound)
                        //    soundManager.play(key,p.sound);
                    }
                }
            }
            if (!has_key && p.updated)
            {
                p.updated = false;
                //Sys.Debug.trace("update again");
                UpdatePanel(p.handlerId,p.panelId,"");
            }
        }
        
        for(i = 0;i < this._sounds.length;i++)
        {
            var item = this._sounds[i];
            var idx = Array.indexOf(keys,item.name);
            if (idx >= 0)
            {
                if (!item.played && soundManager && soundManager._didInit)
                {
                    item.played = true;
                    //soundManager.volume = 10;
                    soundManager.play(item.name,{url:item.path,volume:10});
                }    
            }
            else
                item.played = false;
        }
    }
}

MyComponents.UpdPanel.registerClass('MyComponents.UpdPanel', Sys.Component);

if (typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();

