(function($) {
    $.extend($.fn, {
        youtube: function(options) {
            $('a[href*=youtube.com/watch?v=]').each(function() {
            	$(this).hide();
            	// build player
                var href = 'http://www.youtube.com/v/' + this.href.match(/[a-zA-Z0-9-_]+$/) + '&rel;=1'
                var wrapper = $('<div class="youtube-container" style="display:none;"><div style="display:none;"></div></div>');
                var player = $('div:first', wrapper);
                player.flash({src: href, width: 425, height: 344}, {wmode: 'window'});
                $(this).after(wrapper);
                wrapper.queue(function(){
                    $(this).css('height', 40);
                    $(this).dequeue();
                    $(this).slideDown();
                    $(this).dequeue();
                });
                setTimeout(function(){
                    wrapper.queue(function(){
                        $(this).find('span').hide().end();
                        $(this).dequeue();
                        $(this).animate({height: 385});
                        $(this).dequeue();
                    });
                    setTimeout(function(){
                        player.show();    
                    }, 500);
                }, 500);
                return false;
            	
            });
        }
    });
    
})(jQuery);
