var map,alliw = new Array(),default_zoom = 2,ctr;
var load_places = function(url,image){
    var b = new Request.JSON({
        'url' : url,
        'onSuccess' : function(j,t){
            var n = 1;
            j.each(function(e){
                var myLatLng = new google.maps.LatLng(e.lat,e.lng);
                var im = new google.maps.MarkerImage(image,
                    new google.maps.Size(38,43),
                    new google.maps.Point(0,0),
                    new google.maps.Point(13, 43));
                
                var marker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    icon: im,
                    title : e.name,
                    zIndex : n
                });
                google.maps.event.addListener(marker,'click',function(){
                    var iw = document.getElement('#infowindow');
                    if (iw) iw.dispose();
                    map.setCenter(myLatLng);
                    // create an infowindow
                    var iw = new infowindow('map',map);
                    iw.pop_up(e.name,e.description,e.url);
                    iw.close_returns_centre(ctr);
                    map.setZoom(14);
                });
                n++;
            });
        }
    }).send();
}

window.addEvent('domready',function(){
    ctr = new google.maps.LatLng(37.43997405227057, 17.2265625);
    map = new google.maps.Map(document.getElementById('map'),{
        zoom : default_zoom,
        center : ctr,
        mapTypeId : google.maps.MapTypeId.ROADMAP,
        disableDefaultUI : true,
        navigationControl : true,
        navigationControlOptions : {
            style : google.maps.NavigationControlStyle.SMALL
        },
        scrollwheel : false
    });
    /*google.maps.event.addListener(map,'zoom_changed',function(){
        if (map.getZoom() < default_zoom) map.setZoom(default_zoom);
    });*/
    // find out the lat/lng after the map has been dragged
    /*google.maps.event.addListener(map,'dragend',function(){
        alert(map.getCenter());
    });*/
    load_places('/servicing-markers','/images/servicing-marker.png');
    load_places('/installation-markers','/images/installation-marker.png');
    load_places('/both-markers','/images/both-marker.png');
});





