/*!
 * Text Animation v1.0.0
 * http://addictionworldwide.com
 *
 * Copyright (c) 2011 Addiction Innovation
 *
 * licensed under the MIT licenses.
 * Date: 09/06/2011
 */
 (function($) {
	 $.fn.animateWords = function() {
		 var startingText=this.text();
		 var secondText=$(this).attr('data-field');
		 var el=$(this);
		 this.lettering();
		 var textLength=this.children().length;
		 this.children().each(function (){
			 $(this).hide();
		 });
//		 animationToggle("lr",startingText,secondText,this);
		 var way="lr";
		 animationToggle(way,startingText,secondText,el);
		 
	 };
 })(jQuery);
 
 function animationToggle(way,displayText,nextText,el) {
	 	setTimeout(function() {
			 if(way=="lr") {
				$(el).empty();
				$(el).text(displayText);
				$(el).lettering();
				$(el).children().each(function() {
					$(this).hide();
				});
				var progress=1;
				var timer=setInterval(function() {
					//$('.char'+progress).css('font-size','36px');
					$('.char'+progress).css('font-family','Helvetica,Arial, sans-serif');
			 		$('.char'+progress).fadeIn(300);
			 		if(progress==$(el).children().length) {
				 		clearInterval(timer);
			 		} else {
				 		progress++;
			 		}
				},10);
				 way="rl";
				 animationToggle(way,nextText,displayText,el);
			 } else {
				//$(el).fadeOut();
				$(el).empty();
				$(el).text(displayText);
				$(el).lettering();
				$(el).children().each(function() {
					$(this).hide();
				});
				$(el).show();
				var progress=1;
				var timer=setInterval(function() {
					//$('.char'+progress).css('font-size','36px');
			 		$('.char'+progress).fadeIn(300);
			 		if(progress==$(el).children().length) {
				 		clearInterval(timer);
			 		} else {
				 		progress++;
			 		}
				},10);
				 way="lr";
				 animationToggle(way,nextText,displayText,el);
			 }
			 
		 },4000);
 }

