/*	
	autor			: this be tofus - maxomedia ag
	module			: mxm, mxm.base
	dependencies	: none
*/

/* ---------------------------------------------------------------------------------------------------- */
/* =mxm */
/* ---------------------------------------------------------------------------------------------------- */

/* constructor */
function mxmjskit() {
	this.name = "mxm js kit";
	this.version = "0.1";
}

/* initialize */
var mxm = new mxmjskit();




/* ---------------------------------------------------------------------------------------------------- */
/* =mxm.base */
/* ---------------------------------------------------------------------------------------------------- */

/* constructor */
function mxmbase() {
	this.w3cdom = (document.createElement && document.getElementsByTagName);
	this.ie52mac = (navigator.userAgent.indexOf('MSIE 5.2') != -1 && navigator.userAgent.indexOf('Mac') != -1);
	this.module = "base";
}

/* initialize */
mxmjskit.prototype.base = new mxmbase();




/* ---------------------------------------------------------------------------------------------------- */
/* =methods */
/* ---------------------------------------------------------------------------------------------------- */


/* -------------------------------------------------- */
/* =callStack */

/* constructor */
function callStack () {
	this.stack =  {};
}

/* add */
callStack.prototype.add = function (key, func) {
	this.stack[key] = func;
}

/* invoke */
callStack.prototype.invoke = function () {
	for (key in this.stack) this.stack[key]();
}




/* =isArrayLike() */
mxmbase.prototype.isArrayLike = function () {
	for (var i = 0; i < arguments.length; i++) {
		var o = arguments[i];
		var typ = typeof(o);
		if (
			(typ != 'object' && !(typ == 'function' && typeof(o.item) == 'function')) ||
			o == null ||
			typeof(o.length) != 'number'
		) {
			return false;
		}
	}
	return true;
}

/* =toArray(obj) */
mxmbase.prototype.toArray = function (obj) {
	if (!obj) return [];
	var results = [];
	if (typeof(obj) == "string") results.push(obj);
	else for (var i = 0; i < obj.length; i++) results.push(obj[i]);
	return results;
}

/* =findIn(a, b) */
mxmbase.prototype.findIn = function (find, In) {
	var a, b;
	(typeof(find) == "string") ? a = find.toLowerCase() : a = find;
	b = mxm.base.toArray(In);
	for (var i = 0; i < b.length; i++) {
		if (typeof(b[i]) == "string") b[i] = b[i].toLowerCase();
		if (a === b[i]) return true;
	}
	return false;
}

/* =toArray(iterable) 
mxmbase.prototype.toArray = function (iterable) {
	if (!iterable) return [];
	var results = [];
	for (var i = 0; i < iterable.length; i++)
		results.push(iterable[i]);
	return results;
}*/




/* ---------------------------------------------------------------------------------------------------- */
/* =functions */
/* ---------------------------------------------------------------------------------------------------- */

/* =bind(obj, arguments) */
Function.prototype.bind = function () {
    var method = this, args = mxm.base.toArray(arguments), object = args.shift();
    return function () {
        return method.apply(object, args);
    }
}


/* =bindEventListener(obj, arguments) */
Function.prototype.bindEventListener = function () {
	var method = this, args = mxm.base.toArray(arguments), object = args[0];
	return function (event) {
		args.splice(0,1,event || window.event);
		return method.apply(object, args);
	}
}