/**
 *	LittleHelper.js
 */

/* Binds scope */
Function.prototype._bind = function(scope){
	var _this = this;
	return function() {
		return _this.apply(scope, arguments);
	}
};

/* Groups items into chunks */
function eachSlice(number, collection){
	var chunks = [];
	for(var i = 0; i < collection.length; i += number){ chunks.push(collection.slice(i, i + number)); }
	return chunks;
};

/* Creates class */
var Class = (function(){
	function create(){
		var object = (typeof arguments[0] == 'object') ? arguments[0] : {};
		
		function _class(){
			this.initialize.apply(this, arguments);
		}
		
		for(var property in object){
			_class.prototype[property] = object[property];
		}
		
		if(!_class.prototype.initialize){
			_class.prototype.initialize = function(){};
		}
		
		_class.prototype.constructor = _class;
		return _class;
	};
	
	return {
		create: create
	};
})();

/* Creates and evaluates template */
var Template = Class.create({
	string: '',
	
	initialize: function(string){
		this.string = (typeof string != 'undefined') ? string : '';
	},
	
	evaluate: function(object){
		if(this.string.length > 0 && typeof object == 'object'){
			var result = this.string;
			for(var property in object){ result = result.replace(new RegExp('#{' + property + '}', 'g'), object[property]); }
			return result;
		}
	}
});
