function FancyMapButtons(style) {
	if(style != null) this.style = style;
}

FancyMapButtons.prototype = new GControl();
FancyMapButtons.prototype.style = G_SATELLITE_MAP;

FancyMapButtons.prototype.SetMapType = function(type,div) {
	map.setMapType(type);
	var allButtons = div.parentNode.childNodes;
	for (var i = 1, len = allButtons.length-1; i < len; i += 2)
		this.setButtonStyle_(allButtons[i]);
	this.setButtonStyleOn_(div);
}

/*
 * 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.
 */
FancyMapButtons.prototype.initialize = function(map) {
	var me = this;
	var container = document.createElement("div");
	
	container.appendChild(this.side("left"));
	
	var mapButtonDiv = document.createElement("div");
	if(this.style == G_NORMAL_MAP) this.setButtonStyleOn_(mapButtonDiv);
	else this.setButtonStyle_(mapButtonDiv);
	mapButtonDiv.setAttribute('id','mapButton');
	container.appendChild(mapButtonDiv);
	mapButtonDiv.appendChild(document.createTextNode("Map"));
	GEvent.addDomListener(mapButtonDiv, "click", function() { me.SetMapType(G_NORMAL_MAP,mapButtonDiv); });
	
	container.appendChild(this.spacer());
	
	var satelliteButtonDiv = document.createElement("div");
	if(this.style == G_SATELLITE_MAP) this.setButtonStyleOn_(satelliteButtonDiv);
	else this.setButtonStyle_(satelliteButtonDiv);
	satelliteButtonDiv.setAttribute('id','satelliteButton');
	container.appendChild(satelliteButtonDiv);
	satelliteButtonDiv.appendChild(document.createTextNode("Satellite"));
	GEvent.addDomListener(satelliteButtonDiv, "click", function() { me.SetMapType(G_SATELLITE_MAP,satelliteButtonDiv); });
	
	container.appendChild(this.spacer());
		
	var hybridButtonDiv = document.createElement("div");
	if(this.style == G_HYBRID_MAP) this.setButtonStyleOn_(hybridButtonDiv);
	else this.setButtonStyle_(hybridButtonDiv);
	hybridButtonDiv.setAttribute('id','hybridButton');
	container.appendChild(hybridButtonDiv);
	hybridButtonDiv.appendChild(document.createTextNode("Hybrid"));
	GEvent.addDomListener(hybridButtonDiv, "click", function() { me.SetMapType(G_HYBRID_MAP,hybridButtonDiv); });
	
	container.appendChild(this.spacer());
	
	var TerrainButtonDiv = document.createElement("div");
	if(this.style == G_PHYSICAL_MAP) this.setButtonStyleOn_(TerrainButtonDiv);
	else this.setButtonStyle_(TerrainButtonDiv);
	TerrainButtonDiv.setAttribute('id','terrainButton');
	container.appendChild(TerrainButtonDiv);
	TerrainButtonDiv.appendChild(document.createTextNode("Terrain"));
	GEvent.addDomListener(TerrainButtonDiv, "click", function() { me.SetMapType(G_PHYSICAL_MAP,TerrainButtonDiv); });
	
	container.appendChild(this.side("right"));
	
	map.getContainer().appendChild(container);
	return container;
}

FancyMapButtons.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

/*
 * Sets the proper CSS for the given button element.
 */
FancyMapButtons.prototype.setButtonStyle_ = function(button) {
	button.className = "mapbutton_black mapbutton_default";
}

FancyMapButtons.prototype.setButtonStyleOn_ = function(button) {
	button.className = "mapbutton_black mapbutton_black_on";
}

/*
 * Creates the rounded edge on the side.
 */
FancyMapButtons.prototype.side = function(css) {
	var side = document.createElement("DIV");
	side.className = "mapbutton_side mapbutton_"+css;
	return side;
}

/*
 * Creates the spacer between the buttons.
 */
FancyMapButtons.prototype.spacer = function() {
	var spacer = document.createElement("DIV");
	spacer.className = "mapbutton_spacer";
	return spacer;
}
