(function($){ 
     $.fn.extend({  
         airport: function(array) {
			
			var self = $(this);
			var chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','-','.','!','?',' '];
            var word_index = 0;
            var longest = 0;
            var current_word;
            var resolved;
            
			$(this).empty();
			
			for (var i=0; i<array.length; i++)
				if(array[i].length > longest) longest = array[i].length;
            
			for (var j=longest-1; j>=0; j--)
				$(this).prepend("<span class='c" + j + "'></span>");
            
            function search_for_match(characters, character_index, attempt_index) {
                var must_match = current_word.charAt(character_index);
                var check_against = characters[attempt_index];
                var element = self.find('.c' + character_index);
                
                element.html(check_against);
                
                var reached_end = attempt_index + 1  == characters.length;
                var matched = must_match == check_against;
                if (matched) {
                }
                if (matched || reached_end) {
                    resolved++;
                    if (reached_end && ! matched)
                        element.html('');
                    if (resolved == longest)
                        setTimeout(create_word, 7000);
                    return;
                }
                
                setTimeout(function() {
                    search_for_match(characters, character_index, attempt_index + 1);
                }, 30);
            }
            
            function create_word() {
                current_word = array[word_index++ % array.length];
                resolved = 0;
                for (var k=0; k<longest; k++) {
                    (function(k2) {
                        setTimeout(function() {
                            var charcopy = chars.slice().sort(function() {return (Math.round(Math.random())-0.5);});
                            search_for_match(charcopy, k2, 0);
                        }, Math.floor(Math.random()*2000));
                    })(k);
                }
            }
            
            create_word();
        } 
    }); 
})(jQuery);
