var map;
function onPageLoad() {
  if (map!=null)
    map.Dispose();
  resizeMapContainer();
  map = new VEMap('veMap');
  map.LoadMap();
  resizeMapControl();
  window.setTimeout(initialiseFeed, 2000);
}
function resizeMapContainer() {
  if( typeof( window.innerWidth ) == 'number' ) {
    document.getElementById('veMap').style.height = window.innerHeight - 20;
    document.getElementById('veMap').style.width = window.innerWidth;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
    document.getElementById('veMap').style.height = document.documentElement.clientHeight - 20;
    document.getElementById('veMap').style.width = document.documentElement.clientWidth;
  }
}
function resizeMapControl() {
  if (map != null) {
    if( typeof( window.innerWidth ) == 'number' )
      map.Resize(window.innerWidth,window.innerHeight - 20);
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ))
      map.Resize(document.documentElement.clientWidth,document.documentElement.clientHeight - 20);
  }
}
function onPageResize() {
  resizeMapControl();
  resizeMapContainer();
}
function initialiseFeed() {
  loadGeoRSS();
  document.getElementById('veMap').style.visibility = 'visible';
  window.setInterval(loadGeoRSS, 60000);
}
function loadGeoRSS() {
  var geoRSSUrl = 'eventsfeed/RssGroup2324.xml?Session=' + Math.random();
  var veGeoRSSLayer = new VEShapeLayer();
  var veGeoRSSLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, geoRSSUrl, veGeoRSSLayer);
  map.Clear();
  map.ImportShapeLayerData(veGeoRSSLayerSpec, function() {
                                                var numShapes = veGeoRSSLayer.GetShapeCount();
                                                for(var i = 0; i < numShapes; ++i) {
                                                  var s = veGeoRSSLayer.GetShapeByIndex(i);
                                                  if(s.IconId.substr(0,7) != 'http://')
                                                    s.SetCustomIcon(s.IconId + '.png');
                                                }
                                              }, document.getElementById('chkAutoZoom').checked);
  document.getElementById('lastUpdated').innerHTML = new Date();
}