var Steed = {
	
	currentQuote: 0,
	quoteTpl: null,	
	manDown: false,
	
	preloadQuotes: function(){
		for(var i=0,q; q = this.Quotes[i]; ++i){
			var img = new Image();
			img.src = q.img;
			var quot = new Image();
			quot.src = q.quote;
		}
	},
	
	initQuotes: function(){
		
		var $quotes = $('#testimony');
		this.Quotes = $quotes.attr('data-testimonies')? $.parseJSON($quotes.attr('data-testimonies')) : null;
		
		if( Steed.Quotes ){		
			
			
			this.preloadQuotes();			
			
			$quotes.click( function(){ 			
				
				if( !Steed.manDown ){
					
					Steed.manDown = true;
					
					Steed.currentQuote++;
					var q = Steed.Quotes[ Steed.currentQuote % Steed.Quotes.length ];
					
					//create the markup
					if( !Steed.quoteTpl ){
						Steed.quoteTpl = $quotes.find('.person').clone().addClass('new');
					}
					var $q = Steed.quoteTpl.clone();
					$q.find('img.quote').attr('src', q.quote ).attr('title', q.person + "'s witty remark");
					$q.find('>img').attr('src', q.img ).attr('title', q.person );
					
					//toggle the drop animation
					$quotes.addClass('drop');
					
					setTimeout(
							function(){
								//inject the markup
								$quotes.find('.person:not(.new)').remove();
								$quotes.append( $q );
								
								setTimeout(
									function(){
										$q.removeClass('new');
										$quotes.removeClass('drop');
										Steed.manDown = false;
									},
									500
								);
	
							},
							600					
					);
				}
					
			});
		}
	},
	
	init: function(){
		this.initQuotes();
	}
}

Steed.init();
