$(document).ready(function() {
    // new patch that will add the wmode parameter to a youtube iframe source url as youtube allows the parameter to be passed through in the URL - phew!
    $("iframe").each(function(a){var b=$(this).attr("src");if(typeof b!=="undefined"){if(b.indexOf("youtu")!==-1){if(b.indexOf("?")!==-1){b=b+"&wmode=opaque"}else{b=b+"?wmode=opaque"}$(this).attr("src",b)}}})
    
    var theObj = $('object');
    if (theObj.length>0) {
       theObj.append('<param name="wmode" value="opaque" />');
       theObj.append('<param name="wmode" value="transparent" />');
    }
    
    /*
    Wrote by jose.nobile@gmail.com
    Free to use for any purpose
    Tested at IE 7, IE 8, FF 3.5.5, Chrome 3, Safari 4, Opera 10
    Tested with Object[classid and codebase] < embed >, object[classid and codebase], embed, object < embed > -> Vimeo/Youtube Videos
    Please, reporte me any error / issue
    */
    function LJQ() {
        var sc=document.createElement('script');
        sc.type='text/javascript';
        sc.src='http://ajax.googleapis.com/ajax/libs/$/1.3.2/$.min.js';
        sc.id = 'script1';
        sc.defer = 'defer';
        document.getElementsByTagName('head')[0].appendChild(sc);
        window.noConflict = true;
        window.fix_wmode2transparent_swf();
    }
    if(typeof ($) == "undefined") {
        if (window.addEventListener) {
            window.addEventListener('load', LJQ, false); 
        } else if (window.attachEvent) { 
            window.attachEvent('onload', LJQ);
        }
    } else { // $ is already included
        window.noConflict = false;
        window.setTimeout('window.fix_wmode2transparent_swf()', 200);
    }
    window.fix_wmode2transparent_swf = function  () {
        if(typeof ($) == "undefined") {
            window.setTimeout('window.fix_wmode2transparent_swf()', 200);
            return;
        }
        if(window.noConflict)$.noConflict();
        // For embed
        $("embed").each(function(i) {
            var elClone = this.cloneNode(true);
            elClone.setAttribute("WMode", "Transparent");
            $(this).before(elClone);
            $(this).remove();
        });	
        // For object and/or embed into objects
        $("object").each(function (i, v) {
            var elEmbed = $(this).children("embed");
            if(typeof (elEmbed.get(0)) != "undefined") {
                if(typeof (elEmbed.get(0).outerHTML) != "undefined") {
                    elEmbed.attr("wmode", "transparent");
                    $(this.outerHTML).insertAfter(this);
                    $(this).remove();
                }
                return true;
            }
            var algo = this.attributes;
            var str_tag = '<OBJECT ';
            for (var i=0; i < algo.length; i++) str_tag += algo[i].name + '="' + algo[i].value + '" ';	
            str_tag += '>';
            var flag = false;
            $(this).children().each(function (elem) {
                if(this.nodeName == "PARAM") {
                    if (this.name == "wmode") {
                            flag=true;
                            str_tag += '<PARAM NAME="' + this.name + '" VALUE="transparent">';		
                    } else {
                        str_tag += '<PARAM NAME="' + this.name + '" VALUE="' + this.value + '">';
                    }
                }
            });
            if(!flag) {
                    str_tag += '<PARAM NAME="wmode" VALUE="transparent">';		
            }
            str_tag += '</OBJECT>';
            $(str_tag).insertAfter(this);
            $(this).remove();	
        });
    }
});
