var Local = function(id, tipo, nombre, correo, web, x, y, localidad, direccion, telefono, format){
    this.id = id;
    this.tipo = tipo;
    this.nombre = nombre;
    this.correo = correo;
    this.web = web;
    this.x = x;
    this.y = y;
    this.localidad = localidad;
    this.direccion = direccion;
    this.telefono = telefono;
    this.format = format;
}
Local.prototype.getHTML = function(){
    var myHtml = '<b>' + this.nombre + '</b><br />' + this.localidad + '<br />' + this.direccion + '<br />' + '<a class="infobocata" href="http://www.mallorca-rock.com/locales/' + this.format + '.html" title="Ver m&aacute;s informaci&oacute;n">+ info del local</a>';
	return myHtml;
};
Local.prototype.getGeo = function() { return this.x+'#'+this.y; }
function createMarker(latlng, icon, myHtml){
    var marker = new GMarker(latlng, icon);    
    GEvent.addListener(marker, "click", function(){
        map.openInfoWindowHtml(latlng, myHtml);
    });
    return marker;
}
function cargaPuntos(aLocales){
    if (GBrowserIsCompatible()) {
        map = new GMap2($('gmap'));
		var icon = new GIcon();
		icon.image = "http://www.mallorca-rock.com/img/redicon.gif";
		icon.shadow = "http://www.mallorca-rock.com/img/redshadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
        geocoder = new GClientGeocoder();
        map.addControl(new GLargeMapControl());
        var numLocals = aLocales.length;
        xfinal = 39.608961;
        yfinal = 2.942963;
        map.setCenter(new GLatLng(xfinal, yfinal), 9);
        for (var i = 0; i < numLocals; i++) {
            aLocales[i] = eval(aLocales[i]);
            var myHtml = aLocales[i].getHTML();
		var geo = aLocales[i].getGeo();
            var point = new GLatLng(geo.split('#')[0],geo.split('#')[1]);
            map.addOverlay(createMarker(point, icon, myHtml));
        }
    }
}
var linkSeleccionado = '';
function getLocal(id, objLocal){
	if (linkSeleccionado != '') { linkSeleccionado.className = linkSeleccionado.className.replace('on', 'off'); }
	$(id).className = 'on';
	linkSeleccionado = $(id);
	var myHtml = eval(objLocal).getHTML();
	var geo = eval(objLocal).getGeo();
	map.setCenter(new GLatLng(geo.split('#')[0],geo.split('#')[1]), 15);
	map.openInfoWindowHtml(map.getCenter(), myHtml);
}
window.onload = function(){ if (aLocales != '') { cargaPuntos(aLocales); } }
window.onunload = function(){ GUnload(); }