var icons = [];
var objMap = "";
var icon_name = ["a","b","c","d","e","f","g","h","i"];

function makeGoogleMapIcon(){
	for(var i=0; i<10 ; i++){
		icons[i] = new GIcon();
		icons[i].image = "/images/local/local_list_icon_"+icon_name[i]+".gif";
		icons[i].iconSize = new GSize(15, 13);
		icons[i].iconAnchor = new GPoint(9, 13);
		icons[i].infoWindowAnchor = new GPoint(9, 2);
		icons[i].infoShadowAnchor = new GPoint(10, 15);
	}
}

	  // the icon information is passed to this function
  function createMarker(point,name,html,icontype) {
		var marker = new GMarker(point,{title:name,icon:icons[icontype]});
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowHtml(html);
		  
		});

		return marker;
  }

function setMarkIcon(){

	 objMap.setCenter(new GLatLng(midLat,midLng), mapSize);
	 objMap.clearOverlays();


	  for (var i = 0; i < Mapdata.length; i++) {
		// obtain the attribues of each marker

		if(Mapdata[i][0]=="" || Mapdata[i][1]=="" || Mapdata[i][2]=="") continue;
		if(Mapdata[i][0]==null || Mapdata[i][1]==null || Mapdata[i][2]==null) continue;

		var lat = parseFloat(Mapdata[i][0]);
		var lng =parseFloat(Mapdata[i][1]);
	
		var point = new GLatLng(lat,lng);
		var html ="<span class=\"gmap_window\">" + Mapdata[i][2] +"<BR>" + Mapdata[i][3] + "</span>";

		var label = Mapdata[i][2];
		var icontype = i;
		// create the marker

		if(point == null) continue;
		var marker = createMarker(point,label,html,icontype);

		objMap.addOverlay(marker);
	  }

}

function initialize_googleMap(mode){

	if(mode==null) mode = "list";

	if (!GBrowserIsCompatible()) {
		  alert("Sorry, the Google Maps API is not compatible with this browser");
		  return;
	}

	if(document.getElementById("google_map") != null){	

		  objMap = new GMap2(document.getElementById("google_map"));

		  if(mode=="detail"){
				objMap.addControl(new GSmallMapControl());
				icons[0] = new GIcon();
				icons[0].image = "/images/local/local_detail_store_icon.gif";
				icons[0].iconSize = new GSize(15, 13);
				icons[0].iconAnchor = new GPoint(9, 13);
				icons[0].infoWindowAnchor = new GPoint(9, 2);
				icons[0].infoShadowAnchor = new GPoint(10, 15);
		  }
		  else{
			  objMap.addControl(new GLargeMapControl());
			  makeGoogleMapIcon();
		  }
	
		  objMap.addControl(new GMapTypeControl());	
	      objMap.enableScrollWheelZoom();
		 setMarkIcon();
	}
}
