(function() {
    function initVideoJS() {
        var videos = document.getElementsByTagName('video'),
            time = new Date().getTime();
        
        for (var i = 0; i < videos.length; i++) {
            var video = videos[i];
            
            if (!video.getAttribute('initialized')) {
                var videoChildren = video.childNodes;
                
                for (var j = 0; j < videoChildren.length; j++) {
                    var videoChild = videoChildren[j];
                    
                    if (videoChild.nodeType == 1) {
                        var tagName = videoChild.tagName.toLowerCase();
                        
                        if (tagName == 'link' || tagName == 'source') {
                            var id = 'videoJS' + time + i,
                                src = videoChild.getAttribute('src'),
                                type = videoChild.getAttribute('type');
                            
                            video.setAttribute('id', id);
                            video.setAttribute('initialized', true);
                            video.innerHTML = '<source src="' + src + '" type="' + type + '" />\
                            <object id="flash_fallback" class="vjs-flash-fallback" width="' + video.getAttribute('width') + '" height="' + video.getAttribute('height') + '" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">\
                                <param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />\
                                <param name="allowfullscreen" value="true" />\
                                <param name="flashvars" value=\'config={"playlist":[{"url": "' + src + '","autoPlay":false,"autoBuffering":true}]}\' />\
                            </object>';
                            
                            VideoJS.setup(id, {});
                            
                            break;
                        }
                    }
                }
            }
        }
    }
    
    if (window.addEventListener) {
      window.addEventListener('load', initVideoJS, false);
    } else if (window.attachEvent) {
      window.attachEvent('onload', initVideoJS);
    }
})();
