/**
* Typewriter JQuery effect
* written by James Florentino
* www.jamesflorentino.com
* -----
* errr... this plugin is still experimental. I have yet to make it bug free.
* */

(function( $ ){
	$.fn.typewriter = function(__text, __interval, __callback){
		var i = 0;
		var txtobj		= this;

		txtobj.text('');
		type();

		function type() {
			txtobj.text(__text.substr(0,i));
			if(txtobj.text().length < __text.length){
				i++;
				setTimeout(type, __interval);
			}else{
				if(__callback){
					__callback();
				}
			}
		}
	};
	$.fn.scrambler = function(__text, __interval, __callback){
		var i = 0;
		var txtobj		= this;

		txtobj.text('');
		type();

		function type() {
			var scrambled	= "";
			while(scrambled.length < __text.length - i){
				scrambled += __text.substr(Math.random() * __text.length, 1);
			}
			txtobj.text(__text.substr(0,i) + scrambled);
			if(i < __text.length){
				i++;
				setTimeout(type, __interval);
			}else{
				if(__callback){
					__callback();
				}
			}
		}
	};
})( jQuery );
