//<![CDATA[
	
	var _gmap = null;
	var _mapZoom = 15;
	var _markers = [];
	var _htmls = [];
	var _bounds;
	var _geocoder = null;
	
	var _icon = new GIcon();
	_icon.image = "./images/marker.png";
	_icon.iconSize = new GSize( 20, 34 );
	//_icon.shadow = "./images/shadow.png";
	//_icon.shadowSize = new GSize( 37, 34 );
	_icon.iconAnchor = new GPoint( 9, 34 );
	_icon.infoWindowAnchor = new GPoint( 6, 3 );
	
	var _iconFocus = new GIcon();
	_iconFocus.image = "./imgs/marker.png";
	_iconFocus.iconSize = new GSize( 20, 34 );
	//_iconFocus.shadow = "./imgs/shadow.png";
	//_iconFocus.shadowSize = new GSize( 37, 34 );
	_iconFocus.iconAnchor = new GPoint( 9, 34 );
	_iconFocus.infoWindowAnchor = new GPoint( 8, 12 );
	
	var _currentMarker = null;
	
	
	function isBrowserCompatible() {
		return GBrowserIsCompatible();
	}
	
	function init() {
		if ( isBrowserCompatible() ) {
			_gmap = new GMap2( document.getElementById( "gmap" ) );
			_gmap.addControl( new GSmallZoomControl(),
				new GControlPosition( G_ANCHOR_TOP_LEFT, new GSize( 10, 10 ) ) );	
			
			_gmap.addControl( new GMapTypeControl() );
			
			//  ======== Add a map overview ==========
      //_gmap.addControl( new GOverviewMapControl( new GSize( 150, 150 ) ) );
			
			resetMap();
			_bounds = new GLatLngBounds();
			
			addMarker( -33.874531, 151.218481 );
		}
	}
	
	function resetMap() {
		_gmap.clearOverlays();
		
		setMapBounds( -33.811462, -33.8094845, -33.807507, 151.179294, 151.184546, 151.189798 );
		_gmap.setCenter( new GLatLng( -33.874531, 151.218481 ), _mapZoom );
	}
	
	function setMapCenter(lat, lng, zoom) {
		var point = new GLatLng(lat, lng);
		_gmap.setCenter(point, zoom);
	}
	
	function setMapBounds( minLat, midLat, maxLat, minLng, midLng, maxLng ) {
		var SW = new GLatLng( minLat, minLng );
		var NE = new GLatLng( maxLat, maxLng );
		var mapBounds = new GLatLngBounds( SW,  NE );
		var zoom = _gmap.getBoundsZoomLevel( mapBounds );
		setMapCenter( midLat, midLng, zoom );
	}
	
	function centerMapFromBounds() {
		// ===== determine the zoom level from the bounds =====
		_gmap.setZoom( _gmap.getBoundsZoomLevel( _bounds ) );
		
		// ===== determine the centre from the bounds ======
		var clat = ( _bounds.getNorthEast().lat() + _bounds.getSouthWest().lat() ) / 2;
		var clng = ( _bounds.getNorthEast().lng() + _bounds.getSouthWest().lng() ) / 2;
		//_gmap.setCenter( new GLatLng( clat, clng ) );
		_gmap.setCenter( _bounds.getCenter() );
	}
	
	
	function addMarker( lat, lng ) {
		var options = new Object();
		options.clickable = false;
		options.icon = _icon;
		var point = new GLatLng( lat, lng );
		var marker = new GMarker( point, options );		
		_gmap.addOverlay( marker );
		_bounds.extend( point );
	}
	
	function addClickableMarker( markerNum, lat, lng, title, content ) {
		var htmlInfoWindow = buildInfoWindow( title, content );	
		var options = new Object();
		options.title = title;
		options.clickable = true;
		var point = new GLatLng( lat, lng );
		var marker = createClickableMarker( markerNum, point, htmlInfoWindow );
		_htmls[markerNum] = htmlInfoWindow;
		_gmap.addOverlay( marker, options );
		_bounds.extend( point );
		return marker;
	}
	
	function buildInfoWindow( title, content ) {
		infoWin = '<table border="0" cellpadding="0" cellspacing="0" class="webrates">';
		infoWin += '<tr><th colspan="3">' + title + '</th></tr>';
		infoWin += '<tr><td class="border-left border-right">' + content + '</td></tr><tr><td class="footer-row">&nbsp;</td></tr></table>';
		return infoWin;
		
		//return '<div class="mapInfoWindow"><h3>'+title+'</h3><p>'+content+'</p></div>';
	}
	
	function Right(str, n){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else {
			var iLen = String(str).length;
			return String(str).substring(iLen, iLen - n);
		}
	}
	
	function createClickableMarker( markerNum, point, htmlInfoWindow ) {
		var tmpIcon = new GIcon( _icon );
		tmpIcon.image = "./imgs/markers/marker_" + Right( "000" + markerNum, 3 ) + ".png";
		tmpIcon.iconSize = new GSize( 20, 20 );
		tmpIcon.iconAnchor = new GPoint( 9, 20 );
	
		var marker = new GMarker( point, tmpIcon );
		GEvent.addListener( marker, "mouseover", function() {
			_gmap.removeOverlay( _currentMarker );
			var point = new GLatLng( marker.getPoint().lat(), marker.getPoint().lng() );
			var options = new Object();
			options.clickable = false;
			_currentMarker = createClickableFocusMarker( markerNum, point, htmlInfoWindow )
			_gmap.addOverlay( _currentMarker, options );
		});
		return marker;
	}
	
	function createClickableFocusMarker( markerNum, point, htmlInfoWindow ) {
		var tmpIcon = new GIcon( _iconFocus );
		tmpIcon.image = "./imgs/markers/marker_" + Right( "000" + markerNum, 3 ) + ".png";
		tmpIcon.iconSize = new GSize( 20, 20 );
		tmpIcon.iconAnchor = new GPoint( 9, 20 );
		
		var focusmarker = new GMarker( point, tmpIcon );
		GEvent.addListener( focusmarker, "click", function() { focusmarker.openInfoWindowHtml( htmlInfoWindow, {pixelOffset:new GSize(32,5), maxWidth: 150} ); });
		return focusmarker;
	}
	
	function addDragableMarker( lat, lng ) {
		var marker = createDragableMarker( new GLatLng( lat, lng ) );
		_gmap.addOverlay( marker );
	}
	
	function createDragableMarker( point ) {	
		var options = new Object();
		options.icon = _icon;
		options.draggable = true;
		options.dragCrossMove = true;
		var marker = new GMarker( point, options );
		
		GEvent.addListener( marker, "dragstart", function() {
		  _gmap.closeInfoWindow();
		});
		
		GEvent.addListener( marker, "dragend", function() {
			var latlng = marker.getPoint();
			var mapDescription = document.getElementById( "map-description" );
			mapDescription.innerHTML = 'This is an example of a dragable marker. The point\'s current latitude/longitude is ' + latlng.lat() + '/' + latlng.lng(); 
		  //marker.openInfoWindowHtml("Just bouncing along to... lat " + latlng.lat() + ' lng ' + latlng.lng()  );
		});
		
		return marker;
	}
		
	
	
//]]>
