if(!window.Oventi) {
	Oventi = {};
}

if(!Oventi.Mapplets) {
	Oventi.Mapplets = {};
}

Oventi.Mapplets.Traveler = function (zoomLevel, startMessage) {
	this._map = null;
	this._lastPoint = null;
	this._zoomLevel = zoomLevel;
	this._startMessage = startMessage;
	this._startPoint = null;
	
	var self = this;
	
	this.initMap = function () {
		if(GBrowserIsCompatible()) {
			this._map = new GMap2(document.getElementById("Oventi.Mapplets.Traveler"));
			this._map.setCenter(new GLatLng(-5, -5), this._zoomLevel);
			
			this._startPoint = new GMarker(new GLatLng(-5, -5));
			this._startPoint.openInfoWindowHtml(this._startMessage);			
			this._map.addOverlay(this._startPoint);
			this._startPoint.hide();
			
			return true;
		}
		
		alert("Oventi.Mapplets.Traveler: browser is incompatible with Google Maps");
		return false;
	}	
	
	this.travel = function (index) {
		if(this._startPoint != null) {
			this._map.removeOverlay(this._startPoint);
			this._startPoint = null;
		}	
	
		$.get("php/destination.php", {}, function(response) {
			var gll = new GLatLng(response.latitude, response.longitude);
			newPoint = new GMarker(gll);

			self._map.setCenter(gll);
			
			response.content += '<br><br><div align=right><!-- AddThis Button BEGIN --><a class="addthis_button" href="http://addthis.com/bookmark.php?v=250&amp;username=xa-4be9ec0c4cf9e29b" addthis:url="http://www.globalheal.com/2010/05/10/around-the-world-exposure/" addthis:title="Around the World Exposure | GlobalHeal.com" addthis:description="Through education and awareness, we help realize the similarities between people, instead of categorizing our differences and distancing ourselves from others through our ignorance tool."><img src="http://s7.addthis.com/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4be9ec0c4cf9e29b"></script><!-- AddThis Button END --></div>';			
    		
			GEvent.addListener(newPoint, "click", function() {
				newPoint.openInfoWindowHtml(response.content);
			});
			
			if(self._lastPoint != null) {
				self._map.removeOverlay(self._lastPoint);				
			}
			
			self._map.addOverlay(newPoint);
			newPoint.openInfoWindowHtml(response.content);
			
			/* this line gave me problems
			 * when used, the infoWindow might not be completely visible
			 * to improve it, make the infoWindow centered on the map, and remove the line self._map.setCenter(gll);
			 */
			//self._map.panTo(new GLatLng(response.latitude, response.longitude));
			
			self._lastPoint = newPoint;			
		}, "json");
	}	
}

