/**
 * @author Kirk Ouimet
 */

/* Initialize the Google Map
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
var baseIcon;
function loadMap() {
	if(GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		map.enableScrollWheelZoom();
		//map.addControl(new GLargeMapControl());
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		gKeyboardHandler = new GKeyboardHandler(map);
		map.setCenter(new GLatLng(17.3, 0), 2);
		// Fix the page scroll on zoom issue
		GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
		map.getContainer().onmousewheel = wheelevent; 		
        // Create a base icon for all markers
        baseIcon = new GIcon();
        baseIcon.shadow = "/img/map/shadow.png";
        baseIcon.iconSize = new GSize(20, 20);
        baseIcon.shadowSize = new GSize(30, 20);
        baseIcon.iconAnchor = new GPoint(10, 20);
        baseIcon.infoWindowAnchor = new GPoint(10, 20);
        baseIcon.infoShadowAnchor = new GPoint(10, 20);
	}
}

/* Global variables
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
var vectorTrace = new VectorTrace();

/* Overriding the addServerData function provided by DNSstuff.com
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
function addServerData(serverNumber, hopNumber, time1, time2, time3, bestTime, ip, hostname, asn, country, lat, lng) {
	detailed_results[serverNumber][detailed_results[serverNumber].length] = new Array(hopNumber, time1, time2, time3, bestTime, ip, hostname, asn, country, lat, lng);
	serverNumber++; // Adjust for non-array index notation
	$('server_data_'+serverNumber).innerHTML += hostname+'<br />';
	
	// Trace the new server data on the map
	
	// Create a TraceHop object with the data provided
	var traceHop = new TraceHop(serverNumber, hopNumber, time1, time2, time3, bestTime, ip, hostname, asn, country, lat, lng);
	
	// If we already have a trace object for the particular server
	if(vectorTrace.containsTraceFromServer(traceHop.serverNumber)) {
		// Use the existing trace object
		vectorTrace.traceArray[vectorTrace.getTraceArrayIndexByServerNumber(serverNumber)].addHop(traceHop);
	}
	// If we need to create a trace object for the server
	else {
		var trace = new Trace(serverNumber, vectorTrace.getNextAvailableColor());
		trace.addHop(traceHop); // Add the TraceHop to the Trace
		vectorTrace.addTrace(trace); // Add the Trace to the VectorTrace
	}
}