// Google Map Loading functions
var startZoom = 9; 
var map;

function init_map(name) 
{ 
	if (GBrowserIsCompatible()) { 
		map = new GMap2(document.getElementById(name)); 
		var location = new GLatLng(centerLatitude, centerLongitude); 
		map.setCenter(location, startZoom);
		map.addControl(new GSmallMapControl());
//		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
	}
}

function positionMap(){
	var mapElement = $('map-container');
	var change = (Position.cumulativeOffset(mapElement)[1] - Position.page(mapElement)[1]);
	
	if (change < 338) {
		new Effect.Move(mapElement,{ x: 0, y: (327 - Position.cumulativeOffset(mapElement)[1]), mode: 'relative'});
	}
	else {
		if (!Position.within(mapElement, 700, document.height - 200)) {
			new Effect.Move(mapElement,{ x: 0, y: (0 - Position.page(mapElement)[1]), mode: 'relative', afterFinishInternal: checkMapBottom});
		} else {
			if (Position.page(mapElement)[1] > 100)
			new Effect.Move(mapElement,{ x: 0, y: (0 - Position.page(mapElement)[1]), mode: 'relative'});
		}
	}
}

function checkMapBottom() {
	var mapElement = $('map-container');
	if (Position.within(mapElement, 700, document.height - 200))
	new Effect.Move(mapElement,{ x: 0, y: ($('page').getHeight() - 45 - mapElement.getHeight()) , duration: 0.3 , mode: 'absolute'});
}

Event.onReady(function(){
	map = document.getElementById('map-mini');
	if (!map) {
		new PeriodicalExecuter(positionMap, 2.5);
	}
});
