var mapCentred = 0;

function plotLatLong(map, lat, long, zoom, html, callback) {

	if(zoom == undefined) {
		zoom = 13;
	}
	
	var point = new GLatLng(lat, long);
	
	if(mapCentred == 0) {
		  map.setCenter(point, zoom);
		  mapCentred = 1;
	  }
	  
	  var marker = new GMarker(point);
	  map.addOverlay(marker);
	  
	  GEvent.addListener(marker, "click", function() {
		if(html != '' && html != null) {
			map.panTo(point);
			var tourDateInfo = document.getElementById('tourDateInfo');
			tourDateInfo.innerHTML = html;
			tourDateInfo.style.opacity = 1;
		}
		if(callback != null) {
			callback();
		}
	  });
	
}

// tour points array
// structure = tourpoints => 0 = artistName, 1 = latLongs[] => 0 = lat, 1 = long
var tourPoints = new Array();

function addTourPoint(artistName, lat, long) {

	foundExisting = false;
	
	for (var i=0; i < tourPoints.length; i++){
		
		if(tourPoints[i][0] == artistName) {
			currentLatLongsCount = tourPoints[i][1].length;
			
			newLatLongs = new Array();
			newLatLongs[0]  = lat;
			newLatLongs[1]  = long;
			
			tourPoints[i][1][currentLatLongsCount] = newLatLongs;
			foundExisting = true;
		}
		
	}
	
	if(foundExisting == false) {
		
		// we haven't got an array for this artist yet
		
		newArtistArray = new Array();
		newArtistArray[0] = artistName;
		
		newArtistLatLongs = new Array();
		
		newLatLongs = new Array();
		newLatLongs[0]  = lat;
		newLatLongs[1]  = long;
		
		newArtistLatLongs[0] = newLatLongs;
		
		newArtistArray[1] = newArtistLatLongs;
		
		tourPoints[tourPoints.length] = newArtistArray;
		
	}
	
}

function plotTour(map) {
	
	//alert(tourPoints);
	
	for (var i=0; i < tourPoints.length; i++){
		
		var gPoints = new Array();
		
		for (var j=0; j < tourPoints[i][1].length; j++){
					
			point = new GLatLng(tourPoints[i][1][j][0], tourPoints[i][1][j][1]);
			gPoints[gPoints.length] = point;
			
		}
		
		var index = Math.round(Math.random() * 9);

		var ColorValue = "#5d48ae";
		
		var polyOptions = {geodesic:true};
		
		var polyline = new GPolyline(gPoints, ColorValue, 3, 0.8, polyOptions);
		map.addOverlay(polyline);
		
	}
	
}
