/* software_license
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
# 
# Creado por Fco. Javier Pérez Pacheco
# javielinux@gmail.com
# http://www.javielinux.com/
*/

function GButtons(pos, sep, type) {
	this.container = document.createElement("div");
	this.textDecoration = "none";
	this.color = "#000000";
	this.backgroundColor = "#ffffff";
	this.font = "Arial";
	this.size = "12px";
	this.border = "1px solid black";
	this.padding = "2px";
	this.margin = "3px";
	this.textAlign = "center";
	this.width = "6em";
	this.cursor = "pointer";
	
	this.position = pos;
	this.separate = sep;
	this.type = type;
}

GButtons.prototype = new GControl();

GButtons.prototype.setTextDecoration = function(t) { this.textDecoration = t; }
GButtons.prototype.setColor = function(t) { this.color = t; }
GButtons.prototype.setBackgroundColor = function(t) { this.backgroundColor = t; }
GButtons.prototype.setFont = function(t) { this.font = t; }
GButtons.prototype.setSize = function(t) { this.size = t; }
GButtons.prototype.setBorder = function(t) { this.border = t; }
GButtons.prototype.setPadding = function(t) { this.padding = t; }
GButtons.prototype.setMargin = function(t) { this.margin = t; }
GButtons.prototype.setTextAlign = function(t) { this.textAlign = t; }
GButtons.prototype.setWidth = function(t) { this.width = t; }
GButtons.prototype.setCursor = function(t) { this.cursor = t; }

GButtons.prototype.initialize = function(map) {

	map.getContainer().appendChild(this.container);
	return this.container;

}

GButtons.prototype.addButton = function(txt, funct) {

	var buttonDiv;
	if (this.type=="horizontal") {
		buttonDiv = document.createElement("span");
	} else {
		buttonDiv = document.createElement("div");
	}
	this.setButtonStyle(buttonDiv);
	this.container.appendChild(buttonDiv);
	buttonDiv.appendChild(document.createTextNode(txt));
	GEvent.addDomListener(buttonDiv, "click", function() {
		eval(funct);
	});

}

GButtons.prototype.addImageButton = function(src, funct) {

	var buttonDiv;
	if (this.type=="horizontal") {
		buttonDiv = document.createElement("span");
	} else {
		buttonDiv = document.createElement("div");
	}

	var buttonImg = document.createElement("img");
	buttonImg.setAttribute('src',src);
	buttonImg.style.cursor = this.cursor;
	
	buttonDiv.appendChild(buttonImg);
	
	this.container.appendChild(buttonDiv);
	GEvent.addDomListener(buttonDiv, "click", function() {
		eval(funct);
	});

}

GButtons.prototype.getDefaultPosition = function() {
	return new GControlPosition(this.position, new GSize(this.separate, this.separate));
}


GButtons.prototype.setButtonStyle = function(button) {
	button.style.textDecoration = this.textDecoration;
	button.style.color = this.color;
	button.style.backgroundColor = this.backgroundColor;
	button.style.fontFamily = this.font;
	button.style.fontSize = this.size;
	button.style.border = this.border;
	button.style.padding = this.padding;
	button.style.margin = this.margin;
	button.style.textAlign = this.textAlign;
	button.style.width = this.width;
	button.style.cursor = this.cursor;
}