/*
Copyright (c) willFarrell 2011
*/
// Start at the end of teh alphabet and work back to prevent unexpected var conflicts
var 
		ls = localStorage, //localstorage short name			[localstorage.js]
		online, //online status			[localstorage.js]
	
		s, //search_all			[search.js]
		t, //search_time		[search.js]
		u, //user_ID				[search.js]
		//v, // not assigned yet []
		x = [], // xmlreqs	[ajax.js]
		y, //search_type		[search.js]
		z = 1000; // z-index of popups 		[design.js]


/*
Browser Fixes
ES5 Functions
*/
/*
// String.trim
if(typeof String.prototype.trim !== 'function') {
	String.prototype.trim = function () {
		return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
	};
}

// String.supplant - find and repalce {name} from {name: "value", ....
if(typeof String.prototype.supplant !== 'function') {
	String.prototype.supplant = function (o) {
		return this.replace(/{([^{}]*)}/g, 
			function (a, b) {
				var r = o[b];
				return typeof r === 'string' ? r : a;
			});
	};
}

// Array.isArray
if(typeof Array.isArray !== 'function') {
	Array.isArray = function (value) {
		return Array.prototype.toString.apply(value) === 'object Array]';
	};
}

//Object.later

if(typeof Object.prototype.later !== 'function') {
	Object.prototype.later = function (msec, method) {
		var that = this,
				args = Array.prototype.slice.apply(arguments, [2]);
		if (typeof method === 'string') {
			method = that[method];
		}
		setTimeout(function () {
			method.apply(that, args);
		}, msec);
		return that; // Cascade
	};
}


//Ex.  inc = curry(function add(a,b) { return a + b; }, 1); alert(inc(6)); // 7

if(typeof curry !== 'function') {
	curry = function (func) {
		var args = arguments.slice(1);
		return function () {
			return func.apply(null, args.concat(arguments.slice()));
		};
	};
}

// make_promise
if(typeof make_promise !== 'function') {
	function make_promise () {
		var status = 'unresolved',
				outcome,
				waiting = [],
				dreading = [];
		function vouch(deed, func) {
			switch (status) {
				case 'unresolved':
					(deed === 'fulfilled' ? waiting : dreading).push(func);
					break;
				case deed:
					func(outcome);
					break;
			}
		}
		function resolve(deed, value) {
			if (status !== 'unresolved') {
				throw new Error('The promise has already been resolved: ' + status);
			}
			status = dead;
			outcome = value;
			(deed === 'fulfilled' ? waiting : dreading).forEach(function (func) {
				try {
					func(outcome);
				} catch (ignore) {}
			});
			waiting = null;
			dreading = null;
		}
		return {
			when: function (func) {
				vouch('fulfilled', func);
			},
			fail: function (func) {
				vouch('smashed', func);
			},
			fulfill: function (value) {
				resolve('fulfilled', value);
			},
			smash: function (value) {
				resolve('smashed', string);
			},
			status: function () {
				return status;
			}
		};
	}
}

// memoizer
//Ex.
//var factorial = memoizer([1,1], function (recur, n) { return n* recur(n-1); });
//var fibonacci = memoizer([0,1], function (recur, n) { return recur(n-1) + recur(n - 2); });

if(typeof memoizer !== 'function') {
	function memoizer(memo, formula) {
		var recur = function (n) {
			var result = memo[n];
			if (typeof result !== 'number') {
				result = formula(recur, n);
				memo[n] = result;
			}
			return result;
		};
		return recur;
	};
}
*/
