﻿// youtube-wmode.js
// Sets the wmode to transparent for YouTube embeds

(function($) {

    var plugin = Echo.createPlugin({
	    "name": "YouTubeWmode",
	    "applications": ["Stream"],
	    "init": function(plugin, application) {
		    plugin.extendRenderer("Item", "body", plugin.renderers.body, "YouTubeWmode");
	    }
    });

    plugin.renderers = {};

    plugin.renderers.body = function(element, dom) {
        this.parentRenderer("body", arguments);
        element.find('iframe').each(function() {
            var $this = $(this);
            var match;
            if (match = /^http:\/\/(?:www\.)?youtube.com\/embed\/\w+\/?$/.exec($this.attr('src'))) {
                $this.attr('src', match + "?wmode=transparent");
            }
        });
    }

})(jQuery);
