﻿var Class =
{
	create: function(is)
	{
	  return function()
		{
			try
			{
				if (is)
					this.initialize.apply(this, arguments);
			}
			catch(e)
			{
				alert(e.message);
			}
		}
  }
};

function extendEx(target, source) 
{
	if (typeof(target) == "function")
	{
		for(property in source) 
			target.prototype[property] = source[property];
	}
	else
	{
		for(property in source) 
			if (target)
				target[property] = source[property];
	}
	
	return target;
};

function IsObject(a) {return (a && typeof a == "object") || IsFunction(a);};
function IsArray(a) {return IsObject(a) && a.constructor == Array;};
function IsBoolean(a) {return typeof a == "boolean";};
function IsFunction(a) {return typeof a == "function";};
function IsNull(a) {return typeof a == "object" && !a;};
function IsNumber(a) {return typeof a == "number" && isFinite(a);};
function IsString(a) {return typeof a == "string";};
function IsDate(a) {try{return IsObject(a) && !!a.getYear();}catch(e){return false;}};
function IsUndefined(a) {return typeof a == "undefined";};

Array.from = function(iterable) 
{
	if (!iterable) 
		return [];
	
	if (!iterable.length) 
		return [];
	else 
	{
	    var results = [];
		
		for (var i = 0; i < iterable.length; i++)
	        results.push(iterable[i]);
		
		return results;
	}
};

Function.prototype.inherit = function(source)
{
	var p = this.prototype = new source;
	p.constructor = this;
	return this;
};

Function.prototype.getPrototypes = function()
{
	var names = new Array();
    
  for (var i = 0; i < arguments.length; i++) 
  {
    var name = arguments[i];
      
    if (IsString(name)) 
        names.push(name);
		
		if (IsArray(name))
		{
			names = names.copy(name);
		}
  }
	
	var result = {};
	var source = this.prototype;
	
	for(var i = 0; i < names.length; i++) 
		result[names[i]] = source[names[i]];
	
	return result;
};

Function.prototype.bind = function() 
{
  var __method = this, args = Array.from(arguments), object = args.shift();
    
  return function() 
	{
    return __method.apply(object, arguments);
  }
};

Function.prototype.bindEx = function(object)
{
	var __method = this;
	
	return function()
	{
		return __method.apply(object, arguments);
	}
};

Function.prototype.bindAsEventListener = function(object) 
{
  var _method = this;
	var arg = Array.prototype.slice.call(arguments, 1);
  
  return function(event) 
	{
    return _method.call(object, event || window.event);
  }
};


