// $Revision$

Ensembl.Panel.MultiSpeciesSelector = Ensembl.Panel.MultiSelector.extend({
  updateSelection: function () {
    var params = [ 's', 'r', 'g' ]; // Multi-species parameters
    var existingSelection = {};
    var urlParams = [];
    var i, j, k;
    
    for (var s in Ensembl.multiSpecies) {
      existingSelection[Ensembl.multiSpecies[s].s] = parseInt(s, 10);
    }
    
    for (i = 0; i < this.selection.length; i++) {
      j = existingSelection[this.selection[i]];
      
      if (typeof j != 'undefined') {       
        k = params.length;
        
        while (k--) {
          if (Ensembl.multiSpecies[j][params[k]]) {
            urlParams.push(params[k] + (i + 1) + '=' + Ensembl.multiSpecies[j][params[k]]);
          }
        }
      } else {
        urlParams.push('s' + (i + 1) + '=' + this.selection[i]);
      }
    }
    
    if (this.selection.join(',') != this.initialSelection) {
      Ensembl.redirect(this.elLk.form.attr('action') + '?' + Ensembl.cleanURL(this.elLk.form.serialize() + ';' + urlParams.join(';')));
    }
    
    return true;
  }
});
@@ -130,16 +130,27 @@
  params 
+           
 = %5B 's',
@@ -240,16 +240,56 @@
 lParams 
+        = %5B%5D;%0A    var species           
 = %5B%5D;%0A  
@@ -686,24 +686,160 @@
 rams%5Bk%5D%5D) %7B%0A
+            if (params%5Bk%5D === 's') %7B%0A              species.push('s' + (i + 1) + '=' + Ensembl.multiSpecies%5Bj%5D.s)%0A            %7D else %7B%0A  
             
@@ -914,24 +914,26 @@
 arams%5Bk%5D%5D);%0A
+  
           %7D%0A
@@ -928,24 +928,36 @@
           %7D%0A
+          %7D%0A
         %7D%0A  
@@ -973,32 +973,30 @@
 e %7B%0A        
-urlParam
+specie
 s.push('s' +
@@ -1108,24 +1108,179 @@
 election) %7B%0A
+      $.ajax(%7B%0A        url: '/' + Ensembl.species + '/Ajax/multi_species?' + species.join(';'),%0A        context: this,%0A        complete: function () %7B%0A    
       Ensemb
@@ -1384,28 +1384,74 @@
 ' + 
-urlParams.join(';'))
+species.join(';') + ';' + urlParams.join(';')));%0A        %7D%0A      %7D
 );%0A 

save selected species to the database