var iconBike = null;		// the moving tour marker

// Create start and stop waypoint markers
function setStartStopMarkers(pStart, pStop) {
 var startIcon = new GIcon();
 startIcon.image = "http://www.google.com/mapfiles/dd-start.png";
 startIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
 startIcon.startIconSize = new GSize(20, 34);
 startIcon.shadowSize = new GSize(22, 20);
 startIcon.startIconAnchor = new GPoint(6, 20);
 startIcon.infoWindowAnchor = new GPoint(5, 1);
 
 var stopIcon = new GIcon();
 stopIcon.image = "http://www.google.com/mapfiles/dd-stop.png";
 stopIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
 stopIcon.stopIconSize = new GSize(20, 34);
 stopIcon.shadowSize = new GSize(22, 20);
 stopIcon.stopIconAnchor = new GPoint(6, 20);
 stopIcon.infoWindowAnchor = new GPoint(5, 1);

 var marker1 = new GMarker(pStart, startIcon);
 var marker2 = new GMarker(pStop, stopIcon);
 map.addOverlay(marker1);
 map.addOverlay(marker2);
}

// Creates a marker with an info window
function createInfoMarker(point, number, info) {
 var marker = new GMarker(point);

 // Show this marker's index in the info window when it is clicked
 var html = "give url of image" + info;
 GEvent.addListener(marker, "click", function() {
   marker.openInfoWindowHtml(html);
 });

 return marker;
}

// Creates a marker
function createMarker(point) {
 return(new GMarker(point));
}

function createBikeMarker(point) {
 if (iconBike == null) {
  iconBike = new GIcon();
  iconBike.image = "http://b4mad.net/maps/bike.png";
  iconBike.iconSize = new GSize(32, 18);
  iconBike.iconAnchor = new GPoint(6, 18);
 }

 return(new GMarker(point, iconBike));
}

// Image Preloader
function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ ) 
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);
	
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages, this.nLoaded);
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
