/*
This is a quick and dirty way to gather all the address info
will probably be used more efficiently in venue_entry_form.js later
in development.
*/
var mapper;
var markers = new Array();
function mapLoad(ps, map_id, zoom){
        /*forcing zoom to 15 per big person */
        zoom = 15;
        if (GBrowserIsCompatible()) {
            mapper = new GMap2(document.getElementById(map_id));
            mapper.addControl(new GSmallMapControl());
            mapper.addControl(new GMapTypeControl());
            for(i=0; i<ps.length; i++){
                if(i==0){
                    point = new GLatLng(ps[i].lat, ps[i].lon);
                    mapper.setCenter(point, zoom ? zoom : 10);
                }
                addPoint(ps[i],$(map_id+'_'+ps[i].event_id),true,ps[i].icon);
            }
        }
}
                 

function mapLoad2(ps, id) {
    if (GBrowserIsCompatible()) {
        mapper = new GMap2(document.getElementById(id));
        mapper.addControl(new GSmallMapControl());
        mapper.addControl(new GMapTypeControl());

        for(i=0; i<ps.length; i++){
            point = new GLatLng(ps[i].lat, ps[i].lon);
            if(i==0) mapper.setCenter(point, 16);
            var customIcon = new GIcon();
			    customIcon.image = ps[i].icon;
				customIcon.iconSize = new GSize(21, 25);
				customIcon.iconAnchor = new GPoint(10, 25);
				customIcon.infoWindowAnchor = new GPoint(10, 2);
			    markerOptions = { icon:customIcon };
            var marker = new GMarker(point, markerOptions);
            mapper.addOverlay(marker);
            marker.openInfoWindowHtml(ps[i].bubble);
        }
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(points[0].bubble);
        });
        GEvent.addDomListener($("venTitle"),"mouseover", function() {
            marker.openInfoWindowHtml(points[0].bubble);
        });
    }
}

function addPoint(p,element,addToMap,icon, addToArray){
            point = new GLatLng(p.lat, p.lon);
            if(icon){
                var customIcon = new GIcon();
                customIcon.iconSize = new GSize(21, 25);
				customIcon.iconAnchor = new GPoint(10, 25);
				customIcon.infoWindowAnchor = new GPoint(10, 2);
			    customIcon.image = icon;
			    markerOptions = { icon:customIcon };
            }
            var marker = new GMarker(point, markerOptions);
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(p.bubble);
            });
            GEvent.addDomListener(element,"mouseover", function() {
                    marker.openInfoWindowHtml(p.bubble);
            });
            if(addToArray){ markers.push(marker) };
            if (addToMap){
                 mapper.addOverlay(marker);
            }
            return marker;
}
function clearPoints(){
       for(i=0; i<markers.length; i++){
            mapper.removeOverlay(markers[i]);
        }
    markers = new Array();
}

