//http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Ossabaw+Island+Georgia&sll=31.864292,-81.020136&sspn=0.020994,0.04549&ie=UTF8&ll=31.786989,-81.100216&spn=0.084047,0.181961&z=13


/*
31.864292,-81.020136
31.78874,-81.100216
*/
var mapElements = Array();
var map;
var tmpFunctions = Array();

function googInit( )
{
	try
	{
	
		if ( GBrowserIsCompatible() )
		{
			map = new GMap2(document.getElementById("map_canvas"));
			//map.setCenter(new GLatLng(31.839401, -81.200216), 12);
			map.setCenter(new GLatLng(31.78874, -81.100216), 12);
			//map.setCenter(new GLatLng(31.864292, -81.020136), 12);
			map.addControl(new GSmallMapControl()); 
			map.addControl(new GMapTypeControl() );
			
			// Create a base icon for all of our markers that specifies the shadow,
			// icon dimensions, etc.
			var baseIcon = new GIcon(G_DEFAULT_ICON); baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; 
			baseIcon.iconSize = new GSize(20, 34); 
			baseIcon.shadowSize = new GSize(37, 34);
			baseIcon.iconAnchor = new GPoint(9, 34); 
			baseIcon.infoWindowAnchor = new
			GPoint(9, 2);

			// Creates a marker whose info window displays the letter corresponding
			// to the given index.
			function createMarker(point, index , text ) 
			{
				// Create a lettered icon for this point using our icon class
				//var letter = String.fromCharCode("A".charCodeAt(0) + index);
				//var letteredIcon = new GIcon(baseIcon); letteredIcon.image ="http://www.google.com/mapfiles/marker" + letter + ".png";
				
				// Set up our GMarkerOptions object
				markerOptions = { };//icon:letteredIcon };
				var marker = new GMarker(point,markerOptions);
				
				GEvent.addListener(marker, "click", 
					function() 
					{
						marker.openInfoWindowHtml("" + text + "");
					}
				);
				return marker;
			}
			var k = 1;
			for( var i = 0 ; i < mapElements.length;i+=3)
			{
				try{
					map.addOverlay( createMarker( new GLatLng( Number( mapElements[i] ) , Number( mapElements[i+1] ) ) , i , mapElements[i+2] ) );
				}catch(e)
				{
					k+=3;
				}
			}
			if( k == mapElements.length )
			{
				//document.getElementById( 'map_canvas' ).style.display = "none";
			}else
			{
				tmpFunctions[tmpFunctions.length] = document.getElementById("mapTab").onclick;
				tmpFunctions[tmpFunctions.length] = refreshGoogleMap;
				document.getElementById("mapTab").onclick = runEvents;
				onUnload();
			}
		}
	}catch(e)
	{
		alert( e );
		// LOL Wut? Google not reachable
	}
	
}

function onLoad(a)
{
	
	if( !a )
	{
		document.getElementById( 'map_canvas' ).style.display = "block";
		return;
	}else if( !( a instanceof Array ) )
	{
		document.getElementById( 'map_canvas' ).style.display = "block";
		return;
	}
	
	mapElements = a;
	
	// Add initialize to onLoad action event
	try
	{
		if( window.addEventListener )
		{
			window.addEventListener( "load" , googInit , false );
		}else if( window.attachEvent )
		{
			window.attachEvent( "onload" , googInit );
		}else
		{
			window.onload = googInit;
		}
	}catch(e)
	{
		//document.getElementById( 'map_canvas' ).style.display = "none";
		// Oops Something Happened
	}
}

function onUnload()
{
	// Add GUnload to unload action event
	try
	{
		if( window.addEventListener )
		{
			window.addEventListener( "unload" , GUnload , false );
		}else if( window.attachEvent )
		{
			window.attachEvent( "unload" , GUnload );
		}else
		{
			window.unload = GUnload;
		}
	}catch(e)
	{
		// Oops Something Happened
	}
}

function runEvents(e)
{
	for( $i = 0;$i<tmpFunctions.length;$i++ )
	{
		var f = tmpFunctions[$i];
		f(e);
	}
}

function refreshGoogleMap(e)
{
	setTimeout( 
		new function()
		{
			document.getElementById( 'mapPanel' ).style.display = "block";
			map.checkResize();
			map.setCenter(new GLatLng(31.78874, -81.100216), 12);
		}, 
		1000
	);
}

