// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults   

function remove_field(element, item) {
  element.up(item).remove();
}

/* fade flashes automatically */
Event.observe(window, 'load', function() { 
  $A(document.getElementsByClassName('noticeflash')).each(function(o) {
    o.opacity = 100.0
    Effect.Fade(o, {duration: 7.0})
  });
});


/***
 * Excerpted from "Advanced Rails Recipes",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/fr_arr for more book information.
***/
function initialize() { 
  if (GBrowserIsCompatible() && typeof elements != 'undefined') {
    var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(51.2522, 4.46648), 13);
    map.addControl(new GLargeMapControl());
  
    // Clicking the marker will hide it
    function createMarker(latlng, element, user) {
      var marker = new GMarker(latlng);
      var html=element.body;
      GEvent.addListener(marker,"click", function() {
        map.openInfoWindowHtml(latlng, html);
      });
      return marker;
    }

    var bounds = new GLatLngBounds;
    for (var i = 0; i < elements.length; i++) {
      var latlng=new GLatLng(elements[i].element.lat,elements[i].element.lng)
      bounds.extend(latlng);
      map.addOverlay(createMarker(latlng, elements[i].element));
    }
    map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds)-1);
  }
}  
window.onload=initialize;
window.onunload=GUnload;  
