   

 function BusinessMap(mapid,islargemap,isoverview,isscale,ismaptype,issearch,slat,slng,slevel,iconimage,iconwidth,iconheight,officeLayer,iconData,slider,q,moduleid,pgtemplate,pagesize,defmaptype)
   {
    this.map;
    var mgr;
    this.icons = {};
    this.lsc=null;
    
    this.mapid=mapid;
    this.largemap=islargemap;
    this.overview=isoverview;
    this.scale= isscale;
    this.maptype=ismaptype;
    this.search=issearch;
    this.startlat=slat;
    this.startlng=slng;
    this.startlevel=slevel;
    this.iconimage=iconimage;
    this.iconwidth=iconwidth;
    this.iconheight=iconheight;
    this.officeLayer=officeLayer;
    this.iconData=iconData;
    this.searchquery=q;
    var sidebar= slider;
    var me=this;
    this.moduleid=moduleid;
    this.pgtemplate=pgtemplate;
    this.pagesize=pagesize;
    this.defmaptype=defmaptype;
  
    this.load= function () {
    
      if (GBrowserIsCompatible()) {
        this.map = new GMap2(document.getElementById(mapid));
        if(this.largemap)  this.map.addControl(new GLargeMapControl());
        if(this.overview)  this.map.addControl(new GOverviewMapControl());
        if(this.scale)  this.map.addControl(new GScaleControl());
        if(this.maptype) this.map.addControl(new GMapTypeControl());
        this.map.setMapType(this.defmaptype);
        this.map.setCenter(new GLatLng(this.startlat, this.startlng), this.startlevel);
        this.map.enableDoubleClickZoom();
        mgr = new MarkerManager(this.map, {trackMarkers:true});
         if(this.search)
        {
        this.lsc = new google.maps.LocalSearch({suppressZoomToBounds : true});
        this.map.addControl(this.lsc);
        
        if(this.searchquery!=null&&this.searchquery!='')
        {
       
               this.lsc.execute(this.searchquery);
        }
     
        }
        window.setTimeout(this.setupOfficeMarkers, 0);
      }
    }

 

    this.setupOfficeMarkers=function () {
        var geocoder= null;
    
       var mp=me;
       var markers = [];
      for (var i in officeLayer) { // for i
         var layer = officeLayer[i];
       
        for (var j in layer["places"]) {//for j
          var place = layer["places"][j];
          var icon = me.getIcon(iconData,place["icon"]);
          var title = place["name"];
          var address=place["address"];
          var desc = place["desc"];
         
          if (place["posn"][0]!=""&& place["posn"][1]!=""&&place["posn"][0]!=null&& place["posn"][1]!=null)
          {
            var posn = new GLatLng(place["posn"][0], place["posn"][1]);
            var marker = createMarker(posn,title,desc,icon); 
            markers.push(marker);
          }
          else if (address!=" ")
           {//else
            geocoder= new GClientGeocoder();
           if (geocoder) { //0
                  var p = new myMakerPos(layer,place,mp,mgr,sidebar,moduleid,pgtemplate,pagesize);
                  geocoder.getLatLng(address,p.findloc); 
                  
                 }//0
              }//else
            
            }//for j
          
          
         mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
       } // for i
      mgr.refresh();
      if (sidebar!=null)
      {
          addtosidebar(sidebar,markers,moduleid);
          setPage(moduleid,pgtemplate,pagesize);
      }
       
    }
 }   
 
 BusinessMap.prototype.createMarkerByPlace=function (np,posn)
    {
          var icon = this.getIcon(this.iconData,np["icon"]);
          var title = np["name"];
          var address=np["address"];
          
          var desc = np["desc"];
          return createMarker(posn, title,desc, icon) ;
    }
 
  BusinessMap.prototype.getIcon= function (iconData,image) {
      var icon = null;
      //alert(image);
      if (image) {
        if (this.icons[image]) {
          icon = this.icons[image];
        } else {
          
          icon = new GIcon(G_DEFAULT_ICON);
          //alert(iconData["2"]);
          iconurl=iconData[image][0];
          //alert(iconurl);
          if (iconurl!="")
            {
                icon.image =iconurl;
                icon.shadow=iconurl;
                var size = iconData[image][1];
                if (size.width>0&&size.height>0)
                {
                icon.iconSize = new GSize(size.width, size.height);
                icon.shadowSize = new GSize(size.width, size.height);
                }else
                {
                   if(this.iconwidth>0&&this.iconheight>0)
                     {
                        icon.iconSize = new GSize(this.iconwidth, this.iconheight);
                        icon.shadowSize = new GSize(this.iconwidth, this.iconheight);
                        icon.iconAnchor = new GPoint(2, this.iconheight);
                     }
                }
                this.icons[image] = icon;
             }
             else
             {
                 return this.getIcon1();
             }
         }
      }else
             {
                 return this.getIcon1();
             }
      return icon;
    }
    
    
    BusinessMap.prototype.getIcon1=function () {
     icon = new GIcon(G_DEFAULT_ICON);
     if(this.iconimage!="")
     {
        icon.image =this.iconimage;
        icon.shadow=this.iconimage;
     }
     if(this.iconwidth>0&&this.iconheight>0)
     {
        icon.iconSize = new GSize(this.iconwidth, this.iconheight);
        icon.shadowSize = new GSize(this.iconwidth, this.iconheight);
        icon.iconAnchor = new GPoint(2, this.iconheight);
     }
      return icon;
    }



   function myMakerPos(layer,place,bm,markermamager,side,moduleid,pgtemplate,pagesize)
   {
   var mylayer=layer;
   var myplace=place;
   var myMap=bm;
   var mgr=markermamager;
   var sidebar=side;
   var mid=moduleid;
   var pgt=pgtemplate;
   var pgsize=pagesize;
 // alert(mid);
   this.findloc=function(point) { //1
                         
                         // nposn.push(point);
                          var nl=mylayer;//nlays[nposn.length-1];
                          var np=myplace;//nplace[nposn.length-1];
                          if(point)
                             {
                               var mk = [];
                               var m = myMap.createMarkerByPlace(np,point); 
                               mk.push(m);
                               mgr.addMarkers(mk, nl["zoom"][0], nl["zoom"][1]);
                               mgr.refresh();
                               // alert(mid);
                               if (sidebar!=null)
                                 {
                                   addtosidebar(sidebar,mk,mid);
                                   setPage(mid,pgt,pgsize);
                                 }
                             } 
                             else
                             {
                             //alert("Cannot find");
                             } 
                      }//1
                      
     }
   
   ///common
   
     function createMarker(posn, title,desc, icon) {
      var marker = new GMarker(posn, {title: title, icon: icon, draggable:false });
	  GEvent.addListener(marker, "click", function() {   marker.openInfoWindowHtml(desc);  });  

      return marker;
    }
    
     function addtosidebar(slider,mks,moduleid)
    {
   
       if (slider!=null)
       {
         
          for (var i in mks)
          {
          
          var mk=mks[i];
             //var label = createElem("sidebar-entry", mk.getTitle(), "a");
             var label = createElem("v" + moduleid+ " hidepiece", mk.getTitle(), "a");
             
             label.href = "#";
             label.style.display = "block";
             label.marker=mk;
             mk.label=label;
             label.onclick = function(){GEvent.trigger(this.marker,'click'); return false};//x-browser
             label.onfocus = function(){GEvent.trigger(this.marker,'click'); return false};
             slider.appendChild(label);
             GEvent.addListener(mk,'click',function(){this.label.focus(); return false});
             
           }
          }
    }
    
  function createElem(opt_className, opt_html, opt_tagName) 
  {

    var tag = opt_tagName||"div";
    var elem = document.createElement(tag);
    if (opt_html) elem.innerHTML = opt_html;
    if (opt_className) elem.className = opt_className;
    return elem;
  }

function setPage(moduleid,pgtemplate,pagesize){
var whatsnew=new virtualpaginate({
	piececlass: 'v' + moduleid,
piececontainer:     'a', 
	pieces_per_page: pagesize,
	defaultpage: 0,
	persist: false,
	pagetemplate:pgtemplate
})

 var dd = document.getElementById("listingpaginate" + moduleid);
 if(dd!=null) dd.style.display = "block";
whatsnew.buildpagination(["listingpaginate" + moduleid ]);
}
  
  