function RouteMap(dir) {
	//ex: ../.. or .. number of directories to get to root (/martellhomes/)
	this.dir = dir;
	this.vehicles = [];
}

RouteMap.prototype.refreshVehicles = function(xml) {

	this.destroyVehicles();	
	thismap = this;
	
	$('vehicle', xml).each(function (i) { 
		var id = $(this).attr('id');
		var lat = $(this).attr('lat');
		var lng = $(this).attr('lng');
		var lastupdate = $(this).attr('lastupdate');
		var icon = $(this).attr('icon');
		
		thismap.addVehicle(lat, lng, icon);
		window.map.setCenter(new GLatLng(lat, lng));
	});
	
}

RouteMap.prototype.destroyVehicles = function() {

	for(var i = 0; i < this.vehicles.length; i++) {
		GEvent.clearInstanceListeners(this.vehicles[i]);
		window.map.removeOverlay(this.vehicles[i]);
		this.vehicles[i] = null;
	}
	this.vehicles = [];
}

RouteMap.prototype.addVehicle = function(lat, lng, iconText) {

	var icon = this.getVehicleIcon(iconText);
  
  	var marker = new GMarker(new GLatLng(lat, lng), {icon: icon, draggable: false});
	
	GEvent.bind(marker, "click", this, GEvent.callbackArgs(this, this.clickVehicle, marker));
	
	window.map.addOverlay(marker);
	
	this.vehicles[this.vehicles.length] = marker;
}

RouteMap.prototype.clickVehicle = function(marker) {
	window.open(this.dir+"/admin/camera.php", 'InfoWindow', 'width=600,height=325,scrollbars=yes');
}

RouteMap.prototype.getVehicleIcon = function(id) {	
	
	var icon = new GIcon();

	icon.image = this.dir+"/icons/busIcon.php?id=" + id;
  		
  	icon.iconSize = new GSize(60,60);
  	icon.iconAnchor = new GPoint(5,55);
  	icon.infoWindowAnchor = new GPoint(35,0);
  	
	return icon;
}

RouteMap.prototype.destroy = function() {

	this.destroyVehicles();
	this.buses = [];
}