function initMap(options){
  var followUp = null;
  var mapOptions = {numZoomLevels: 18};
  map = new OpenLayers.Map($('map'),mapOptions);
  for(var option in options){self[option] = options[option];}
  if(name == 'India - Yahoo'){ 
    baseLayer = new OpenLayers.Layer.Yahoo("Yahoo",
        {sphericalMercator: true, maxExtent: new OpenLayers.Bounds(-20037508, -20037508,20037508, 20037508.34)}
        );
  }
  map.addLayer(baseLayer);
  trgProj = baseLayer.projection;
  map.setCenter(new OpenLayers.LonLat(lon,lat).transform(srcProj,trgProj),zoom);

  /**
   *case statements here should be replaced by lookup references
   */
 var template = {externalGraphic: "${icon}",graphicWidth:"${width}",graphicHeight:"${height}"};
  
  var cont = {
        radius: function(feature){return Math.min(feature.attributes.count, 7) + 3;},
        icon: function(feature){
           _level = Math.min(feature.attributes.count,4) - 1;
           if(_level == 0 && feature.attributes.icon){
             return "/images/"+feature.attributes.icon;
           }else{
             return "../images/cluster"+_level+".png";
           }
         },
	width: function(feature){ _level = Math.min(feature.attributes.count,4) - 1; 
          w = 32;
          switch(_level){
            case 0:
             w = 32;
              break;
            case 1:
             w =  44;
              break;
            case 2:
             w =  53;
              break;
            case 3:
             w = 76;
              break;
          }
          return w;
        },
        height:function(feature){
          _level = Math.min(feature.attributes.count,4) - 1;
          h = 29;
          switch(_level){
            case 0:
              h = 29;
              break;
            case 1:
              h = 36;
              break;
            case 2:
              h = 48;
              break;
            case 3:
              h = 60;
              break;
          }
          return h;
        }
      };

  var style = new OpenLayers.Style(template, {context: cont});
  vLayer = new OpenLayers.Layer.Vector("Mapposts",
      {
       projection: new OpenLayers.Projection("EPSG:4326"),
       styleMap: new OpenLayers.StyleMap({
         "default": style,
         "select": {
              fillColor: "#8aeeef",
              strokeColor: "#32a8a9"
          }
        }),
         strategies: [cluster]
       });

  
  map.addLayer(vLayer);
  
  for(var key in controls){
    var control = controls[key];
    map.addControl(control);
    control.activate();

  }
  selectControl = new OpenLayers.Control.SelectFeature(vLayer,{clickout:true,hover:false,onSelect:getInfo});
  map.addControl(selectControl);
  selectControl.activate();
  request(self.followUp);
  new Draggable("info");
  
}

function updateSubdomain(input_obj) {
  var value = input_obj.value.toLowerCase().gsub(/[!@#$%^&*()\s]+/, "-");
  $('subcommunity').innerHTML = 'http://' + value + '.mapunity.org';
  $('url').value = value;
}


function get(url){
  request(url);
}

function upd(url,target){
  new Ajax.Updater(target, url, {method: 'get',asynchronous:true, evalScripts:true});
}


function u(url){
  new Ajax.Request(url,{method: 'get',evalScripts:true, onSuccess: function(transport){
      $('info').innerHTML = transport.responseText;
      transport.responseText.evalScripts();
      transport.responseText.extractScripts();
      Element.show('info');}
      });
}



function request(url){
  if(!url){return;}
  new Ajax.Request(url, {method: 'get',asynchronous:true, evalScripts:true,onSuccess:function(transport){
      transport.responseText.evalScripts();
      transport.responseText.extractScripts();
      }
  });
}

function getInfo(feature){
  if(feature.attributes.count > 1){
    var fGeom = feature.geometry;
    map.setCenter(fGeom.lon,fGeom.lon);
    map.zoomTo(map.getZoom() + 1);
  }else{
    request("/info/"+feature.attributes.fid);
  }

}

function hide_user_msg() {
   setTimeout("Element.hide('user_message')",10000);
}

function closeInfo(){
  Element.hide("info");
}

function render(result){
  vLayer.destroyFeatures();
  pointList = [];

  /**
   * this rule should be applied for a newly added feature or feature being editted
   *
   */
  var point = null;
  var disp = "";
  var bounds = null;
  var pgeom = null;

  result.each(
      function(record){
        _props = {'fid': record.id,'info': record.info,'icon': record.icon,clickoutTolerance:2};
        pgeom = new OpenLayers.Geometry.Point(record.lon,record.lat);
        pgeom.transform(srcProj,trgProj);
        if(!bounds){bounds = pgeom.getBounds();}
        bounds.extend(pgeom);
        point = new OpenLayers.Feature.Vector(pgeom,_props, null);
        point.fid = record.id; //fid belongs to feature object
        pointList.push(point);
      }
  );
  vLayer.addFeatures(pointList);
  if(vLayer.features.size() < 1){
    bounds = resizeExtent(bounds);
  }
//  map.setCenter(bounds.getCenterLonLat(),map.getZoomForExtent(bounds));
    
    map.setCenter(new OpenLayers.LonLat(lon,lat),zoom);
}



/**
 * click control handler
 */
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control,{
    defaultHandlerOptions: {
      'single': true,
      'double': true,
      'pixelTolerance':0,
      'stopSingle':false,
      'stopDouble':false
    },
    initialize: function(options){
        this.handlerOptions = new OpenLayers.Util.extend({},this.defaultHandlerOptions);
        OpenLayers.Control.prototype.initialize.apply(this,arguments);
        this.handler = new OpenLayers.Handler.Click(this,{
          'click': this.onClick,
          'dblclick': this.onDblClick
          },this.handlerOptions);
    },
    onClick: function(evt){
      //do nothing
    },
    onDblClick: function(evt){
      //do nothing
    }
});

var controls = {
  "logo": new OpenLayers.Control.MapunityText(),
  "position": new OpenLayers.Control.MousePosition(),
  "click": new OpenLayers.Control.Click({handlerOptions:{'double':true,'single':true,'stopSingle':true,'stopDouble':true}})
}


var name = 'India - Mapunity';
var cluster = new OpenLayers.Strategy.Cluster();
var tile_url = ["http://tiles0.mapunity.org","http://tiles1.mapunity.org","http://tiles2.mapunity.org","http://tiles3.mapunity.org"];
var baseLayer = new OpenLayers.Layer.GTileGrid(name,tile_url);
var map = null;
var zoom = 5;
//var lat = 23.62;
//var lon = 81.7;
var lon = 74.38310546875;
var lat = 22.38953125;
var minZoom = 10;
var maxZoom = 18;
var vLayer = null;
var state = "UNKNOWN";
var trgProj = new OpenLayers.Projection("EPSG:900913");
var srcProj = new OpenLayers.Projection("EPSG:4326");
