
google.load ("maps", "2"); 

///////
// GM
///////

GM.SCALE               =   1;	// Escala
GM.SMALLMAP            =   2; // Zoom y desplazamiento
GM.LARGEMAP            =   4; // Zoom desplazamiento y barra deslizante
GM.SMALLZOOM           =   8; // Solo Zoom pequeño
GM.MAPTYPE             =  16; // Tipos de mapas (Mapa, satelite e hibrido)
GM.MENUMAPTYPE         =  32; // Selector de tipo de mapa
GM.HIERARCHICALMAPTYPE =  64;
GM.OVERVIEWMAP         = 128;	// Mapa pequeño

GM.LOCALIZADOR   = '/imagenes/mapas/localizador.png';
GM.NUMERO1       = '/imagenes/mapas/n1.png';
GM.NUMERO2       = '/imagenes/mapas/n2.png';
GM.NUMERO3       = '/imagenes/mapas/n3.png';
GM.NUMERO4       = '/imagenes/mapas/n4.png';
GM.NUMERO5       = '/imagenes/mapas/n5.png';
GM.NUMERO6       = '/imagenes/mapas/n6.png';
GM.NUMERO7       = '/imagenes/mapas/n7.png';
GM.NUMERO8       = '/imagenes/mapas/n8.png';
GM.NUMERO9       = '/imagenes/mapas/n9.png';
GM.NUMERO10      = '/imagenes/mapas/n10.png';
GM.NUMERO11      = '/imagenes/mapas/n11.png';
GM.NUMERO12      = '/imagenes/mapas/n12.png';
GM.NUMERO13      = '/imagenes/mapas/n13.png';
GM.NUMERO14      = '/imagenes/mapas/n14.png';
GM.NUMERO15      = '/imagenes/mapas/n15.png';
GM.NUMERO16      = '/imagenes/mapas/n16.png';
GM.COMERCIO      = '/imagenes/mapas/comercio.png';
GM.OCIO          = '/imagenes/mapas/ocio.png';
GM.SERVICIOS     = '/imagenes/mapas/servicios.png';
GM.INTERES       = '/imagenes/mapas/puntointeres.png';
GM.CULTURA       = '/imagenes/mapas/cultura.png';
GM.DEPORTE       = '/imagenes/mapas/deporte.png';
GM.RESTAURANTE   = '/imagenes/mapas/restaurante.png';
GM.ALOJAMIENTO   = '/imagenes/mapas/hotel.png';
GM.FOTO		       = '/imagenes/mapas/foto.png';
GM.PANORAMICA    = '/imagenes/mapas/panoramica.png';

function GM () {}

/////////////
//  GMLinea
/////////////

GMLinea.prototype._aPuntos = null;
GMLinea.prototype.Color    = '#0000ff';
GMLinea.prototype.Grosor   = 5;

GMLinea.prototype.Punto = function (fLat, fLon)
{
	this._aPuntos.push (new google.maps.LatLng (fLat, fLon));
}

GMLinea.prototype.Puntos = function (sPuntos)
{
	var aPuntos = sPuntos.split (' ');
	
	for (var i = aPuntos.length -1; i >= 0; i -= 2)
		this._aPuntos.push (new google.maps.LatLng (aPuntos [i - 1], aPuntos [i]));
}

function GMLinea ()
{
	this._aPuntos = new Array ();
}


///////////
//  GMMap
///////////

GMMap._aInstancias  = new Array ();
GMMap._Inicializado = false;

GMMap.prototype.Controles      =  GM.LARGEMAP | GM.MENUMAPTYPE | GM.OVERVIEWMAP;
GMMap.prototype.Desplazamiento = true;
GMMap.prototype.Escala         = false;
GMMap.prototype.Hibrido        = false;
GMMap.prototype.Latitud        = 37.338928
GMMap.prototype.Longitud       = -5.838965
GMMap.prototype.Satelite       = false;
GMMap.prototype.Zoom           = 14;
GMMap.prototype.onSeleccionar  = null;
GMMap.prototype.onCargar       = null;

GMMap.prototype._Map   = null;


GMMap.prototype.Cargar = function ()
{
	if (GMMap._Inicializado)
	{	if (google.maps.BrowserIsCompatible ())
		{	if (! this.sId) alert ('Tiene que indicar un identificador');
			else
			{	var oId = document.getElementById (this.sId);
				if (! oId) alert ('El identificador "' + this.sId + '" no se ha encontrado');
				else
				{	var self = this;
					if (! this._Map) this._Map = new google.maps.Map2 (document.getElementById (this.sId));
					if (this.Controles & GM.SMALLZOOM) this._Map.addControl (new google.maps.SmallZoomControl ());
					if (this.Controles & GM.SCALE) this._Map.addControl (new google.maps.ScaleControl ());
					if ((this.Controles & (GM.SMALLMAP | GM.LARGEMAP)) == GM.SMALLMAP) this._Map.addControl (new google.maps.SmallMapControl ());
					if (this.Controles & GM.LARGEMAP) this._Map.addControl (new google.maps.LargeMapControl ());
					if (this.Controles & GM.MAPTYPE) this._Map.addControl (new google.maps.MapTypeControl ());
					if (this.Controles & GM.MENUMAPTYPE) this._Map.addControl (new google.maps.MenuMapTypeControl ());
					if (this.Controles & GM.HIERARCHICALMAPTYPE) this._Map.addControl (new google.maps.HierarchicalMapTypeControl ());
					if (this.Controles & GM.OVERVIEWMAP) this._Map.addControl (new google.maps.OverviewMapControl ());
					if (this.Hibrido) this._Map.setMapType  (google.maps.HYBRID_MAP);
					if (this.Satelite) this._Map.setMapType (google.maps.SATELLITE_MAP);
					this._Map.setCenter (new google.maps.LatLng (this.Latitud, this.Longitud), this.Zoom);
					if (this.onCargar) this.onCargar (this);
					if (this.onSeleccionar) google.maps.Event.addListener (this._Map, 'click', function (overlay, latlng) { if (latlng) self.onSeleccionar (self, latlng.lat (), latlng.lng ()); });
				}
			}
		}
	} else window.setTimeout ('GMMap._aInstancias ["' + this.sId + '"].Cargar ()', 100);
}


GMMap._Init = function () 
{
	GMMap._Inicializado = true;
}


GMMap.prototype.Limpiar = function ()
{
	this._Map.clearOverlays ();
}


GMMap.prototype.Linea = function (oLinea)
{
	var Linea = new google.maps.Polyline (oLinea._aPuntos, oLinea.Color, oLinea.Grosor);
	this._Map.addOverlay (Linea);
}

GMMap.prototype.Marca	= function (oMarca)
{
	var Icono     = new google.maps.Icon (google.maps.DEFAULT_ICON);
	oMarca._Marca = new google.maps.Marker (new google.maps.LatLng (oMarca.Latitud, oMarca.Longitud), { icon: Icono });

	if (oMarca.HTML) oMarca._Marca.bindInfoWindowHtml (oMarca.HTML);
	else if (oMarca._aTabs) oMarca._Marca.bindInfoWindowTabsHtml (oMarca._aTabs);
		
	Icono.image = oMarca.Icono;
	this._Map.addOverlay (oMarca._Marca);	
}

function GMMap (sId)
{
	this.sId = sId;
	GMMap._aInstancias [sId] = this;
}


////////////
// GMMarca
////////////

GMMarca.prototype._Marca = null;
GMMarca.prototype._aTabs = null;

GMMarca.prototype.HTML     = '';
GMMarca.prototype.Latitud  = 37.338928
GMMarca.prototype.Longitud = -5.838965
GMMarca.prototype.Icono    = GM.LOCALIZADOR;


GMMarca.prototype.Pos = function (fLatitud, fLongitud)
{
	this.Latitud  = fLatitud;
	this.Longitud = fLongitud;
	this._Marca.setPoint (new google.maps.LatLng (fLatitud, fLongitud));
}

GMMarca.prototype.Tab = function (sTab, sContenido)
{
	if (! this._aTabs) this._aTabs = new Array ();
	this._aTabs.push (new google.maps.InfoWindowTab (sTab, sContenido));
}

function GMMarca (fLatitud, fLongitud, sIcono) 
{ 
	if (typeof fLatitud  != 'undefined') this.Latitud  = fLatitud;
	if (typeof fLongitud != 'undefined') this.Longitud = fLongitud;
	if (typeof sIcono != 'undefined')    this.Icono    = sIcono;
}


google.setOnLoadCallback (GMMap._Init);


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


