// Object.extendInto
// Copies the source object into the destination, changing the functions of the source object so that this is passed as the first argument to each function in the source object.   Used to convert prototype's Abtract classes into concrete classes.

/*
Object.extendInto = function(destination, source) {
  for (property in source) {
  	if (typeof source[property] == 'function') {
  		source[property].bindAsExtension(destination);
  	}
  	else {
    	destination[property] = source[property];
    }
  }
  return destination;
}

Function.prototype.bindAsExtension = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat(this, $A(arguments)));
  }
}
*/

/**
 * Overloads a function with new code.  The original function is available in the overload function as the variable SUPER
 * @param func The function to call
 */
 /*
Function.overload(func) {
	var SUPER = this;
	SUPER.apply(func(arguments)
}
*/

Object.applyDefaults = function(obj, defaults) {
	for (var key in defaults) {
		if (obj[key]) { continue; }
		obj[key] = defaults[key];
	}
	return obj;
};

GenericClass = {
    newWithArgs: function(classtype, args) {
        if (args._class == classtype.prototype._class) { return args; }
        return new classtype(args);
    }
};


Number.prototype.currency = function() {
    return '$'+this.toFixed(2);
}


var $val = function(thing) {
    if (typeof thing == 'function') {
        return thing();
    }
    else {
        return thing;
    }
}

