/**************************************************\
*                SYNTACTIC SUGAR                   *
* Author: Andrew Green                             *
* Modified: 03/02/2009                             *
* Description:                                     *
*  Here are some things to make Javascript sweeter *
*                                                  *
*  Syntactic sugar is a term coined by             *
*  Peter J. Landin for additions to the syntax of a*
*  computer language that do not affect its        *
*  functionality but make it "sweeter" for humans  *
*  to use.                                         *
\**************************************************/

/****************************\
* jslint verified 03/02/2009 *
* http://www.jslint.com/     *
\****************************/
Date.prototype.getElapsed = function(date) {
	return Math.abs((date || new Date()).getTime()-this.getTime());
};

Function.prototype.scope = function(myScope){//handy for callback functions
	var method = this;//create private var of method
	return function() {
		return method.apply(myScope, arguments);//on function call apply scope
	};
};



var baseClass=function(classObject){//Used to get PHP style class
		var classConstructor=classObject.constructor ? classObject.constructor : function(){};
		var copyTo=function(_to,_from){
			for(var key in _from){
				_to[key]=_from[key];
			}
		};
		copyTo(classConstructor.prototype, classObject);
		classConstructor.extend=function(classObject){//we use extend as extends is reserved word
				var parentClass= this;
				
				
				var classConstructor=classObject.constructor ? classObject.constructor : function(){parentClass.apply(this, arguments);};//call the parent classes constructorvar 
				classConstructor.superclass=parentClass.prototype;
				copyTo(classConstructor.prototype, parentClass.prototype);//copy parent prototype over new class
				classConstructor.parent=parentClass.prototype;//set link to parent class
				
				copyTo(classConstructor.prototype, classObject);//write new functions and overight any parent functions
				classConstructor.extend = this.extend;
				
				return classConstructor;
			};
		return classConstructor;
	};
	
