(function(){ 
    var w = typeof unsafeWindow != "undefined" ? unsafeWindow : window;
    if (w.swfArgs) {
        var playerDiv2 = document.getElementById("watch-player-div");
        playerDiv2.innerHTML = '<embed type="video/mp4" autoplay="false" src="http://www.youtube.com/get_video?video_id=' + w.swfArgs.video_id + '&amp;t=' + w.swfArgs.t + '&amp;fmt=18" width="640" height="388"></embed>' ;
        return;
    }
    
    var nodes = document.getElementsByTagName('embed');
    for (var index = 0; index < nodes.length; index++) {
        var src = nodes[index].src;
        if (!/http:\/\/(\w+\.)?youtube.com/.test(src)) continue;

        var videoId = src.match(/v[=\/](\w+)/);
        if (!videoId) continue;

        for (var node = nodes[index].parentNode; node && !/object/i.test(node.nodeName); node = node.parentNode);
        if (!node) continue;
        
        var name = 'c' + Math.random().toString().substring(2);
        w[name] = function(node){ return function(data){
            if (data.error) return;
            node.parentNode.innerHTML = "<embed autoplay='false' type='video/mp4' src='" + data.url + "&amp;fmt=18' width='" + node.width + "' height='" + node.height + "'></embed>";
        }}(node);
        
        script = document.createElement('script');
        script.src = 'http://youtube-parser.appspot.com/?id=' + encodeURIComponent(videoId[1]) + '&callback=' + name;
        document.body.appendChild(script);
    }
})();
