/* 
            Prototype Functions to allow easy access to overlays by id and group 
            Author : Jason Patterson 
            Contact : jasonp <at> cableaz.com 
            Date : 8/8/2005 
            */ 
            GMarker.prototype.id = false; 
            GMarker.prototype.group = false; 
            GMap.prototype.addOverlaysID=function(a) 
            { 
                 if (a.icon) 
                 { 
                   a = new Array(a); 
                 } 
                 var b=this; 
                 for (i=0;i< a.length;i++) 
                 { 
                    try 
                    { 
                        this.overlays.push(a[i]); 
                        a[i].initialize(this); 
                        a[i].redraw(true); 
                        // if an id is set apply it 
                        if (a[i].id) 
                        { 
                                //Set this.overlays['id'] = a[i]; 
                                this.overlays[this.overlays[i].id] = a[i]; 
                        } 
                        //If a group is set apply it 
                        if (a[i].group) 
                        { 
                                // create the special groups array if it does not exist 
                                if (!this.overlays['groups']) 
                                { 
                                        this.overlays['groups'] = [ ]; 
                                        this.overlays['groups'] = [ ]; 
                                } 
                                // if the group doesn't exist create it and add it to a special groups array 
                                if (!this.overlays[a[i].group]) 
                                { 
                                        this.overlays[a[i].group] = [ ]; 
                                        this.overlays['groups'].push (a[i].group); 
                                } 
                                //Finally add the marker to the array as both an index (0,1,2,3) and as an associative array ('id1', 'id2') 
                                this.overlays[a[i].group].push(a[i]); 
                                this.overlays[a[i].group][a[i].id] = a[i]; 
                        } 
                      } 
                      catch(ex) 
                      { 
                        //alert('err: ' + i + ', ' + ex.toString()); 
                      } 
                    } 
                  this.reOrderOverlays(); 

               }; 

               GMap.prototype.clearOverlaysID=function() 
               { 
                    this.closeInfoWindow(); 
                   for (var a = 0; a < this.overlays.length; a++) 
                   { 
                       this.overlays[a].remove(); 
                   } 
                   // 
                   this.overlays = [ ]; 
                   this.saveMapState(); 
                   this.mapBlowupZoom = 1; 
                   this.mapBlowupSpec = null; 
                   GEvent.trigger(this, "clearoverlays"); 
               }; 

               GMap.prototype.removeOverlayID=function(a) 
               { 
                    var b = []; 
                   for (var c = 0; c < this.overlays.length; c++) 
                   { 
                       if (this.overlays[c] == a) { 
                        // before we remove this we need to delete the associative parts of the array 
                        if (this.overlays[c].id) 
                        { 
                                delete  this.overlays[this.overlays[c].id]; 
                        } 
                        if (this.overlays[c].group) 
                        { 
                                if (this.overlays[this.overlays[c].group].length == 0) 
                                { 
                                        delete this.overlays[this.overlays[c].group]; 
                                        for (var x =0;x < this.overlays['groups'].length; x++) 
                                        { 
                                                if (this.overlays['groups'][x] == this.overlays[c].group) 
                                                { 
                                                        this.overlays['groups'].splice(x, 1); 
                                                } 
                                        } 
                                } 
                        } 
                        a.remove(); 
                       } else { 
                        b.push(this.overlays[c]); 
                       } 
                   } 
                   if (this.overlays.length != b.length) { 
                    this.overlays = b; 
                } 
                GEvent.trigger(this, "removeoverlay", a); 
            }; 
