* added textSelection plugin from usability
[lhc/web/wiklou.git] / js2 / mwEmbed / mv_embed.js
index f0b83c6..7fc146d 100644 (file)
  * (in cases where media will be hosted in a different place than the embedding page)
  *
  */
-// Fix multiple instances of mv_embed (i.e. include twice from two different servers)
-var MV_DO_INIT=true;
-if( MV_EMBED_VERSION ){
-       MV_DO_INIT=false;
+
+/**
+ * AutoLoader paths 
+ * @path The path to the file (or set of files) with ending slash
+ * @gClasses The set of classes
+ *             if it's an array, $j.className becomes jquery.className.js
+ *             if it's an associative object then key => value pairs are used
+ */
+if( typeof mvAutoLoadClasses == 'undefined' )
+       mvAutoLoadClasses = {};
+
+// The script that loads the class set
+function lcPaths( classSet ){
+       for( var i in classSet ) {
+               mvAutoLoadClasses[i] = classSet[i];
+       }
+}
+
+function mvGetClassPath(k){
+       if( mvAutoLoadClasses[k] ) {
+               //js_log('got class path:' + k +  ' : '+ mvClassPaths[k]);
+               return mvAutoLoadClasses[k];
+       } else {
+               js_log('Error:: Could not find path for requested class ' + k );
+               return false;
+       }
+}
+if( typeof mvCssPaths == 'undefined' )
+       mvCssPaths = {};
+
+function lcCssPath( cssSet ) {
+       for( var i in cssSet ) {
+               mvCssPaths[i] = mv_embed_path + cssSet[i];
+       }
 }
-// Used to grab fresh copies of scripts.
-var MV_EMBED_VERSION = '1.0r20';
 
 /*
- * Configuration variables should be set by extending mwConfigOptions
- * here is the default config:
+ * --  Load Class Paths --
+ *
+ * MUST BE VALID JSON (NOT JS)
+ * This is used by the script loader to auto-load classes (so we only define
+ * this once for PHP & JavaScript)
+ *
+ * Right now the PHP AutoLoader only reads this mv_embed.js file.
+ * In the future we could have multiple lcPath calls that PHP reads
+ * (if our autoloading class list becomes too long) 
+ * or 
+ * we could support direct file requests to the script loader instead 
+ * of shared class names read from a central location.
  */
-var mwDefaultConfig = {
-       'skin_name': 'mvpcf',
-       'jui_skin': 'redmond',
-       'video_size':'400x300'
-}
+lcPaths({
+       "mv_embed"                      : "mv_embed.js",
+       "window.jQuery"         : "jquery/jquery-1.3.2.js",
+       "$j.fn.pngFix"          : "jquery/plugins/jquery.pngFix.js",
+       "$j.fn.autocomplete": "jquery/plugins/jquery.autocomplete.js",
+       "$j.fn.hoverIntent"     : "jquery/plugins/jquery.hoverIntent.js",
+       "$j.fn.datePicker"      : "jquery/plugins/jquery.datePicker.js",
+       "$j.ui"                         : "jquery/jquery.ui/ui/ui.core.js",
+       "$j.fn.ColorPicker"     : "libClipEdit/colorpicker/js/colorpicker.js",
+       "$j.Jcrop"                      : "libClipEdit/Jcrop/js/jquery.Jcrop.js",
+       "$j.fn.simpleUploadForm" : "libAddMedia/simpleUploadForm.js",
+       
+       "$mw.proxy"             : "libMwApi/mw.proxy.js",
+       
+       "$mw.testLang"  :  "tests/testLang.js",
+       
+       "ctrlBuilder"   : "skins/ctrlBuilder.js",
+       "kskinConfig"   : "skins/kskin/kskin.js",
+       "mvpcfConfig"   : "skins/mvpcf/mvpcf.js",
+
+       "JSON"                          : "libMwApi/json2.js",
+       "$j.cookie"                     : "jquery/plugins/jquery.cookie.js",
+       "$j.contextMenu"        : "jquery/plugins/jquery.contextMenu.js",
+       "$j.fn.suggestions"     : "jquery/plugins/jquery.suggestions.js",
+       "$j.fn.textSelection"   : "jquery/plugins/jquery.textSelection.js",
+
+       "$j.effects.blind"              : "jquery/jquery.ui/ui/effects.blind.js",
+       "$j.effects.drop"               : "jquery/jquery.ui/ui/effects.drop.js",
+       "$j.effects.pulsate"    : "jquery/jquery.ui/ui/effects.pulsate.js",
+       "$j.effects.transfer"   : "jquery/jquery.ui/ui/effects.transfer.js",
+       "$j.ui.droppable"               : "jquery/jquery.ui/ui/ui.droppable.js",
+       "$j.ui.slider"                  : "jquery/jquery.ui/ui/ui.slider.js",
+       "$j.effects.bounce"             : "jquery/jquery.ui/ui/effects.bounce.js",
+       "$j.effects.explode"    : "jquery/jquery.ui/ui/effects.explode.js",
+       "$j.effects.scale"              : "jquery/jquery.ui/ui/effects.scale.js",
+       "$j.ui.datepicker"              : "jquery/jquery.ui/ui/ui.datepicker.js",
+       "$j.ui.progressbar"             : "jquery/jquery.ui/ui/ui.progressbar.js",
+       "$j.ui.sortable"                : "jquery/jquery.ui/ui/ui.sortable.js",
+       "$j.effects.clip"               : "jquery/jquery.ui/ui/effects.clip.js",
+       "$j.effects.fold"               : "jquery/jquery.ui/ui/effects.fold.js",
+       "$j.effects.shake"              : "jquery/jquery.ui/ui/effects.shake.js",
+       "$j.ui.dialog"                  : "jquery/jquery.ui/ui/ui.dialog.js",
+       "$j.ui.resizable"               : "jquery/jquery.ui/ui/ui.resizable.js",
+       "$j.ui.tabs"                    : "jquery/jquery.ui/ui/ui.tabs.js",
+       "$j.effects.core"               : "jquery/jquery.ui/ui/effects.core.js",
+       "$j.effects.highlight"  : "jquery/jquery.ui/ui/effects.highlight.js",
+       "$j.effects.slide"              : "jquery/jquery.ui/ui/effects.slide.js",
+       "$j.ui.accordion"               : "jquery/jquery.ui/ui/ui.accordion.js",
+       "$j.ui.draggable"               : "jquery/jquery.ui/ui/ui.draggable.js",
+       "$j.ui.selectable"              : "jquery/jquery.ui/ui/ui.selectable.js",
+
+       "$j.fn.dragDropFile"            : "libAddMedia/dragDropFile.js",
+       "mvFirefogg"                    : "libAddMedia/mvFirefogg.js",
+       "mvAdvFirefogg"                 : "libAddMedia/mvAdvFirefogg.js",
+       "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
+       "remoteSearchDriver"    : "libAddMedia/remoteSearchDriver.js",
+       "seqRemoteSearchDriver" : "libSequencer/seqRemoteSearchDriver.js",
+
+       "baseRemoteSearch"              : "libAddMedia/searchLibs/baseRemoteSearch.js",
+       "mediaWikiSearch"               : "libAddMedia/searchLibs/mediaWikiSearch.js",
+       "metavidSearch"                 : "libAddMedia/searchLibs/metavidSearch.js",
+       "archiveOrgSearch"              : "libAddMedia/searchLibs/archiveOrgSearch.js",
+       "flickrSearch"                  : "libAddMedia/searchLibs/flickrSearch.js",
+       "baseRemoteSearch"              : "libAddMedia/searchLibs/baseRemoteSearch.js",
+
+       "mvClipEdit"                    : "libClipEdit/mvClipEdit.js",
+
+       "embedVideo"            : "libEmbedVideo/embedVideo.js",
+       "flashEmbed"            : "libEmbedVideo/flashEmbed.js",
+       "genericEmbed"          : "libEmbedVideo/genericEmbed.js",
+       "htmlEmbed"                     : "libEmbedVideo/htmlEmbed.js",
+       "javaEmbed"                     : "libEmbedVideo/javaEmbed.js",
+       "nativeEmbed"           : "libEmbedVideo/nativeEmbed.js",
+       "quicktimeEmbed"        : "libEmbedVideo/quicktimeEmbed.js",
+       "vlcEmbed"                      : "libEmbedVideo/vlcEmbed.js",
+
+       "mvPlayList"            : "libSequencer/mvPlayList.js",
+       "mvSequencer"           : "libSequencer/mvSequencer.js",
+       "mvFirefoggRender"      : "libSequencer/mvFirefoggRender.js",
+       "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
+
+       "mvTextInterface"       : "libTimedText/mvTextInterface.js",
+       "mvTimedTextEdit"       : "libTimedText/mvTimedTextEdit.js"
+});
+
+// Dependency mapping for CSS files for self-contained included plugins:
+lcCssPath({
+       '$j.Jcrop'                      : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
+       '$j.fn.ColorPicker'     : 'libClipEdit/colorpicker/css/colorpicker.css'
+})
 
-// (We install the default config values for anything not set in mwConfig once we know we have jquery)
-if( !mwConfig )
-       var mwConfig = {};
 
 // parseUri 1.2.2
 // (c) Steven Levithan <stevenlevithan.com>
@@ -70,20 +190,19 @@ parseUri.options = {
 // For use when mv_embed with script-loader is in the root MediaWiki path
 var mediaWiki_mvEmbed_path = 'js2/mwEmbed/';
 
-var _global = this; // Global obj (depreciate use window)
+//The global scope: will be depreciated once we get everything into $mw
+var _global = this; 
 
 /*
 * setup the empty global $mw object
-* will ensure all our functions are properly namespaced
+* will ensure all our functions and variables are properly namespaced
+* reducing chance of conflicts
 */
 if(!window['$mw']){
        window['$mw'] = {}
 }
 
 //@@todo move these into $mw
-var mv_init_done = false;
-var global_cb_count = 0;
-var global_player_list = new Array(); // The global player list per page
 var global_req_cb = new Array(); // The global request callback array
 
 // Get the mv_embed location if it has not been set
@@ -97,6 +216,28 @@ if( !mv_embed_path ) {
 * there way into the $mw namespace
 */
 (function( $ ) {
+       /*
+        * global config
+        */
+       $.conf = {
+               'skin_name' : 'mvpcf',
+               'jui_skin' : 'redmond',
+               'video_size' : '400x300'        
+       }
+       //list valid skins here:
+       $.valid_skins = ['mvpcf', 'kskin'];
+       // the version of mwEmbed
+       $.version = '1.0r21';
+       
+       /*
+       * some global containers flags 
+       */
+       $.skin_list = new Array();
+       $.init_done = false;
+       $.cb_count = 0;
+       $.player_list = new Array(), // The global player list per page
+       $.req_cb = new Array() // The global request callback array     
+        
        /*
        * Language classes $mw.lang
        *
@@ -152,18 +293,20 @@ if( !mv_embed_path ) {
 
                //swap in the arg values
                var ms =  $.lang.gMsgSwap( key, args) ;
-
+               
+               
+               
                //a quick check to see if we need to send the msg via the 'parser'
                //(we can add more detailed check once we support more wiki syntax)
-               if(ms.indexOf('{{')==-1){
+               if( ms.indexOf('{{') === -1 && ms.indexOf('[') === -1){
                        return ms;
-                       //return ms;
                }
 
                //make sure we have the lagMagic setup:
+               //@@todo move to init
                $.lang.magicSetup();
                //send the msg key through the parser
-               pObj = $.parser.pNew( ms );
+               var pObj = $.parser.pNew( ms );         
                //return the transformed msg
                return pObj.getHTML();
        }
@@ -232,7 +375,7 @@ if( !mv_embed_path ) {
                 * Plural matchRuleTest
                 */
                function matchRuleTest(cRule, val){
-                       js_log("matchRuleTest:: " + typeof cRule + ' ' + cRule + ' == ' + val );
+                       //js_log("matchRuleTest:: " + typeof cRule + ' ' + cRule + ' == ' + val );
 
                        function checkValue(compare, val){
                                if(typeof compare == 'string'){
@@ -301,12 +444,12 @@ if( !mv_embed_path ) {
                for(var ruleInx in rs){
                        cRule = rs[ruleInx];
                        if( matchRuleTest( cRule, tObj.arg ) ){
-                               js_log("matched rule: " + ruleInx );
+                               //js_log("matched rule: " + ruleInx );
                                return getTempParamFromRuleInx(tObj, rCount );
                        }
                        rCount ++;
                }
-               js_log('no match found for: ' + tObj.arg + ' using last/other : ' +  tObj.param [ tObj.param.length -1 ] );
+               //js_log('no match found for: ' + tObj.arg + ' using last/other : ' +  tObj.param [ tObj.param.length -1 ] );
                //return the last /"other" template param
                return tObj.param [ tObj.param.length -1 ];
        }
@@ -425,7 +568,7 @@ if( !mv_embed_path ) {
        /**
         * parser addMagic
         *
-        * lets you add a set of magic keys and associated callback funcions
+        * lets you add a set of magic keys and associated callback functions
         * callback: @param ( Object Template )
         * callback: @return the transformed template output
         *
@@ -451,7 +594,7 @@ if( !mv_embed_path ) {
                        },
                        updateText : function( wikiText ){
                                this.wikiText = wikiText;
-                               //invalidate the output (will force a reparse)
+                               //invalidate the output (will force a re-parse )
                                this.pOut = '';
                        },
                        parse : function(){
@@ -460,10 +603,12 @@ if( !mv_embed_path ) {
                                 */
 
                                // ~ probably a better algorithm out there / should mirror php parser flow ~
+                               //       (we are already running white-space issues ie php parse strips whitespace diffrently)
+                               
                                // ... but I am having fun with recursion so here it is...
                                // or at least mirror: http://www.mediawiki.org/wiki/Extension:Page_Object_Model
-                               function rdpp ( txt , cn){
-                                       var node = {};
+                               function rdpp ( txt , cn){                              
+                                       var node = {};                                  
                                        //inspect each char
                                        for(var a=0; a < txt.length; a++){
                                                if( txt[a] == '{' && txt[a+1] == '{' ){
@@ -473,18 +618,18 @@ if( !mv_embed_path ) {
                                                                node['c'] = new Array();
 
                                                        node['c'].push( rdpp( txt.substr( a ), true ) );                                                                                                                                                                                                                                                                                                                                        
-                                               }else if( txt[a] == '}' && txt[a+1] == '}'){
+                                               }else if( txt[a] == '}' && txt[a+1] == '}'){                                                    
+                                                       a=a+2;
                                                        if( !node['p'] ){
                                                                return node;
-                                                       }
-                                                       node = node['p'];
-                                                       a=a+2;
+                                                       }                                                       
+                                                       node = node['p'];                                                       
                                                }
                                                if(!node['t'])
                                                        node['t']='';
-                                               
-                                               if( txt[a] )
-                                                               node['t']+=txt[a];
+                                               //dont put closures into output:
+                                               if( txt[a] &&  txt[a]!='}' )
+                                                               node['t'] += txt[a];
                                                                
                                        }
                                        return node;
@@ -492,7 +637,7 @@ if( !mv_embed_path ) {
                                /**
                                 * parse template text as template name and named params
                                 */
-                               function parseTmplTxt( ts ){
+                               function parseTmplTxt( ts ){                            
                                        var tObj = {};
                                        //Get template name:
                                        tname = ts.split('\|').shift() ;
@@ -507,14 +652,18 @@ if( !mv_embed_path ) {
                                                tObj["arg"] = tname.split(':').pop();
                                        }
 
-                                       js_log("TNAME::" + tObj["name"] + ' from:: ' + ts);     
-                                       
+                                       //js_log("TNAME::" + tObj["name"] + ' from:: ' + ts);                                           
                                        var pSet = ts.split('\|');
-                                       pSet.splice(0,1);
+                                       pSet.splice(0,1);                                       
                                        if( pSet.length ){
                                                tObj.param = new Array();
-                                               for(var pInx in pSet){
+                                               for(var pInx in pSet){                                                  
                                                        var tStr = pSet[ pInx ];
+                                                       //check for empty param
+                                                       if(tStr==''){
+                                                               tObj.param[ pInx ] = '';
+                                                               continue;
+                                                       }
                                                        for(var b=0 ; b < tStr.length ; b++){
                                                                if(tStr[b] == '=' && b>0 && b<tStr.length && tStr[b-1]!='\\'){
                                                                        //named param
@@ -525,12 +674,12 @@ if( !mv_embed_path ) {
                                                                }
                                                        }
                                                }
-                                       }
+                                       }                                                       
                                        return tObj;
                                }
                                function getMagicTxtFromTempNode( node ){
                                        node.tObj = parseTmplTxt ( node.t );
-                                       //do magic swap if templet key found in pMagicSet
+                                       //do magic swap if template key found in pMagicSet
                                        if( node.tObj.name in pMagicSet){
                                                var nt = pMagicSet[ node.tObj.name ]( node.tObj );
                                                return nt;
@@ -575,7 +724,7 @@ if( !mv_embed_path ) {
                                //strip out the parent from the root    
                                this.pNode['p'] = null;
                                
-                               //do the recusrive magic swap text:
+                               //do the recursive magic swap text:
                                this.pOut = recurse_magic_swap( this.pNode );
 
                        },
@@ -613,10 +762,10 @@ if( !mv_embed_path ) {
                        /**
                         * Returns the transformed wikitext
                         * 
-                        * Build output from swapable index 
-                        *              (all transforms must be expanded in parse stage and linerarly rebuilt)  
-                        * Alternativly we could build output using a placeholder & replace system 
-                        *              (this lets us be slightly more slopty with ordering and indexes, but probably slower)
+                        * Build output from swappable index 
+                        *              (all transforms must be expanded in parse stage and linearly rebuilt)  
+                        * Alternatively we could build output using a place-holder & replace system 
+                        *              (this lets us be slightly more slopy with ordering and indexes, but probably slower)
                         * 
                         * Ideal: we build a 'wiki DOM' 
                         *              When editing you update the data structure directly
@@ -626,7 +775,7 @@ if( !mv_embed_path ) {
                                //wikiText updates should invalidate pOut
                                if( this.pOut == ''){
                                        this.parse();
-                               }
+                               }                               
                                return this.pOut;
                        }
                };
@@ -641,165 +790,26 @@ var loadGM = $mw.lang.loadGM;
 var loadRS = $mw.lang.loadRS;
 var gM = $mw.lang.gM;
 
-//if some no-js2 script defined and loaded gMsg in global space:
-if( _global['gMsg'] ){
-       loadGM( _global['gMsg'] );
-}
-
 // All default messages in [English] should be overwritten by the CMS language message system.
 $mw.lang.loadGM({
-       "mwe-loading_txt" : "loading ...",
-       "mwe-loading_title" : "Loading...",
+       "mwe-loading_txt" : "Loading ...",
        "mwe-size-gigabytes" : "$1 GB",
        "mwe-size-megabytes" : "$1 MB",
        "mwe-size-kilobytes" : "$1 K",
        "mwe-size-bytes" : "$1 B",
        "mwe-error_load_lib" : "Error: JavaScript $1 was not retrievable or does not define $2",
-       "mwe-loading-add-media-wiz": "Loading add media wizard",
-       "mwe-apiproxy-setup" : " Setting up API proxy"
+       "mwe-loading-add-media-wiz" : "Loading add media wizard",
+       "mwe-apiproxy-setup" : "Setting up API proxy",
+       "mwe-load-drag-item" : "Loading dragged item",
+       "mwe-ok" : "OK",
+       "mwe-cancel" : "Cancel"
 });
 
 
-
-/**
- * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
- * Any file _not_ listed here won't be auto-loadable
- * @path The path to the file (or set of files) with ending slash
- * @gClasses The set of classes
- *             if it's an array, $j.className becomes jquery.className.js
- *             if it's an associative object then key => value pairs are used
- */
-if( typeof mvAutoLoadClasses == 'undefined' )
-       mvAutoLoadClasses = {};
-
-// The script that loads the class set
-function lcPaths( classSet ){
-       for( var i in classSet ) {
-               mvAutoLoadClasses[i] = classSet[i];
-       }
-}
-
-function mvGetClassPath(k){
-       if( mvAutoLoadClasses[k] ) {
-               //js_log('got class path:' + k +  ' : '+ mvClassPaths[k]);
-               return mvAutoLoadClasses[k];
-       } else {
-               js_log('Error:: Could not find path for requested class ' + k );
-               return false;
-       }
-}
-if( typeof mvCssPaths == 'undefined' )
-       mvCssPaths = {};
-
-function lcCssPath( cssSet ) {
-       for( var i in cssSet ) {
-               mvCssPaths[i] = mv_embed_path + cssSet[i];
-       }
-}
-
-/*
- * --  Load Class Paths --
- *
- * MUST BE VALID JSON (NOT JS)
- * This is used by the script loader to auto-load classes (so we only define
- * this once for PHP & JavaScript)
- *
- * Right now the PHP AutoLoader only reads this mv_embed.js file.
- * In the future we could have multiple lcPath calls that PHP reads
- * (if our autoloading class list becomes too long) just have to add those
- * files to the jsAutoLoader file list.
- */
-lcPaths({
-       "mv_embed"                      : "mv_embed.js",
-       "window.jQuery"         : "jquery/jquery-1.3.2.js",
-       "$j.fn.pngFix"          : "jquery/plugins/jquery.pngFix.js",
-       "$j.fn.autocomplete": "jquery/plugins/jquery.autocomplete.js",
-       "$j.fn.hoverIntent"     : "jquery/plugins/jquery.hoverIntent.js",
-       "$j.fn.datePicker"      : "jquery/plugins/jquery.datePicker.js",
-       "$j.ui"                         : "jquery/jquery.ui/ui/ui.core.js",
-       "$j.fn.ColorPicker"     : "libClipEdit/colorpicker/js/colorpicker.js",
-       "$j.Jcrop"                      : "libClipEdit/Jcrop/js/jquery.Jcrop.js",
-       "$j.fn.simpleUploadForm" : "libAddMedia/simpleUploadForm.js",
-       
-       "$mw.proxy"             : "libMwApi/mw.proxy.js", 
-       
-       "ctrlBuilder"   : "skins/ctrlBuilder.js",
-       "kskinConfig"   : "skins/kskin/kskin.js",
-       "mvpcfConfig"   : "skins/mvpcf/mvpcf.js",
-
-       "JSON"                          : "libMwApi/json2.js",
-       "$j.cookie"                     : "jquery/plugins/jquery.cookie.js",
-       "$j.contextMenu"        : "jquery/plugins/jquery.contextMenu.js",
-       "$j.fn.suggestions"     : "jquery/plugins/jquery.suggestions.js",
-
-       "$j.effects.blind"              : "jquery/jquery.ui/ui/effects.blind.js",
-       "$j.effects.drop"               : "jquery/jquery.ui/ui/effects.drop.js",
-       "$j.effects.pulsate"    : "jquery/jquery.ui/ui/effects.pulsate.js",
-       "$j.effects.transfer"   : "jquery/jquery.ui/ui/effects.transfer.js",
-       "$j.ui.droppable"               : "jquery/jquery.ui/ui/ui.droppable.js",
-       "$j.ui.slider"                  : "jquery/jquery.ui/ui/ui.slider.js",
-       "$j.effects.bounce"             : "jquery/jquery.ui/ui/effects.bounce.js",
-       "$j.effects.explode"    : "jquery/jquery.ui/ui/effects.explode.js",
-       "$j.effects.scale"              : "jquery/jquery.ui/ui/effects.scale.js",
-       "$j.ui.datepicker"              : "jquery/jquery.ui/ui/ui.datepicker.js",
-       "$j.ui.progressbar"             : "jquery/jquery.ui/ui/ui.progressbar.js",
-       "$j.ui.sortable"                : "jquery/jquery.ui/ui/ui.sortable.js",
-       "$j.effects.clip"               : "jquery/jquery.ui/ui/effects.clip.js",
-       "$j.effects.fold"               : "jquery/jquery.ui/ui/effects.fold.js",
-       "$j.effects.shake"              : "jquery/jquery.ui/ui/effects.shake.js",
-       "$j.ui.dialog"                  : "jquery/jquery.ui/ui/ui.dialog.js",
-       "$j.ui.resizable"               : "jquery/jquery.ui/ui/ui.resizable.js",
-       "$j.ui.tabs"                    : "jquery/jquery.ui/ui/ui.tabs.js",
-       "$j.effects.core"               : "jquery/jquery.ui/ui/effects.core.js",
-       "$j.effects.highlight"  : "jquery/jquery.ui/ui/effects.highlight.js",
-       "$j.effects.slide"              : "jquery/jquery.ui/ui/effects.slide.js",
-       "$j.ui.accordion"               : "jquery/jquery.ui/ui/ui.accordion.js",
-       "$j.ui.draggable"               : "jquery/jquery.ui/ui/ui.draggable.js",
-       "$j.ui.selectable"              : "jquery/jquery.ui/ui/ui.selectable.js",
-
-       "mvFirefogg"                    : "libAddMedia/mvFirefogg.js",
-       "mvAdvFirefogg"                 : "libAddMedia/mvAdvFirefogg.js",
-       "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
-       "remoteSearchDriver"    : "libAddMedia/remoteSearchDriver.js",
-       "seqRemoteSearchDriver" : "libSequencer/seqRemoteSearchDriver.js",
-
-       "baseRemoteSearch"              : "libAddMedia/searchLibs/baseRemoteSearch.js",
-       "mediaWikiSearch"               : "libAddMedia/searchLibs/mediaWikiSearch.js",
-       "metavidSearch"                 : "libAddMedia/searchLibs/metavidSearch.js",
-       "archiveOrgSearch"              : "libAddMedia/searchLibs/archiveOrgSearch.js",
-       "flickrSearch"                  : "libAddMedia/searchLibs/flickrSearch.js",
-       "baseRemoteSearch"              : "libAddMedia/searchLibs/baseRemoteSearch.js",
-
-       "mvClipEdit"                    : "libClipEdit/mvClipEdit.js",
-
-       "embedVideo"            : "libEmbedVideo/embedVideo.js",
-       "flashEmbed"            : "libEmbedVideo/flashEmbed.js",
-       "genericEmbed"          : "libEmbedVideo/genericEmbed.js",
-       "htmlEmbed"                     : "libEmbedVideo/htmlEmbed.js",
-       "javaEmbed"                     : "libEmbedVideo/javaEmbed.js",
-       "nativeEmbed"           : "libEmbedVideo/nativeEmbed.js",
-       "quicktimeEmbed"        : "libEmbedVideo/quicktimeEmbed.js",
-       "vlcEmbed"                      : "libEmbedVideo/vlcEmbed.js",
-
-       "mvPlayList"            : "libSequencer/mvPlayList.js",
-       "mvSequencer"           : "libSequencer/mvSequencer.js",
-       "mvFirefoggRender"      : "libSequencer/mvFirefoggRender.js",
-       "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
-
-       "mvTextInterface"       : "libTimedText/mvTextInterface.js"
-});
-
-// Dependency mapping for CSS files for self-contained included plugins:
-lcCssPath({
-       '$j.Jcrop'                      : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
-       '$j.fn.ColorPicker'     : 'libClipEdit/colorpicker/css/colorpicker.css'
-})
-
-
 // Get the loading image
 function mv_get_loading_img( style, class_attr ){
        var style_txt = (style)?style:'';
-       var class_attr = (class_attr)?'class="'+class_attr+'"':'class="mv_loading_img"';
+       var class_attr = (class_attr) ? 'class="' + class_attr + '"' : 'class="mv_loading_img"';
        return '<div '+class_attr+' style="' + style +'"></div>';
 }
 
@@ -812,9 +822,8 @@ function mv_set_loading(target, load_id){
 }
 
 /**
-  * mvJsLoader class handles initialization and js file loads
-  */
-
+* mvJsLoader class handles initialization and js file loads
+*/
 var mvJsLoader = {
        libreq : {},
        libs : {},
@@ -835,8 +844,8 @@ var mvJsLoader = {
        missing_path : null,
        doLoad: function( loadLibs, callback ) {
                this.ctime++;
-
                if( loadLibs && loadLibs.length != 0 ) {
+                       //js_log("doLoad setup::" + JSON.stringify( loadLibs ) );
                        // Set up this.libs
                        // First check if we already have this library loaded
                        var all_libs_loaded = true;
@@ -847,7 +856,7 @@ var mvJsLoader = {
                                }
                        }
                        if( all_libs_loaded ) {
-                               //js_log( 'Libraries ( ' + loadLibs  +  ') already loaded... skipping load request' );
+                               js_log( 'Libraries ( ' + loadLibs  +  ') already loaded... skipping load request' );
                                callback();
                                return;
                        }
@@ -872,7 +881,7 @@ var mvJsLoader = {
                                                coma = ',';
                                        }
                                }
-                               //Build the url to the scriptServer striping its request paramaters:
+                               //Build the url to the scriptServer striping its request parameters:
                                var puri = parseUri( getMvEmbedURL() );
                                if( ( getMvEmbedURL().indexOf('://') != -1 )
                                        && puri.host != parseUri( document.URL ).host )
@@ -881,10 +890,9 @@ var mvJsLoader = {
                                }else{
                                        var scriptPath = puri.path;
                                }
-                               //js_log('scriptServer Path is: ' + scriptPath + "\n host script path:" + getMvEmbedURL() );
-                               var dbug_attr = ( puri.queryKey['debug'] ) ? '&debug=true' : '';
+                               //js_log('scriptServer Path is: ' + scriptPath + "\n host script path:" + getMvEmbedURL() );                            
                                this.libs[ last_class ] = scriptPath + '?class=' + class_set +
-                                       '&urid=' + getMvUniqueReqId() + dbug_attr;
+                                       '&' + getMwReqParam();
 
                        } else {
                                // Do many requests
@@ -895,19 +903,19 @@ var mvJsLoader = {
                                                // Do a direct load of the file (pass along unique request id from
                                                // request or mv_embed Version )
                                                var qmark = (libLoc.indexOf( '?' ) !== true) ? '?' : '&';
-                                               this.libs[curLib] = mv_embed_path + libLoc + qmark + 'urid=' + getMvUniqueReqId();
+                                               this.libs[curLib] = mv_embed_path + libLoc + qmark + getMwReqParam();
                                        }
                                }
                        }
                }
+               
                if( callback ) {
                        this.callbacks.push( callback );
                }
                if( this.checkLoading() ) {
                        //@@todo we should check the <script> Element .onLoad property to
-                       //make sure its just not a very slow connection or we can run the callback
+                       //make sure its just not a very slow connection
                        //(even though the class is not loaded)
-
                        if( this.load_time++ > 4000 ){ // Time out after ~80 seconds
                                js_log( gM('mwe-error_load_lib', [mvGetClassPath(this.missing_path),  this.missing_path]) );
                                this.load_error = true;
@@ -997,11 +1005,14 @@ var mvJsLoader = {
         * checks for jQuery and adds the $j noConflict var
         */
        jQueryCheck: function( callback ) {
-               js_log( 'jQueryCheck::' );
+               //js_log( 'jQueryCheck::' );
+               var _this = this;
                // Skip stuff if $j is already loaded:
-               if( _global['$j'] && callback )
+               if( _global['$j'] && callback ){
                        callback();
-               var _this = this;
+                       if( _this.jQuerySetupFlag )
+                               return ;
+               }               
                // Load jQuery
                _this.doLoad([
                        'window.jQuery'
@@ -1011,21 +1022,17 @@ var mvJsLoader = {
                                _global['$j'] = jQuery.noConflict();
                        }
                        if( _this.jQuerySetupFlag == false){
-                               js_log('setup mv_embed jQuery bindings');
+                               //js_log('setup mv_embed jQuery bindings');
                                //setup our global settings using the (jQuery helper)
-                               mwConfig = $j.extend( mwDefaultConfig, mwConfig);
 
                                // Set up the skin path
-                               _global['mv_jquery_skin_path'] = mv_embed_path + 'jquery/jquery.ui/themes/' +mwConfig['jui_skin'] + '/';
-                               _global['mv_skin_img_path'] = mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/images/';
-                               _global['mv_default_thumb_url'] = mv_skin_img_path + 'vid_default_thumb.jpg';
-
-                               //setup skin dependent dependencies
-                               lcCssPath({'embedVideo' : 'skins/' + mwConfig['skin_name'] + '/playerSkin.css'});
+                               _global['mv_jquery_skin_path'] = mv_embed_path + 'jquery/jquery.ui/themes/' + $mw.conf['jui_skin'] + '/';
+                               _global['mv_skin_img_path'] = mv_embed_path + 'skins/' + $mw.conf['skin_name'] + '/images/';
+                               _global['mv_default_thumb_url'] = mv_skin_img_path + 'vid_default_thumb.jpg';                   
 
                                // Make sure the skin/style sheets are always available:
                                loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
-                               loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/styles.css' );
+                               loadExternalCss( mv_embed_path + 'skins/' + $mw.conf['skin_name'] + '/styles.css' );
 
                                // Set up AJAX to not send dynamic URLs for loading scripts (we control that with
                                // the scriptLoader)
@@ -1063,9 +1070,14 @@ var mvJsLoader = {
                                        '$j.ui.slider'
                                ]
                        ];
-                       //add skin if set:
-                       if( mwConfig['skin_name'] )
-                               depReq[0].push( mwConfig['skin_name'] + 'Config' );
+                       
+                       //add any requested skins (suports multiple skins per single page)
+                       if( $mw.skin_list ){
+                               for(var i in $mw.skin_list  ){
+                                       depReq[0].push( $mw.skin_list[i] + 'Config' );
+                               }
+                       }
+                               
 
                        // Add PNG fix if needed:
                        if( $j.browser.msie || $j.browser.version < 7 )
@@ -1085,17 +1097,19 @@ var mvJsLoader = {
        // Check the jQuery flag. This way, when remote embedding, we don't load jQuery
        // unless js2AddOnloadHook was used or there is video on the page.
        runQueuedFunctions: function() {
-               js_log("runQueuedFunctions");
+               js_log("runQueuedFunctions");           
                var _this = this;               
-               this.jQueryCheck( function() {
-                       this.doneReadyEvents = true;
+               this.jQueryCheck( function() {                  
                        _this.runReadyEvents();
+                       _this.doneReadyEvents = true;
                });
        },
        runReadyEvents: function() {
                js_log( "runReadyEvents" );
-               while( this.onReadyEvents.length ) {
-                       this.onReadyEvents.shift()();
+               while( this.onReadyEvents.length ) {    
+                       var func = this.onReadyEvents.shift();
+                       //js_log('run onReady:: ' + func );
+                       func();
                }
        }
 }
@@ -1119,23 +1133,36 @@ $mw.load = mwLoad;
  * $j(document).ready( function(){ */
 function mwdomReady( force ) {
        js_log( 'f:mwdomReady:' );
-       if( !force && mv_init_done ) {
-               js_log( "mv_init_done already done, do nothing..." );
+       if( !force && $mw.init_done ) {
+               js_log( "mw done, do nothing..." );
                return false;
        }
-       mv_init_done = true;
+       $mw.init_done = true;
        // Handle the execution of queued functions with jQuery "ready"
 
-       // Check if this page has a video or playlist
+       // Check if this page has a video, audio or playlist tag
        var e = [
                document.getElementsByTagName( "video" ),
                document.getElementsByTagName( "audio" ),
                document.getElementsByTagName( "playlist" )
        ];
        if( e[0].length != 0 || e[1].length != 0 || e[2].length != 0 ) {
-               js_log( 'we have items to rewrite' );
-               setSwappableToLoading( e );
-               // Load libs and process them
+               //look for any skin classes we have to load: 
+               for(var j in e){
+                       for(var k in e[j]){
+                               if(e[j][k] && typeof( e[j][k]) == 'object'){
+                                       var     sn = e[j][k].getAttribute('class');                             
+                                       if( sn && sn != ''){
+                                               for(var n=0;n< $mw.valid_skins.length;n++){ 
+                                                       if( sn.indexOf($mw.valid_skins[n]) !== -1){
+                                                               $mw.skin_list.push( $mw.valid_skins[n] );
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }                               
+               // Load libs and process videos
                mvJsLoader.embedVideoCheck( function() {
                        // Run any queued global events:
                        mv_video_embed( function() {
@@ -1143,30 +1170,22 @@ function mwdomReady( force ) {
                        });
                });
        } else {
-               // If we already have jQuery, make sure it's loaded into its proper context $j
-               // Run any queued global events
                mvJsLoader.runQueuedFunctions();
        }
 }
-// A quick function that sets the initial text of swappable elements to "loading".
-// jQuery might not be ready. Does not destroy inner elements.
-function setSwappableToLoading( e ) {
-       //for(var i =0)
-       //for(var j = 0; i < j.length; j++){
-       //}
-}
+
 //js2AddOnloadHook: ensure jQuery and the DOM are ready
 function js2AddOnloadHook( func ) {
-       js_log("js2AddOnloadHook::" + mvJsLoader.doneReadyEvents);
-       // If we have already run the DOM-ready function, just run the function directly:
-       if( mvJsLoader.doneReadyEvents ) {
-               // Make sure jQuery is there:
-               mvJsLoader.jQueryCheck( function() {
+       //js_log('js2AddOnloadHook:: jquery:' + typeof window.jQuery + ' $j: ' + typeof $j);    
+       //check for jQuery then add the load event (to run after video tag rewrites (if present) 
+       mvJsLoader.jQueryCheck( function() {
+               if( mvJsLoader.doneReadyEvents ) {
+                       //js_log('run queued event: ' + func);  
                        func();
-               });
-       } else {
-               mvJsLoader.addLoadEvent( func );
-       }
+               } else {                
+                       mvJsLoader.addLoadEvent( func );
+               }
+       });
 }
 // Deprecated mwAddOnloadHook in favor of js2 naming (for clear separation of js2 code from old MW code
 var mwAddOnloadHook = js2AddOnloadHook;
@@ -1193,11 +1212,11 @@ var temp_f;
 if( window.onload ) {
     temp_f = window.onload;
 }
-// Use the onload method as a backup (mwdomReady hanndles dobule init calls)
+// Use the onload method as a backup
 window.onload = function () {
     if( temp_f )
         temp_f();
-       mwdomReady();    
+       mwdomReady();
 }
 
 /*
@@ -1205,13 +1224,25 @@ window.onload = function () {
  * (set up after jQuery is available).
  *
  * These functions are genneraly are loaders that do the dynamic mapping of
- * dependencies for a given compoent
+ * dependencies for a given commponet
  * 
  *
  */
 function mv_jqueryBindings() {
        js_log( 'mv_jqueryBindings' );
        (function( $ ) {
+               /*
+               * dragDrop file loader 
+               */
+               $.fn.dragFileUpload = function ( conf ){
+                       if( this.selector ){    
+                               var _this = this;       
+                               //load the dragger and "setup"
+                               $mw.load( ['$j.fn.dragDropFile'], function(){
+                                       $j(_this.selector).dragDropFile();                                                      
+                               }); 
+                       }                                        
+               }
                /*
                 * apiProxy Loader loader:
                 * 
@@ -1235,6 +1266,7 @@ function mv_jqueryBindings() {
                                }
                        });     
                }
+               
                //non selector based add-media-wizard direct invocation with loader
                $.addMediaWiz = function( iObj, callback ){                     
                        js_log(".addMediaWiz call");
@@ -1261,20 +1293,21 @@ function mv_jqueryBindings() {
                $.fn.addMediaWiz = function( iObj, callback ) {                 
                        if( this.selector ){                    
                                // First set the cursor for the button to "loading"
-                               $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_title' ) );
+                               $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_txt' ) );
                                //set the target: 
                                iObj['target_invocation'] = this.selector;
                        }
 
                        // Load the mv_embed_base skin:
                        loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
-                       loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name']+'/styles.css' );
+                       loadExternalCss( mv_embed_path + 'skins/' + $mw.conf['skin_name'] + '/styles.css' );
                        // Load all the required libs:
                        mvJsLoader.jQueryCheck( function() {
                                // Load with staged dependencies (for IE that does not execute in order)
                                mvJsLoader.doLoadDepMode([
                                        [       'remoteSearchDriver',
                                                '$j.cookie',
+                                               '$j.fn.textSelection',
                                                '$j.ui'
                                        ],[
                                                '$j.ui.resizable',
@@ -1285,19 +1318,23 @@ function mv_jqueryBindings() {
                                        ]
                                ], function() {
                                        iObj['instance_name'] = 'rsdMVRS';
-                                       _global['rsdMVRS'] = new remoteSearchDriver( iObj );
+                                       if( ! _global['rsdMVRS'] )
+                                               _global['rsdMVRS'] = new remoteSearchDriver( iObj );
                                        if( callback ) {
                                                callback( _global['rsdMVRS'] );
                                        }
                                });
                        });
                }
+               /*
+               * Sequencer loader
+               */
                $.fn.sequencer = function( iObj, callback ) {
                        // Debugger
                        iObj['target_sequence_container'] = this.selector;
                        // Issue a request to get the CSS file (if not already included):
                        loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
-                       loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/mv_sequence.css' );
+                       loadExternalCss( mv_embed_path + 'skins/' + $mw.conf['skin_name'] + '/mv_sequence.css' );
                        // Make sure we have the required mv_embed libs (they are not loaded when no video
                        // element is on the page)
                        mvJsLoader.embedVideoCheck( function() {
@@ -1343,7 +1380,7 @@ function mv_jqueryBindings() {
                                iObj = {};
                        // Add the base theme CSS:
                        loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
-                       loadExternalCss( mv_embed_path + 'skins/'+mwConfig['skin_name'] + '/styles.css' );
+                       loadExternalCss( mv_embed_path + 'skins/' + $mw.conf['skin_name'] + '/styles.css' );
 
                        // Check if we already have Firefogg loaded (the call just updates the element's
                        // properties)
@@ -1475,6 +1512,26 @@ function mv_jqueryBindings() {
                        )
                        return this;
                }
+               /**
+               * resize the dialog to fit the window
+               */
+               $.fn.dialogFitWindow = function(opt){                   
+                       var opt_default = {'hspace':50,'vspace':50};
+                       if(!opt)
+                               var opt={};                     
+                       $j.extend(opt, opt_default);
+                       $j( this.selector).dialog('option', 'width', $j(window).width() - opt.hspace );
+                       $j( this.selector).dialog('option', 'height', $j(window).height() - opt.vspace );
+                       $j( this.selector).dialog('option', 'position','center');
+                               //update the child position: (some of this should be pushed up-stream via dialog config options
+                       $j( this.selector +'~ .ui-dialog-buttonpane').css({
+                               'position':'absolute',
+                               'left':'0px',
+                               'right':'0px',
+                               'bottom':'0px',
+                       });                     
+               }
+               
                /**
                * addLoaderDialog
                *  small helper for putting a loading dialog box on top of everything
@@ -1484,14 +1541,20 @@ function mv_jqueryBindings() {
                */
                $.addLoaderDialog = function( msg_txt ){                        
                        $.addDialog( msg_txt, msg_txt + '<br>' + mv_get_loading_img() );                
-               }
+               }                                               
                
                $.addDialog = function ( title, msg_txt, btn ){
                        $('#mwe_tmp_loader').remove();
                        //append the style free loader ontop: 
                        $('body').append('<div id="mwe_tmp_loader" style="display:none" title="' + title + '" >' +
                                        msg_txt +
-                       '</div>');
+                       '</div>');                      
+                       //special btn == ok gives empty give a single "oky" -> "close"
+                       if( btn == 'ok' ){
+                               btn[ gM('mwe-ok') ] = function(){
+                                       $j('#mwe_tmp_loader').close();
+                               }
+                       }
                        //turn the loader into a real dialog loader: 
                        mvJsLoader.doLoadDepMode([
                                [
@@ -1511,8 +1574,17 @@ function mv_jqueryBindings() {
                                });
                        });
                }
-               $.closeLoaderDialog = function(){                       
-                       $('#mwe_tmp_loader').dialog('close');
+               $.closeLoaderDialog = function(){               
+                       mvJsLoader.doLoadDepMode([
+                               [
+                                       '$j.ui'
+                               ],
+                               [
+                                       '$j.ui.dialog'
+                               ]
+                       ], function() { 
+                               $j('#mwe_tmp_loader').dialog('close');
+                       });
                }
        
                $.mwProxy = function( apiConf ){
@@ -1640,7 +1712,7 @@ function do_api_req( options, callback ) {
                return js_error( 'Error: request paramaters must be an object' );
        }
        // Generate the URL if it's missing
-       if( typeof options.url == 'undefined' || options.url === false ) {
+       if( typeof options.url == 'undefined' || !options.url ) {
                if( !wgServer || ! wgScriptPath ) {
                        return js_error('Error: no api url for api request');
                }
@@ -1653,7 +1725,7 @@ function do_api_req( options, callback ) {
        options.data['format'] = 'json';
 
        // If action is not set, assume query
-       if( !options.data['action'] )
+       if( ! options.data['action'] )
                options.data['action'] = 'query';
 
        // js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );     
@@ -1689,7 +1761,7 @@ function do_api_req( options, callback ) {
                        req_url += paramAnd + encodeURIComponent( i ) + '=' + encodeURIComponent( options.data[i] );
                        paramAnd = '&';
                }
-               var fname = 'mycpfn_' + ( global_cb_count++ );
+               var fname = 'mycpfn_' + ( $mw.cb_count++ );
                _global[ fname ] = callback;
                req_url += '&' + options.jsonCB + '=' + fname;
                loadExternalJs( req_url );
@@ -1701,36 +1773,6 @@ function mwGetLocalApiUrl( url ) {
        }
        return false;
 }
-// Grab wiki form error for wiki html page processing (should be deprecated because we use api now)
-function grabWikiFormError( result_page ) {
-               var res = {};
-               sp = result_page.indexOf( '<span class="error">' );
-               if( sp != -1 ) {
-                       se = result_page.indexOf( '</span>', sp );
-                       res.error_txt = result_page.substr( sp, sp - se ) + '</span>';
-               } else {
-                       // Look for warning
-                       sp = result_page.indexOf( '<ul class="warning">' )
-                       if( sp != -1 ) {
-                               se = result_page.indexOf( '</ul>', sp );
-                               res.error_txt = result_page.substr( sp, se - sp ) + '</ul>';
-                               // Try to add the ignore form item
-                               sfp = result_page.indexOf( '<form method="post"' );
-                               if( sfp != -1 ) {
-                                       sfe = result_page.indexOf( '</form>', sfp );
-                                       res.form_txt = result_page.substr( sfp, sfe - sfp ) + '</form>';
-                               }
-                       } else {
-                               // One more error type check
-                               sp = result_page.indexOf( 'class="mw-warning-with-logexcerpt">' )
-                               if( sp != -1 ) {
-                                       se = result_page.indexOf( '</div>', sp );
-                                       res.error_txt = result_page.substr( sp, se - sp ) + '</div>';
-                               }
-                       }
-               }
-               return res;
-}
 // Do a "normal" request
 function do_request( req_url, callback ) {
        js_log( 'do_request::req_url:' + req_url + ' != ' +  parseUri( req_url ).host );
@@ -1752,7 +1794,8 @@ function do_request( req_url, callback ) {
                global_req_cb.push( callback );
                // Prepend json_ to feed_format if not already requesting json format (metavid specific)
                if( req_url.indexOf( "feed_format=" ) != -1 && req_url.indexOf( "feed_format=json" ) == -1 )
-                       req_url = req_url.replace( /feed_format=/, 'feed_format=json_' );
+                       req_url = req_url.replace( /feed_format=/, 'feed_format=json_' );               
+               
                loadExternalJs( req_url + '&cb=mv_jsdata_cb&cb_inx=' + (global_req_cb.length - 1) );
        }
 }
@@ -1841,7 +1884,7 @@ function loadExternalCss( url ) {
        }
 
        if( url.indexOf('?') == -1 ) {
-               url += '?' + getMvUniqueReqId();
+               url += '?' + getMwReqParam();
        }
        if( !styleSheetPresent( url ) ) {
                js_log( 'load css: ' + url );
@@ -1873,25 +1916,34 @@ function getMvEmbedURL() {
        return false;
 }
 // Get a unique request ID to ensure fresh JavaScript
-function getMvUniqueReqId() {
-       if( _global['urid'] )
-               return _global['urid'];
+function getMwReqParam() {     
+       if( _global['req_param'] )
+               return _global['req_param'];
        var mv_embed_url = getMvEmbedURL();
-       // If we have a URI, return it
-       var urid = parseUri( mv_embed_url ).queryKey['urid']
-       if( urid ) {
-               _global['urid'] = urid;
-               return urid;
-       }
-       // If we're in debug mode, get a fresh unique request key
-       if( parseUri( mv_embed_url ).queryKey['debug'] == 'true' ) {
+       
+       var req_param = '';
+       
+       // If we have a URI, add it to the req
+       var urid = parseUri( mv_embed_url ).queryKey['urid']    
+       // If we're in debug mode, get a fresh unique request key and pass on "debug" param
+       if( parseUri( mv_embed_url ).queryKey['debug'] == 'true' ){
                var d = new Date();
-               var urid = d.getTime();
-               _global['urid'] = urid;
-               return urid;
+               req_param += 'urid=' + d.getTime() + '&debug=true';             
+       }else if( urid ) {
+               // Set from request urid:
+               req_param += 'urid=' + urid;
+       }else{
+               // Otherwise, just use the mv_embed version
+               req_param += 'urid=' + $mw.version;
        }
-       // Otherwise, just return the mv_embed version
-       return MV_EMBED_VERSION;
+       //add the lang param:
+       var langKey = parseUri( mv_embed_url ).queryKey['uselang'];
+       if( langKey )
+               req_param += '&uselang=' + langKey;
+                       
+       _global['req_param'] = req_param;
+               
+       return _global['req_param'];
 }
 /*
  * Set the global mv_embed path based on the script's location
@@ -1948,9 +2000,9 @@ if ( typeof DOMParser == "undefined" ) {
 * Utility functions
 */
 function js_log( string ) {
-       ///add any prepend debug strings if nessesary
-       if( mwConfig['debug_pre'] )
-               string = mwConfig['debug_pre']+ string;
+       ///add any prepend debug strings if nessesary (used for cross browser)
+       if( $mw.conf['debug_pre'] )
+               string = $mw.conf['debug_pre']+ string;
                        
        if( window.console ) {                          
                window.console.log( string );
@@ -1977,4 +2029,4 @@ function js_log( string ) {
 function js_error( string ) {
        alert( string );
        return false;
-}
\ No newline at end of file
+}