
// defino variables globales
var markers = new Array();
var map, points;

function Ciudad( latitud2,longitud2, nombre2 ) {
	this.latitud = latitud2;
	this.longitud = longitud2;
	this.nombre = nombre2;
}

function ocultarMarcas(){
	map.clearOverlays();
	map.addOverlay( new GPolyline( points, '#FF0000', 2 ) );
}

function mostrarMarcas(){
	ocultarMarcas();
	for( var i=0; i<markers.length; i++ ){
		map.addOverlay(markers[i]);
	}
}

function createMarker(point, ciudad) {
 	var marker = new GMarker(point, iconito);
 	var html = "<b>" + ciudad + "</b>";
 	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

function zoom() {
	i = document.getElementById( 'selectCiudadGoogle' ).value;
	if( i == 'tlaxcala' ) {
		map.setCenter(new GLatLng(19.4165, -98.1745), 9);
	} else {
		map.setCenter(new GLatLng(ciudades[i].longitud, ciudades[i].latitud), 13);	
		markers[i].openInfoWindowHtml( "<b>" + ciudades[i].nombre + "</b>" );
	}
}

points = new Array();

points[points.length] = new GPoint( -98.6848,19.5123 );
points[points.length] = new GPoint( -98.6542,19.5602 );
points[points.length] = new GPoint( -98.5407,19.6065 );
points[points.length] = new GPoint( -98.3595,19.5818 );
points[points.length] = new GPoint( -98.3112,19.6960 );
points[points.length] = new GPoint( -98.2500,19.6867 );
points[points.length] = new GPoint( -98.2138,19.6497 );
points[points.length] = new GPoint( -98.0761,19.6543 );
points[points.length] = new GPoint( -98.0503,19.6929 );
points[points.length] = new GPoint( -98.0262,19.6250 );
points[points.length] = new GPoint( -97.9328,19.5694 );
points[points.length] = new GPoint( -97.9014,19.5725 );
points[points.length] = new GPoint( -97.8563,19.5401 );
points[points.length] = new GPoint( -97.8756,19.4815 );
points[points.length] = new GPoint( -97.7870,19.4660 );
points[points.length] = new GPoint( -97.6188,19.3441 );
points[points.length] = new GPoint( -97.6075,19.3117 );
points[points.length] = new GPoint( -97.6671,19.2778 );
points[points.length] = new GPoint( -97.8225,19.2701 );
points[points.length] = new GPoint( -97.8305,19.1991 );
points[points.length] = new GPoint( -97.8933,19.1466 );
points[points.length] = new GPoint( -98.0052,19.2099 );
points[points.length] = new GPoint( -98.1461,19.0787 );
points[points.length] = new GPoint( -98.3112,19.1404 );
points[points.length] = new GPoint( -98.5455,19.4105 );
points[points.length] = new GPoint( -98.6236,19.4321 );
points[points.length] = new GPoint( -98.6848,19.5123 );


var ciudades = new Array();

ciudades[ciudades.length] = new Ciudad( -98.1666, 19.35, 'Amaxac de Guerrero' );
ciudades[ciudades.length] = new Ciudad( -98.20, 19.3333, 'Apetatitlan' );
ciudades[ciudades.length] = new Ciudad( -98.20, 19.5333, 'Atlangatepec' );
ciudades[ciudades.length] = new Ciudad( -97.80, 19.4333, 'Altzayanca' );
ciudades[ciudades.length] = new Ciudad( -98.1333, 19.4166, 'Apizaco' );
ciudades[ciudades.length] = new Ciudad( -98.5666, 19.5833, 'Calpulalpan' );
ciudades[ciudades.length] = new Ciudad( -97.65, 19.3166, 'El Carmen Tequexquitla' );
ciudades[ciudades.length] = new Ciudad( -97.7666, 19.30, 'Cuapiaxtla' );
ciudades[ciudades.length] = new Ciudad( -98.10, 19.35, 'Cuaxomulco' );
ciudades[ciudades.length] = new Ciudad( -98.20, 19.3167, 'Chiautempan' );
ciudades[ciudades.length] = new Ciudad( -98.20, 19.4666, 'Muñoz de Domingo Arenas' );
ciudades[ciudades.length] = new Ciudad( -98.4166, 19.35, 'Españita' );
ciudades[ciudades.length] = new Ciudad( -97.9166, 19.3166, 'Huamantla' );
ciudades[ciudades.length] = new Ciudad( -98.35, 19.4666, 'Hueyotlipan' );
ciudades[ciudades.length] = new Ciudad( -98.3833, 19.3333, 'Ixtacuixtla de  Mariano Matamoros' );
ciudades[ciudades.length] = new Ciudad( -97.8833, 19.25, 'Ixtenco' );
ciudades[ciudades.length] = new Ciudad( -98.1833, 19.1833, 'Mazatecochco de José María Morelos' );
ciudades[ciudades.length] = new Ciudad( -98.1667, 19.3333, 'Contla de Juan Cuamatzi' );
ciudades[ciudades.length] = new Ciudad( -98.3667, 19.2667, 'Tepetitla de Lardizábal' );
ciudades[ciudades.length] = new Ciudad( -98.4667, 19.4833, 'Sanctórum de Lázaro Cárdenas' );
ciudades[ciudades.length] = new Ciudad( -98.5333, 19.4833, 'Nanacamilpa de Mariano Arista' );
ciudades[ciudades.length] = new Ciudad( -98.2, 19.2167, 'Acuamanala de Miguel Hidalgo' );
ciudades[ciudades.length] = new Ciudad( -98.3167, 19.2333, 'Nativitas' );
ciudades[ciudades.length] = new Ciudad( -98.2667, 19.3167, 'Panotla' );
ciudades[ciudades.length] = new Ciudad( -98.1667, 19.1167, 'San Pablo del Monte' );
ciudades[ciudades.length] = new Ciudad( -98.15, 19.35, 'Santa Cruz Tlaxcala' );
ciudades[ciudades.length] = new Ciudad( -98.2, 19.15, 'Tenancingo' );
ciudades[ciudades.length] = new Ciudad( -98.1833, 19.2333, 'Teolocholco' );
ciudades[ciudades.length] = new Ciudad( -98.2333, 19.25, 'Tepeyanco' );
ciudades[ciudades.length] = new Ciudad( -97.9167, 19.4667, 'Terrenate' );
ciudades[ciudades.length] = new Ciudad( -98.1, 19.4333, 'Tetla de la Solidaridad' );
ciudades[ciudades.length] = new Ciudad( -98.3, 19.2333, 'Tetlatlahuca' );
ciudades[ciudades.length] = new Ciudad( -98.2333, 19.3, 'Tlaxcala' );
ciudades[ciudades.length] = new Ciudad( -98.1167, 19.6167, 'Tlaxco' );
ciudades[ciudades.length] = new Ciudad( -98.0333, 19.3833, 'Tocatlán' );
ciudades[ciudades.length] = new Ciudad( -98.25, 19.3333, 'Totolac' );
ciudades[ciudades.length] = new Ciudad( -97.9, 19.2, 'Zitlaltepec de Trinidad Sánchez Santos' );
ciudades[ciudades.length] = new Ciudad( -98.0833, 19.3667, 'Tzompantepec' );
ciudades[ciudades.length] = new Ciudad( -98.05, 19.4, 'Xaloztoc' );
ciudades[ciudades.length] = new Ciudad( -98.2, 19.4167, 'Xaltocan' );
ciudades[ciudades.length] = new Ciudad( -98.2, 19.1167, 'Papalotla de Xicohténcatl' );
ciudades[ciudades.length] = new Ciudad( -98.1833, 19.4, 'Xicohtzinco' );
ciudades[ciudades.length] = new Ciudad( -98.2333, 19.2167, 'Zacatelco' );
ciudades[ciudades.length] = new Ciudad( -98.4333, 19.5833, 'Benito Juárez' );
ciudades[ciudades.length] = new Ciudad( -97.9167, 19.5667, 'Emiliano Zapata' );
ciudades[ciudades.length] = new Ciudad( -97.9833, 19.5333, 'Lázaro Cárdenas' );
ciudades[ciudades.length] = new Ciudad( -98.2, 19.2833, 'La Magdalena Tlaltelulco' );
ciudades[ciudades.length] = new Ciudad( -98.2833, 19.2833, 'San Damián Texoloc' );
ciudades[ciudades.length] = new Ciudad( -98.1667, 19.2667, 'San Francisco Tetlanohcan' );
ciudades[ciudades.length] = new Ciudad( -98.2667, 19.2333, 'San Jerónimo Zacualpan' );
ciudades[ciudades.length] = new Ciudad( -98.0667, 19.3333, 'San José Teacalco' );
ciudades[ciudades.length] = new Ciudad( -98.25, 19.2333, 'San Juan Huactzinco' );
ciudades[ciudades.length] = new Ciudad( -98.25, 19.2333, 'San Lorenzo Axocomanitla' );
ciudades[ciudades.length] = new Ciudad( -98.25, 19.4833, 'San Lucas Tecopilco' );
ciudades[ciudades.length] = new Ciudad( -98.3333, 19.3, 'Santa Ana Nopalucan' );
ciudades[ciudades.length] = new Ciudad( -98.3167, 19.2333, 'Santa Apolonia Teacalco' );
ciudades[ciudades.length] = new Ciudad( -98.2167, 19.2, 'Santa Catarina Ayometla' );
ciudades[ciudades.length] = new Ciudad( -98.2167, 19.2167, 'Santa Cruz Quilehtla' );
ciudades[ciudades.length] = new Ciudad( -98.2167, 19.2667, 'Santa Isabel Xiloxoxtla' );
// Montes
ciudades[ciudades.length] = new Ciudad( -98.0333, 19.2333, 'La Malinche' );
ciudades[ciudades.length] = new Ciudad( -98.6667, 19.4833, 'Cerro el Huilotepec' );
ciudades[ciudades.length] = new Ciudad( -98.0500, 19.6333, 'Cerro Huilapitzo' );
ciudades[ciudades.length] = new Ciudad( -97.7833, 19.4667, 'Cerro San Gabriel' );
ciudades[ciudades.length] = new Ciudad( -98.1167, 19.6500, 'Cerro Huintetépetl' );
ciudades[ciudades.length] = new Ciudad( -97.9333, 19.5167, 'Cerro Tlacoxolo' );
ciudades[ciudades.length] = new Ciudad( -98.4167, 19.5333, 'Cerro San Nicolás' );
ciudades[ciudades.length] = new Ciudad( -98.0833, 19.3333, 'Cerro Cuatlapanga' );
ciudades[ciudades.length] = new Ciudad( -98.3000, 19.6333, 'Cerro Soltepec' );

// Creo el mapa	
window.onunload=GUnload;

var iconito = new GIcon();
iconito.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
iconito.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
iconito.iconSize = new GSize(12, 20);
iconito.shadowSize = new GSize(22, 20);
iconito.iconAnchor = new GPoint(6, 20);
iconito.infoWindowAnchor = new GPoint(5, 1);

window.onload = function(){
	if( !/^http:\/\/tlaxcala\.tlax\.com\//.test( window.location ) && !/^http:\/\/www\.tlaxcala\.tlax\.com\//.test( window.location ) ){
		alert( 'Visita http://www.tlaxcala.tlax.com' );
	}
	// me salgo si no es compatible
 	if( !GBrowserIsCompatible() ) {
		alet( 'Tu navegador no es compatible, trata con Firefox, Safari o IE' );
		return;
	}

	map = new GMap2(document.getElementById("map") );
	//hago zoom a el estado de tlaxcala
	map.setCenter(new GLatLng(19.4165, -98.1745), 9, G_HYBRID_MAP) ;
	// establezco el tipo a satelite
	//map.setMapType( G_HYBRID_MAP );
	// agrego el tipo de mapa earth
	map.addMapType(G_PHYSICAL_MAP);
	map.addMapType(G_SATELLITE_3D_MAP);
	// agrego el control zoom
	//map.addControl(new GSmallMapControl());
	map.addControl(new GLargeMapControl()); 
	//agrego el control tipo
	map.addControl(new GMapTypeControl());	
	
	var htmlCode='<select id="selectCiudadGoogle" selected="selected"><option value="tlaxcala">Todo el Estado</option>';
	for( var i=0; i<ciudades.length; i++ ){
		htmlCode += '<option value="' + i + '">' +ciudades[i].nombre + '</option>  ';
		var point = new GLatLng( ciudades[i].longitud, ciudades[i].latitud );
		markers[i] = createMarker(point, ciudades[i].nombre);
	  	//var marker = new GMarker(point);
		map.addOverlay(markers[i]);
	}
	htmlCode+='</select><input type="button" value="Acercar" onclick="zoom();return false;" />';

	document.getElementById( 'zoomCode' ).innerHTML = htmlCode;
	
	map.addOverlay( new GPolyline( points, '#FF0000', 2 ) );
}

