/*global jQuery */
/*!
 * FitVids 1.0
 *
 * Copyright 2011, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com
 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/
 *
 * Date: Thu Sept 01 18:00:00 2011 -0500
 */
(function (a) {
    a.fn.fitVids = function (b) {
        var c = {customSelector: null}, d = document.createElement("div"), e = document.getElementsByTagName("base")[0] || document.getElementsByTagName("script")[0];
        return d.className = "fit-vids-style", d.innerHTML = "&shy;<style>               .fluid-width-video-wrapper {                 width: 100%;                                                    padding: 0;                            }                                                                                   .fluid-width-video-wrapper iframe,        .fluid-width-video-wrapper object,        .fluid-width-video-wrapper embed {           position: absolute;                       top: 0;                                   left: 0;                                  width: 100%;                              height: 100%;                          }                                       </style>", e.parentNode.insertBefore(d, e), b && a.extend(c, b), this.each(function () {
            var b = ["iframe[src^='http://player.vimeo.com']", "iframe[src^='http://www.youtube.com']", "iframe[src^='https://www.youtube.com']", "iframe[src^='http://www.kickstarter.com']", "object", "embed"];
            c.customSelector && b.push(c.customSelector);
            var d = a(this).find(b.join(","));
            d.each(function () {
                var b = a(this);
                if (this.tagName.toLowerCase() == "embed" && b.parent("object").length || b.parent(".fluid-width-video-wrapper").length)return;
                var c = this.tagName.toLowerCase() == "object" ? b.attr("height") : b.height(), d = c / b.width();
                if (!b.attr("id")) {
                    var e = "fitvid" + Math.floor(Math.random() * 999999);
                    b.attr("id", e)
                }
                b.wrap('<div class="fluid-width-video-wrapper"></div>').parent(".fluid-width-video-wrapper").css("padding-top", d * 100 + "%"), b.removeAttr("height").removeAttr("width")
            })
        })
    }
})(jQuery)