﻿   
 function BusinessMap(mapid,islargemap,isoverview,isscale,ismaptype,issearch,slat,slng,slevel,iconimage,iconwidth,iconheight,officeLayer,iconData)
   {
    this.map;
    var mgr;
    var icons = {};
    var allmarkers = [];
    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.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());
        if(this.search)
        {
        this.lsc = new google.maps.LocalSearch({suppressZoomToBounds : true});
        this.map.addControl(this.lsc);
        }
        this.map.setCenter(new GLatLng(this.startlat, this.startlng), this.startlevel);
        this.map.enableDoubleClickZoom();
        mgr = new MarkerManager(this.map, {trackMarkers:true});
        window.setTimeout(this.setupOfficeMarkers, 0);
      }
    }

    function getIcon(image) {
      var icon = null;
      //alert(image);
      if (image) {
        if (icons[image]) {
          icon = 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];
                icon.iconSize = new GSize(size.width, size.height);
                icon.shadowSize = new GSize(size.width, size.height);
                icons[image] = icon;
             }
             else
             {
                 return getIcon1();
             }
         }
      }else
             {
                 return getIcon1();
             }
      return icon;
    }
    
    
    function getIcon1() {
     icon = new GIcon(G_DEFAULT_ICON);
     if(iconimage!="")
     {
        icon.image =iconimage;
        icon.shadow=iconimage;
     }
     if(iconwidth>0&&iconheight>0)
     {
        icon.iconSize = new GSize(iconwidth, iconheight);
        icon.shadowSize = new GSize(iconwidth, iconheight);
     }
      return icon;
    }

    this.setupOfficeMarkers=function () {
      allmarkers.length = 0;
      for (var i in officeLayer) {
        var layer = officeLayer[i];
        var markers = [];
        for (var j in layer["places"]) {
          var place = layer["places"][j];
          var icon = getIcon(place["icon"]);
                  
          var title = place["name"];
          var desc = place["desc"];
          var posn = new GLatLng(place["posn"][0], place["posn"][1]);
          var marker = createMarker(posn,title,desc,icon); 
          markers.push(marker);
          allmarkers.push(marker);
        }
        mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
      }
      mgr.refresh();
    }
  
    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;
    }
   }

   