
// Variable declarations
var map;
var iconsSwitch = false;
var iconsSwitchZoom = 10;

// Maps functions
function initialize()
{
	if (GBrowserIsCompatible())
	{
		// Create map
		map = new GMap2(document.getElementById("map"));
		
		// Add controls
		map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(15, 20)));
        map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(87, 18)));
		map.addControl(new GScaleControl());
		map.enableScrollWheelZoom();
		map.addMapType(G_PHYSICAL_MAP);
		map.setMapType(G_PHYSICAL_MAP);
		
		// Map listeners
		GEvent.addListener(map, "load", function()
		{
			map.checkResize();
		});
		
		if (iconsSwitch == true)
		{
			GEvent.addListener(map, "zoomend", function(oldLevel, newLevel)
			{
				zoomEndHandler(oldLevel, newLevel);
			});
		}
		
		// Center map
		map.setCenter(new GLatLng(52.45935663683681, 5.9051513671875), 8);
		
		// Display markers
		for (var i = 0; i < markersSingleList.length; i++)
		{
			if (markersSingleList[i] != undefined)
			{
				map.addOverlay(markersSingleList[i]);
			}
		}
		
		for (var i = 0; i < markersMultipleList.length; i++)
		{
			if (markersMultipleList[i] != undefined)
			{
				map.addOverlay(markersMultipleList[i]);
			}
		}
		showMarkers(markersMultipleList, true);
		
		if (iconsSwitch == true)
		{
			for (var i = 0; i < markersZoomSingleList.length; i++)
			{
				if (markersZoomSingleList[i] != undefined)
				{
					map.addOverlay(markersZoomSingleList[i]);
				}
			}
			showMarkers(markersZoomSingleList, false);
		}
	}
}

function resizeMap()
{
	h = $(window).height();
	h = h - 145;
	$("div#map").css({'height' : h+'px' });
	
	w = $(window).width();
	if (w < 945) 
	{
		$("div#footer").css({'width' : '945px' });
		$("div#map").css({'width' : '945px' });		
	} else {
		$("div#footer").css({'width' : '100%' });				
		$("div#map").css({'width' : '100%' });		
	}	
	
	if (map != undefined)
	{
		map.checkResize();
	}
	
	return false;
}

function showMarkers(markersList, value)
{
	for (var i = 0; i < markersList.length; i++)
	{
		if (markersList[i] != undefined)
		{
			if (value == true)
			{
				markersList[i].show();
			} else
			{
				markersList[i].hide();
			}
		}
	}
}

function zoomEndHandler(oldLevel, newLevel)
{
	if ((oldLevel != undefined) && (newLevel != undefined))
	{
		if ((oldLevel < iconsSwitchZoom) && (newLevel >= iconsSwitchZoom))
		{
			showMarkers(markersMultipleList, false);
			showMarkers(markersZoomSingleList, true);
		} else if ((oldLevel >= iconsSwitchZoom) && (newLevel < iconsSwitchZoom))
		{
			showMarkers(markersMultipleList, true);
			showMarkers(markersZoomSingleList, false);
		}
	}
}
