	var map;
    
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"),{
                 mapTypes : [G_SATELLITE_MAP,G_NORMAL_MAP]
              });
        map.addControl(new GLargeMapControl());
    	map.addControl(new GMapTypeControl());
		//map.enableScrollWheelZoom();
    	
    	var copyright = new GCopyright(1,new GLatLngBounds(new GLatLng(37.56199695314352,-110.56640625), new GLatLng(27.89734922968426,-97.22900390625)), 0, "Lowes");
    	var copyrightCollection = new GCopyrightCollection('Lowe\'s');
		copyrightCollection.addCopyright(copyright);
		
		var tilelayers = [new GTileLayer(copyrightCollection ,6, 9)];
		tilelayers[0].getTileUrl = CustomGetTileUrl;
		
		var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Lowe's", {errorMessage:"No chart data available"});
		map.addMapType(custommap);
		map.setMapType(custommap) 
        map.setCenter(new GLatLng(32.65787573695528, -103.86474609375), 6);
        
        // Add markers and polylines
		//initMapEvent( map ) ;         
        
		manager = new GMarkerManager(map);
		
		// This is a sorting trick, don't worry too much about it.
		markers.sort(function(a, b) { return (a.abbr > b.abbr) ? +1 : -1; }); 
		
		batch = [];
		for(id in markers) {
			batch.push(createMarker(markers[id]));
		}
		manager.addMarkers(batch, 2);
		manager.refresh();
		
		//refreshTime = setTimeout ( "zoomp()", 3000 );
	
      }
    }
 
	
		 
    
    function CustomGetTileUrl(a,b) {
   // alert("getting custom tiles");
      if (b==6 && a.x>=12 && a.x<=14 && a.y>=24 && a.y<= 26) {
         //return "map/Tile_"+(a.x)+"_"+(a.y)+"_"+b+".jpg";
		 return "map/"+b+"_"+(a.x)+"_"+(a.y)+".png";
		 // alert("yes");
	  } else if (b==9 && a.x>=98 && a.x<=117 && a.y>=199 && a.y<= 214){
		   return "map/"+b+"_"+(a.x)+"_"+(a.y)+".png";
	  } else if (b==8 && a.x>=49 && a.x<=58 && a.y>=99 && a.y<= 107){
		   return "map/"+b+"_"+(a.x)+"_"+(a.y)+".png";
	  } else if (b==7 && a.x>=24 && a.x<=28 && a.y>=49 && a.y<= 53){
		   return "map/"+b+"_"+(a.x)+"_"+(a.y)+".png";
      } else {
           return "map/Tile_14_24_6.jpg";
		  //return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(a,b);
      }
	}
	
	


function createMarkerClickHandler(marker, text, ID, phone) {
	return function() {
		marker.openInfoWindowHtml(
			'<h4>' + text + '<br>phone: '+phone+'</h4>' +
			'<p class="textBigger" target="_blank"><a href="index.php?store=' + ID + '">more info</a></p>'
		);
		return false;
	};
}


function createMarker(pointData) {
	var latlng = new GLatLng(pointData.latitude, pointData.longitude);
	var icon = new GIcon();
	icon.image = 'pin.png';
	icon.iconSize = new GSize(10, 10);
	icon.iconAnchor = new GPoint(10, 10);
	icon.infoWindowAnchor = new GPoint(5, 5);

	opts = {
		"icon": icon,
		"clickable": true,
		"labelOffset": new GSize(-10, -10)
	};
	var marker = new LabeledMarker(latlng, opts);
	var handler = createMarkerClickHandler(marker, pointData.name, pointData.wp, pointData.phone);
	
	GEvent.addListener(marker, "click", handler);
	
	var listItem = document.createElement('li');
	listItem.innerHTML = '<div class="label">'+pointData.abbr+'</div><a href="' + pointData.wp + '">' + pointData.name + '<br>'+ pointData.phone + '<br>Open '+ pointData.hours + '</a>';
	listItem.getElementsByTagName('a')[0].onclick = handler;

	//document.getElementById('sidebar-list').appendChild(listItem);

	return marker;
}
