/**
 * Keyboard-accessible Google Maps
 * 
 * Written by Patrick H. Lauke (@patrick_h_lauke) for Dev.Opera
 * http://dev.opera.com/articles/view/keyboard-accessible-google-maps/
 * 
 * Modified by Martin Kliehm (@kliehm) for Learning the World
 * http://learningtheworld.eu/2009/keyboard-accessible-google-maps/
 * 
 * Code licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

var GMAP = {
	map: '',
	initMap: function() {
		if ( document.getElementById( 'map' ) && typeof GBrowserIsCompatible !== 'undefined' && GBrowserIsCompatible() ) {
			GMAP.map = new google.maps.Map2( document.getElementById( 'map' ) );
			GEvent.addDomListener( GMAP.map, 'load', function() {
				setTimeout( 'GMAP.GKeyboardPatch( GMAP.map );', 3000 );
			});
			GMAP.map.setCenter( new GLatLng(50.112267, 8.678384), 15 );
			GMAP.map.addControl( new google.maps.SmallMapControl() );
			GMAP.map.addControl( new google.maps.MapTypeControl() );
			new GKeyboardHandler( GMAP.map );
			
			// Set latitude and longitude
			var point = new GLatLng( 50.110950757575814, 8.684666901826859 );
			// Create a marker
			marker = new GMarker( point );
			// Add the marker to map
			GMAP.map.addOverlay( marker );
			GMAP.map.enableScrollWheelZoom();
			GMAP.map.enableContinuousZoom();
		}
	},
	
	GKeyboardPatch: function( map ) {
		var button, divs = map.getContainer().getElementsByTagName( 'div' );
		var i = 0;
		while ( divs[i] ) {
			if ( divs[i].getAttribute( 'log' ) || ( divs[i].getAttribute( 'title' ) && divs[i].getAttribute( 'title' ) != '' ) ) {
				button = document.createElement( 'button' );
				button.setAttribute( 'value', divs[i].getAttribute( 'title' ) );
				divs[i].appendChild( button );
				if ( divs[i].getAttribute( 'log' ) ) { // only control buttons
					// override the IE opacity filter that Google annoyingly sets
					divs[i].style.filter = '';
					// should really set to 'transparent'
					divs[i].style.background = 'url( http://www.google.com/intl/en_ALL/mapfiles/transparent.png )';
				}
			}
			i++;
		}
	}
}
