
/**
 * Implementacion del control de check para mostrar las calles o no.
 * 
 * See: http://code.google.com/apis/maps/documentation/controls.html#Custom_Controls
 */
 
/**
 * Creo la funcion constructor para el control.
 */
PorArriba.CheckCallesControl = function() {}

/**
 * Creo el prototipo. Lo heredo de GControl.
 */
PorArriba.CheckCallesControl.prototype = new GControl();

/**
 * Variable que indica si se estan mostrando las calles o no
 */
PorArriba.CheckCallesControl.prototype.showCalles = false;

/**
 * Funcion de inicializacion.
 * Crea el componente en su estado inicial y asigna eventos de click.
 */
PorArriba.CheckCallesControl.prototype.initialize = function(map) {
	var container = document.createElement("div");

	var tableContainer = document.createElement("table");
	tableContainer.setAttribute("id", "tableCheckCallesControl");
	tableContainer.setAttribute("border", "0");
	tableContainer.setAttribute("cellpadding", "0");
	tableContainer.setAttribute("cellspacing", "0");
	tableContainer.setAttribute("background", "files/pacontrol/checkno.png");
	tableContainer.setAttribute("width", "122");
	tableContainer.setAttribute("height", "27");
	
	var tbody = document.createElement("tbody");
		
	var tableTR = document.createElement("tr");
	var tableTD = document.createElement("td");
	tableTD.setAttribute("id", "tdCheckCallesControl");
	tableTD.style.paddingLeft = "35px";
	tableTD.style.fontFamily = "Verdana,Arial";
	tableTD.style.fontWeight = "bold";
	tableTD.style.fontSize = "10px";
	
	var txt = document.createTextNode("VER CALLES");

	tableTD.appendChild(txt);
	tableTR.appendChild(tableTD);
	tbody.appendChild(tableTR);
	tableContainer.appendChild(tbody);
	
	container.appendChild(tableContainer);

	GEvent.addDomListener(tableContainer, "click", this.clickHandle);
	
	this.setButtonStyle(container);

	map.getContainer().appendChild(container);
	return container;
}

/**
 * Maneja el evento click
 */
PorArriba.CheckCallesControl.prototype.clickHandle = function() {
	this.showCalles = !this.showCalles;
	var table = document.getElementById("tableCheckCallesControl");

	if (this.showCalles) {
		layoutControl.mostrarCalles();
		table.setAttribute("background", "files/pacontrol/checkok.png");
	} else {
		layoutControl.ocultarCalles();
		table.setAttribute("background", "files/pacontrol/checkno.png");
	}
}

/**
 * Regresa la posicion por defecto del control
 */
PorArriba.CheckCallesControl.prototype.getDefaultPosition = function() {
 	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 10));
}

/**
 * Coloca las propiedades de estilo CSS
 */
PorArriba.CheckCallesControl.prototype.setButtonStyle = function(button) {
	button.style.cursor = "pointer";
}

fileLoaded("CheckCallesControl.js");
