/**
* This is the the main class used to register global events like window load
*
*/

/**
* Set class's default constructor
*/
KMain.prototype.constructor = KMain;

/**
* Main constructor
*/
function KMain()
{
    this.init();
}

/**
* Separated constructing function
*/
KMain.prototype.init = function()
{ 
    this.eWindowLoad = new Array(0);    
}

/**
* Adds event listener for a specific event type
*
* @param string eventType type of the event: e.g. "windowload"
* @param int met pointer to a method or function. This function is called when events occurs
* @param int obj pointer to an object that owns the method. null if met is a function
*/
KMain.prototype.addEventListener = function(eventType, met, obj)
{    
    if (met)
    {
        switch (eventType)
        {
            case "windowload":
                this.eWindowLoad[this.eWindowLoad.length] =new Array(obj, met);
                break;
            default:
                alert("Unknown event type: " . eventType);
                break;
                    
        }    
    }
}

/**
* This method is called when a window load event occurs and needs to be forwarded.
*/
KMain.prototype.notifyWindowLoad = function()
{    
    for (var i = 0; i < this.eWindowLoad.length; i++)
    {
        var obj = this.eWindowLoad[i][0];
        var met = this.eWindowLoad[i][1];
        
        if (null == obj)
        {
            met();
        }
        else
        {
            obj.met();    
        }
    }
}

/**
* This is the hander of the window.onload event
*/
function KMainWindowLoad()
{    
    kmain.notifyWindowLoad();
}

/**
*------------------------------------------------------------------------------
* Some code that is executed imediattely
*
* Creates a global kmain object and links it to window.onload;
*/
var kmain = new KMain();
window.onload = KMainWindowLoad;