/*
 * FancyMapControl defines the zooming and panning buttons shown in the top left corner
 * of the map.
 */

function FancyMapControl() {}

FancyMapControl.prototype = new GControl();

FancyMapControl.prototype.initialize = function(map) {
	var me = this;
	var container = document.createElement("DIV");
	
	this.CreateArrows(container,map);
	this.CreateZoom(container,map);
	
	map.getContainer().appendChild(container);
	return container;
}

/*
 * Sets up the functions to change the button's color when the mouse moves over it.
 */
FancyMapControl.prototype.SetHighlight = function(obj) {
	GEvent.addDomListener(obj,"mouseover",function() {obj.style.backgroundPosition = "bottom";});
	GEvent.addDomListener(obj,"mouseout",function() {obj.style.backgroundPosition = "top";});
}

/*
 * Sets up the panning buttons.
 */
FancyMapControl.prototype.CreateArrows = function(container,map) {
	var up = document.createElement("DIV");
	up.className = "up_arrow";
	container.appendChild(up);
	GEvent.addDomListener(up,"click",function() {map.panBy(new GSize(0,Math.floor(map.getContainer().offsetHeight*0.5)));});
	this.SetHighlight(up);
	
	var down = document.createElement("DIV");
	down.className = "down_arrow";
	container.appendChild(down);
	GEvent.addDomListener(down,"click",function() {map.panBy(new GSize(0,-Math.floor(map.getContainer().offsetWidth*0.5)));});
	this.SetHighlight(down);
	
	var left = document.createElement("DIV");
	left.className = "left_arrow";
	container.appendChild(left);
	GEvent.addDomListener(left,"click",function() {map.panBy(new GSize(Math.floor(map.getContainer().offsetWidth*0.5),0));});
	this.SetHighlight(left);
	
	var right = document.createElement("DIV");
	right.className = "right_arrow";
	container.appendChild(right);
	GEvent.addDomListener(right,"click",function() {map.panBy(new GSize(-Math.floor(map.getContainer().offsetWidth*0.5),0));});
	this.SetHighlight(right);
}

/*
 * Sets up the zooming buttons.
 */
FancyMapControl.prototype.CreateZoom = function(container,map) {
	var plus = document.createElement("DIV");
	plus.className = "plus_control";
	container.appendChild(plus);
	GEvent.addDomListener(plus,"click",function() {map.zoomIn();});
	this.SetHighlight(plus);
	
	var minus = document.createElement("DIV");
	minus.className = "minus_control";
	container.appendChild(minus);
	GEvent.addDomListener(minus,"click",function() {map.zoomOut();});
	this.SetHighlight(minus);
}

/*
 * Positions the map control in the top left corner.
 */
FancyMapControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}
