/**
TypeIt 1.0
@requires jQuery v1.3 or 1.4
by Oriol Tendero - oriol@tendero.cat
January 2011

You should include in ur CSS:

	.typeit{
		display:none;
	}


Use -- 	Encapsulate the HTML or text that u wanna typeFX by the span classed element
		Attribute "rel" indicates the waitin' time in miliseconds between type letter by letter [Optional
	
	Example: <span class="typeit" rel="50">Texto or HTML to type</span>
	

You can use directly the function _typeText(), "obj" has to be a jQuery object, for example $('.title')
or set to true variable "typeit_autoload"

	Example: _typeText($('.title'),"Hello world!");
	
*/
$.typeit_autoload = false;
$.typeit_timeout_default = 20;


$(document).ready(function(){ if($.typeit_autoload){ _typeit(typeit_timeout); } });
function _typeit(t,j){
	$.typeit_timeout = t;
	$.typeit_chars = j;
	$('.typeit').each(function(){
		if($(this).attr("rel") != "" && $(this).attr("rel") != null){
			$.typeit_timeout = parseInt($(this).attr("rel"));
		}
		var text = $(this).html();
		$(this).html("");
		$(this).css("display","inline");
		text = text.replace(/</gi,"%3C");
		text = text.replace(/>/gi,"%3E");
		_typeText($(this),text,$.typeit_timeout,$.typeit_chars);
	});
}
function _typeText(obj,str,time_out,j,i,htmlentitie){
	if(time_out==null){ time_out=$.typeit_timeout_default; }
	if(i==null){ i=0; }
	if(j==null){ j=2; }
	if(htmlentitie==null){ htmlentitie = ""; }
	
	var c = "";
	for(var k=0;k<j;k++){
		c = c+""+str.charAt(i++);
	}
	
	if(str.charAt(i) == null || str.charAt(i) == ''){ //END
		obj.html(unescape(obj.html()+c));
		return false;
	}
	
	//Preload some tags
	var actC = obj.html();
	if(actC!=null){
		actC = actC.replace("%3Cbr/%3E","<br/>");
		actC = actC.replace("%3Cbr%3E","<br/>");
		actC = actC.replace("%20"," ");
		
	}
	obj.html(actC+""+c);
	setTimeout(function(){ _typeText(obj,str,time_out,j,i); }, time_out);
}
