//// GoogleMaps support ( © 2008 buienradar.nl)
//// Version		1.0
//// Author			B. Hendriks
////
//// GoogleMapsSupport is a script contains functions for displaying radar images as an overlay
//// ontop of the googlemap.
//// 
	
//// Global variables ////
var overlayimages = new Array(images.length);
var imagetimestamp = new Array(images.length);
var mapindex = 0;
var map = null;

//// public functions ////
function initialize() {
  if(gup('panorama')!="")
{

	window.moveTo(0, 0);
	window.resizeTo(screen.width, screen.height);
}

	map = new GMap2(document.getElementById("map_canvas"));
//    map.setCenter(new GLatLng(52.4345,5.428), 8, G_PHYSICAL_MAP);
    map.setCenter(new GLatLng(52.4345,5.428), 8, G_HYBRID_MAP);


    map.addControl(new GSmallMapControl());
    map.addMapType(G_PHYSICAL_MAP);
    map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl(new GSize(150,150)));
	var boundaries = new GLatLngBounds(new GLatLng(48.895,0), new GLatLng(55.974,10.856));
	
	//// Due to googlemaps limitations this way of showing the images is only suitable for ie7.
//	if (navigator.userAgent.indexOf('MSIE 7') != -1||navigator.userAgent.indexOf('Firefox/3') != -1)  
	if (navigator.userAgent.indexOf('MSIE 7') != -1||navigator.userAgent.indexOf('MSIE 8') != -1)  
	{
		while (mapindex<overlayimages.length)
		{
			overlayimages[mapindex] = new GGroundOverlay(images[mapindex], boundaries);
			imagetimestamp[mapindex] = images[mapindex].substring(images[mapindex].length-8,images[mapindex].length-4);
			mapindex++;
		}
		mapindex=0;

		window.setTimeout(function() {nextOverlay();}, 2000);
	}
	else
	{
		map.addOverlay(new GGroundOverlay(animimage, boundaries));
	}
}

//// private functions ////
function nextOverlay()
{
	map.clearOverlays();
    map.addOverlay(overlayimages[mapindex]);
	document.getElementById("timestamp").innerHTML = imagetimestamp[mapindex];
	document.getElementById("timestamp2").innerHTML = imagetimestamp[mapindex];
	mapindex++;

	if (mapindex >= overlayimages.length)
	{
		//// Last image showes longer.
		window.setTimeout(function() {nextOverlay();}, 4000);
		mapindex = 0;
	}
	else 
	{
		window.setTimeout(function() {nextOverlay();}, 250);
	}

}

function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
