  var imagesPrefix = '/style/felicity/carto/controls/';
  
  // Creates pan buttons on the map for zoom in/out, center, left, right, up, & down .
  function MapControl() { }
  MapControl.prototype = new GControl();
  
  // Creates a one DIV for each of the buttons and places them in a container
  // DIV which is returned as our control element. We add the control to
  // to the map container and return the element for the map class to
  // position properly.
  MapControl.prototype.initialize = function(map) {
  	var container = document.createElement("div");
  	
  	var padding=10;
  	var size_of_direction_label = 25;
  	var width = map.getSize().width;
  	var middle_w = 0;
  	if (width > 0) middle_w = width/2 - size_of_direction_label;
  
  	var height = map.getSize().height;
  	var middle_height = 0;
  	if (height > 0) middle_height = height/2;
  	
  	var map_control_div = document.createElement("div");
  	map_control_div.id = "map-control";
  	this.setButtonStyle(map_control_div, 0, 0);
  	container.appendChild(map_control_div);
  	map_control_div.style.display = 'none';
  	
  	var pan_right_div = document.createElement("div");
  	pan_right_div.id="pan-right";
  	this.setButtonStyle(pan_right_div, middle_height-13-padding, width-28-padding);
  	map_control_div.appendChild(pan_right_div);
  	var img_right = document.createElement('img');
  	img_right.src = imagesPrefix + "pan_right.gif";
  	//img_right.src = imagesPrefix + "pan_right_black.gif";
  	pan_right_div.appendChild(img_right);
  	GEvent.addDomListener(pan_right_div, "click", function() { map.panDirection(-1,0);get_places_around(); });
  	
  	var pan_left_div = document.createElement("div");
  	pan_left_div.id="pan-left";
  	this.setButtonStyle(pan_left_div, middle_height - 13-padding, -padding);
  	map_control_div.appendChild(pan_left_div);
  	var img_left = document.createElement('img');
  	img_left.src = imagesPrefix + "pan_left.gif";
  	//img_left.src = imagesPrefix + "pan_left_black.gif";
  	pan_left_div.appendChild(img_left);
  	GEvent.addDomListener(pan_left_div, "click", function() { map.panDirection(1,0);get_places_around(); });
  	
  	var pan_up_div = document.createElement("div");
  	pan_up_div.id="pan-up";
  	this.setButtonStyle(pan_up_div, -padding, middle_w+13-padding );
  	map_control_div.appendChild(pan_up_div);
  	var img_up = document.createElement('img');
  	img_up.src = imagesPrefix + "pan_up.gif";
  	//img_up.src = imagesPrefix + "pan_up_black.gif";
  	pan_up_div.appendChild(img_up);
  	GEvent.addDomListener(pan_up_div, "click", function() { map.panDirection(0,1);get_places_around(); });
  	
  	var pan_down_div = document.createElement("div");
  	pan_down_div.id="pan-down";
  	this.setButtonStyle(pan_down_div, height - 27-padding, middle_w+13-padding);
  	map_control_div.appendChild(pan_down_div);
  	var img_down = document.createElement('img');
  	img_down.src = imagesPrefix + "pan_down.gif";
  	//img_down.src = imagesPrefix + "pan_down_black.gif";
  	pan_down_div.appendChild(img_down);
  	GEvent.addDomListener(pan_down_div, "click", function() { map.panDirection(0,-1);get_places_around(); });
  	
  	
  	
  	var zoom_div = document.createElement("div");
  	this.setButtonStyle(zoom_div, 5, width-54-10);
  	map_control_div.appendChild(zoom_div);
  	zoom_div.style.background = "url("+imagesPrefix + "controls_view.gif) top left no-repeat";
  	zoom_div.id = "map-zoom";
  	zoom_div.style.width = "55px";
  	zoom_div.style.height = "88px"; 
  	
  	var img_zoomin = document.createElement('img');
  	img_zoomin.src = imagesPrefix + "zoomin.gif";
  	this.setButtonStyle(img_zoomin, 63, 7);
  	zoom_div.appendChild(img_zoomin);
  	GEvent.addDomListener(img_zoomin, "click", function() { setZoom('+') });
  	
	var img_zoomout = document.createElement('img');
  	img_zoomout.src = imagesPrefix + "zoomout.gif";
  	this.setButtonStyle(img_zoomout, 22, 7);  	
  	zoom_div.appendChild(img_zoomout);
  	GEvent.addDomListener(img_zoomout, "click", function() { setZoom('-') });
  	


  	  	
  	map.getContainer().appendChild(container);
  	return container;
  }
 
  MapControl.prototype.addIconSwitch = function(div, name) {
  	var img = document.createElement('img');
  	img.src = "/style/felicity/carto/typed_avatars/profile_type/map_profile_"+name+"_cluster.png";
  	//this.setButtonStyle(img, 63, 7);
  	div.appendChild(img);
  	GEvent.addDomListener(img, "click", function() { alert(name) });
  }	
    
  MapControl.prototype.getDefaultPosition = function() {
  	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
  }
  
  // Sets the proper CSS for the given button element.
  MapControl.prototype.setButtonStyle = function(button, top_pos, left_pos) {
  	button.style.top = top_pos + "px";
  	button.style.left = left_pos + "px";
  	button.style.position = "absolute";
  	button.style.cursor = "pointer";
  }	
	




 function MapWait(map) {		
  	var container = document.createElement("div");
  	var size_of_direction_label = 25;
  	var width = map.getSize().width;
  	var middle_w = 0;
  	if (width > 0) middle_w = width/2 - size_of_direction_label;
  
  	var height = map.getSize().height;
  	var middle_height = 0;
  	if (height > 0) middle_height = height/2;
  	
   	var wait_div = document.createElement("div");
	wait_div.id = "map-wait";   	
   	/*wait_div.style.top = middle_height-60 + "px";
  	wait_div.style.left = "0px";
  	wait_div.style.width=width+"px";
  	wait_div.style.height="120px";
  	*/
  	wait_div.style.left = "0px";
  	wait_div.style.width=width+"px";
  	wait_div.style.height="28px";	
  	wait_div.style.top =  "0px";
  	container.appendChild(wait_div);
  	map.getContainer().appendChild(container);
  	return container;
  }
  










	
	function setZoom(value){
		if(value == "+"){
			if(gmap.getZoom()>=maxZoomLevel) return;
			gmap.clearOverlays();		
			gmap.zoomIn();
		}else if(value == "-"){
			if(gmap.getZoom()<=minZoomLevel) return;
			gmap.clearOverlays();
			gmap.zoomOut();
		}else{}
	}
	
	function setMapType(value){
		gmap.setMapType(value);
		/*mapType=document.getElementById(value);
		mapType.className ='active';*/
	}

	function pan(value){
		if(value=="right")gmap.panDirection(-1,0);
		if(value=="left")gmap.panDirection(1,0);
		if(value=="up")gmap.panDirection(0,1);
		if(value=="down")gmap.panDirection(0,-1);
	}

	function isMapType(value){
		return gmap.getCurrentMapType()==value;
	}

