;(function($) {
	// private variables
	var oSettings = {};
	//
	// default settings
	$.scramble = {
		 id: "Scramble"
		,version: "1.0.0"
		,defaults: {
			 debug:		true
			,chars:		["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," "," "," "]//,"1","2","3","4","5","6","7","8","9","0","!","@","#","$","%","^","&","*","(",")","{","}","<",">","/","?"]
			,text:		"Text scramble"
			,speed:		20
		}
		// public functions
		,foo: function(bar) {
		}
	};
	// init
	$(function() {
	});

	// call
	$.fn.extend({
		scramble: function(_text,_settings) {
			oSettings = $.extend({}, $.scramble.defaults, _settings);
			//
			var iLen = String(_text).length;
			this.each(function(i,el) {
				revealText($(this),_text,iLen,iLen);
			});
			return this;
		}
	});

	function randText(len) {
		var sRtr = "";
		while (len>=0) {
			sRtr += oSettings.chars[Math.floor(Math.random()*oSettings.chars.length)];
			len--;
		}
		return sRtr;
	}
	function revealText(mDo,sText,iCnt,iLen) {
		if (iCnt>0) {
			mDo.html( str_repeat("&nbsp;",iCnt) + randText(iCnt) + sText.substr(iLen-(iLen-iCnt),iLen-iCnt) );
			mDo.animate({"foo":1},{"duration":oSettings.speed,"complete":function(){revealText(mDo,sText,iCnt,iLen)}});
		} else {
			mDo.text(sText);
		}
		iCnt--;
	}
	function str_repeat(input,multiplier) {
		return new Array(multiplier+1).join(input); 
	}

	// trace
	function trace(o,v) {
		if (window.console&&window.console.log) {//(v||oSettings.debug)&&
			if (typeof(o)=="string")	window.console.log(o);
			else						for (var prop in o) window.console.log(prop+":\t"+String(o[prop]).split("\n")[0]);
		}
	}
})(jQuery);
