//sampleMarker.js
//This javascript code helps us create and destroy a sample marker on the map.

//Constructor
function SampleMarker(permanent, point, icon, googlemap) {
	//The permanent icon that this marker is displacing.
	this.permanent = permanent;
	this.googlemap = googlemap;
	googlemap.removeOverlay(permanent);
	
	this.displayedSample = null;
	this.point = point;
	this.icon = icon;
	this.redisplay();
}

//Redisplay the sample marker with a new point and picture.
SampleMarker.prototype.redisplay = function() {
	this.googlemap.removeOverlay(this.displayedSample);
	this.displayedSample = new GMarker(this.point, this.icon);
	this.googlemap.addOverlay(this.displayedSample);
}

//Change the location of the sample marker
SampleMarker.prototype.moveToPoint = function(point) {
	this.point = point;
	this.redisplay();
};

//Change the icon of the sample marker
SampleMarker.prototype.changeIcon = function(icon) {
	this.icon = icon;
	this.redisplay();
}

//Destroy the sample marker and return the map to its previus statae with the permanent marker.
//The permanent marker may be null, in which case the sample marker just disappears.
SampleMarker.prototype.destroy = function() {
	this.googlemap.removeOverlay(this.displayedSample);
	if (this.permanent)
		this.googlemap.addOverlay(this.permanent);
}