
// Some javascript text animations by Adam Ketterhagen 

$.easing.def = "easeOutCirc";
	
$.fn.textAnimate = function(data){

	if(!data.a) return;
	
	var delay = data.txtDelay ? data.txtDelay : 25;
	var anim  = data.animDelay ? data.animDelay : 400;
	var size = parseInt($(this).css('font-size').replace('px', ''));
	var growPixels = data.growPixels ? data.growPixels : 20;
	var easing = data.easing ? data.easing : $.easing.def;
	var dropHeight = data.dropHeight ? data.dropHeight : 50;
	var repeat = data.repeat ? data.repeat : 1;
	
	var text = $(this).text();
	$(this).css('height', $(this).height()+"px"); 
	$(this).css('width', $(this).width()+"px"); 
	$(this).empty();
	var shortcode = data.a.substring(0, 3);
	
	//$(this).append('<span>'); 
	  
	for(var i=0; i<text.length;++i) $(this).append("<span id = \""+$(this).attr('id')+shortcode+i+"\">"+text.substring(i,i+1)+"</span>");
	  
	//$(this).append('</span>'); 
	  
	for(var j=0;j<repeat;++j)  
	for(var i=0;i<text.length;++i){
	  
	    var $cur = $("#"+$(this).attr('id')+shortcode+i);
		if(!$cur.html()) $cur.html('&nbsp;');
	  
		switch(data.a.toLowerCase()){
		  
			case 'fadeinlefttoright':
			
				$cur.css('opacity', 0);
				$cur.delay(i*delay).animate({opacity: 1}, {easing: easing, duration: anim});
				break;
				 
			case 'shine':
			
				$cur.css('width', $cur.width()+"px"); 
				$cur.delay(i*delay).animate({opacity:0},{easing: easing, duration: anim}).animate({opacity:1},{easing: easing, duration: anim})
				break;
			
			case 'wave':
			
				$cur.css('vertical-align', 'top');
				$cur.delay(i*delay).animate({fontSize: (size+growPixels)+'px'},{easing: easing, duration: anim}).animate({fontSize: (size)+'px'}, {easing: easing, duration: anim});
				break;
				
			case 'strikethrough':
			
				//$cur.delay(100+i*delay).animate({textDecoration: 'line-through'});
				$cur.css('width', $cur.width()+"px"); 
				$cur.delay(i*delay).queue(function(){
					$(this).css('text-decoration', 'line-through');	
					$(this).dequeue();
				});
				break;
				
			case 'drop':
			
				$cur.css('opacity', 0);
				$cur.css('position','relative').css('bottom', dropHeight+'px');
				$cur.delay(delay*i).animate({bottom: 0+'px', opacity: 1},{easing: easing, duration: anim});
				break;
				
			case 'ripple':
			
				var $width = $cur.width();
				$cur.css('overflow','hidden');
				$cur.delay(delay*i).animate({width: ($width*(3/5))+'px', opacity:.5},{easing: easing, duration: anim}).animate( {width: $width+'px' , opacity: 1 }, {easing: easing, duration: anim});
				break;
				
			case 'fall':
				$cur.css('opacity', 0).css('vertical-align', 'top');
				$cur.css('font-size', (size+growPixels)+'px');
				$cur.delay(delay*i).animate( {fontSize: size , opacity: 1 }, {easing: easing, duration: anim});
				break;
		 
			default:
				$(this).show();
		}
	}	
}
	/*
$(document).ready(function(){
	$("#testdiv0").click(function(){$(this).textAnimate(  { txtDelay: 25, animDelay: 600, a: 'fadeInLeftToRight', easing: 'easeOutBack' }    )});
	$("#testdiv1").click(function(){$(this).textAnimate(  { txtDelay: 25, animDelay: 250, a: 'ripple', easing: 'easeInOutBounce'}                )});
	$("#testdiv2").click(function(){$(this).textAnimate(  { txtDelay: 25, animDelay: 400, a: 'strikeThrough'}         )});
	$("#testdiv3").click(function(){$(this).textAnimate(  { txtDelay: 25, animDelay: 250, a: 'shine', easing: 'easeOutBounce' }                )});
	$("#testdiv4").click(function(){$(this).textAnimate(  { txtDelay: 50, animDelay: 400, a: 'wave', growPixels: 50, easing: 'jswing'}                 )});
	$("#testdiv5").click(function(){$(this).textAnimate(  { txtDelay: 50, animDelay: 1500, easing: 'easeOutBounce', a: 'drop', dropHeight: 300 }                 )});
	$("#testdiv6").click(function(){$(this).textAnimate(  { txtDelay: 100, animDelay: 1000, a: 'fall', easing: 'easeOutExpo', growPixels: 500 }                 )});

});
*/


