if(typeof(initModuleComboVideo) == 'undefined')
{

    var initModuleComboVideo = function($module, xmlFiles, opts){
    
        opts = opts || {};
        xmlFiles = xmlFiles || [];
        var debug = function(msg){
            if(!opts.debug) return;
            if(!$.browser.mozilla || !$.browser.safari) return alert(msg);
            try {
                console.log(msg);
            } catch(e) {
                alert(msg);
            }
        };
       
        return $module.each(function(){
            var lastXmlIdx = 0;
            
            // loop the tabs
            $module.find('.moduleNav > li').each(function(){
            
                // index of the video tab
                var idx = $(this).prevAll('li').length;
                
                // assign the click handler
                $(this).find('a').click(function(){
                    try {
                        if(opts.googleID){
                            gaTrack(opts.googleID, "startVideo_" + idx);
                        }
                    } catch(e){
                    }
                    lastXmlIdx = idx;
                    // the swf 
                    if(!xmlFiles[idx]){
                        debug('no xml file defined in xmlFiles[' + idx + ']');
                        return false;
                    }
                    var $swf = $module.find('object')[0];
                    if(!$swf){
                        debug('no videoplayer object found within module');
                        return false;
                    }
                    $($swf).show();
                    try {
                        debug('calling $swf.stopVideoHandler()'); 
                        $swf.stopVideoHandler();
                    } catch(e) {
                        debug(e.message);
                    }
                    try {
                        debug('calling $swf.newContentAutoPlayHandler(' + xmlFiles[idx] + ')'); 
                        $swf.newContentAutoPlayHandler(xmlFiles[idx]);
                    } catch(e) {
                        debug(e.message);
                    }
                    $(this).closest('li').addClass('selected').siblings('li').removeClass('selected');
                    return false;
                });
                
                // preload the video for the first or selected video
                if( (idx == 0 && $(this).siblings('.selected').length < 1) || $(this).hasClass('selected') ){
                    lastXmlIdx = idx;
                    var doIt = function(){
                        var $swf = $module.find('object')[0];
                        if(!$swf) { 
                            debug('delaying doIt 1000ms');
                            return setTimeout(doIt, 1000);
                        }
                        setTimeout(function(){
                            var $swf = $module.find('object')[0];
                            try {
                                $swf.newContentHandler(xmlFiles[lastXmlIdx]);
                                debug('called newContentHandler(' + xmlFiles[lastXmlIdx] + ')');
                            } catch(e) {
                                setTimeout(doIt, 1000);
                            }
                        }, 1000);
                    };
                    doIt();
                    $(this).closest('ul.carousel').bind('carouselHidden', function(){
                        try {
                            $module.find('object')[0].stopVideoHandler();
                        } catch(e) {
                            debug(e.message);
                        }
                    });
                    if($.browser.mozilla){
                        $(this).closest('ul.carousel').bind('carouselVisible', doIt);
                    }
                }
            });
        });
    };
    
} // end module