function Project(name, title, lat, lng, llat, llng, pin, active)
{
	this.name = name;
	this.title = title;
	this.location = new GLatLng(lat, lng);
	this.labelVector = new GLatLng(llat - lat, llng - lng);
	this.labelLocation = new GLatLng(llat, llng);
	this.showLabel = true;
	this.pinIcon = (pin == 0)
		? smallPinIconLeft
		: smallPinIconRight;
	this.active = active;
	this.visible = true;
	
	var labelPix = map.fromLatLngToDivPixel(this.labelLocation);
	var basePix = new GPoint(labelPix.x, labelPix.y + 31);
	
	this.labelBase = map.fromDivPixelToLatLng(basePix);
	map.addOverlay(this.createMarker());
	map.addOverlay(this.createPolyline());
	map.addOverlay(this.createLabel());
	
	this.info = document.getElementById(name);
	this.infoMax = document.getElementById(name + "-max");
}

Project.prototype.update = function(zoom) {
	//
	var scale = Math.pow(2, (zoom - 2));
	var lat = this.location.lat() + (this.labelVector.lat() / scale);
	var lng = this.location.lng() + (this.labelVector.lng() / scale);
	this.labelLocation = new GLatLng(lat, lng);
	
	var labelPix = map.fromLatLngToDivPixel(this.labelLocation);
	var basePix = new GPoint(labelPix.x, labelPix.y + 31);
	
	this.labelBase = map.fromDivPixelToLatLng(basePix);
	
	if (this.visible && this.showLabel)
	{
		map.removeOverlay(this.polyline);
		map.addOverlay(this.createPolyline());
		this.label.setLatLng(this.labelBase);
	}
	
}

Project.prototype.showInfo = function()
{
	this.infoMax.insertBefore(bmapElement, this.infoMax.firstChild);
	bmapCenter = this.location;
	infoOptions = { maxContent:this.infoMax,
		maxTitle:"<p><b>" + this.title + "</b></p>",
		maxWidth:400 };
		
	this.marker.openInfoWindow(this.info, infoOptions);
}

Project.prototype.createMarker = function()
{
	var marker = new GMarker(this.location, { icon:this.pinIcon, title:this.title });
	var project = this;

	GEvent.addListener(marker, "click",
		function() { project.showInfo(); }
	);
	
	this.marker = marker;
	return marker;
}

Project.prototype.createLabel = function()
{
	var projectIcon = new GIcon(labelIcon);
	projectIcon.image = "images/map/" + this.name + "-icon.png";

	markerOptions = { icon:projectIcon, title:this.title, draggable:true, autoPan:false };
	var label = new GMarker(this.labelBase, markerOptions);
	var project = this;
	
	GEvent.addListener(label, "click", function()
		{
			setTimeout(function() { project.showInfo(); });
		}
	);
	
	GEvent.addListener(label, "dblclick",
		function() { }
	);
	
	GEvent.addListener(label, "dragstart",
		function() { map.removeOverlay(project.polyline); }
	);
	
	GEvent.addListener(label, "dragend", function()
		{
			project.labelBase = label.getLatLng();
			
			var basePix = map.fromLatLngToDivPixel(project.labelBase);
			var labelPix = new GPoint(basePix.x, basePix.y - 31);

			project.labelLocation = map.fromDivPixelToLatLng(labelPix);
			
			var scale = Math.pow(2, (map.getZoom() - 2));
			var lat = (project.labelLocation.lat() - project.location.lat()) * scale;
			var lng = (project.labelLocation.lng() - project.location.lng()) * scale;
			project.labelVector = new GLatLng(lat, lng);
			
			map.addOverlay(project.createPolyline());
		}
	);
	
	this.label = label;
	return label;
}

Project.prototype.createPolyline = function() {

  polyOptions = { clickable:false, geodesic:false };
  var poly = new GPolyline([this.location, this.labelLocation],
	"#000000", 1.5, 0.7, polyOptions);
	
	this.polyline = poly;
	
  return poly;
}

Project.prototype.setShowLabel = function(show)
{
	if (show != this.showLabel)
	{
		this.showLabel = show;
		if (this.visible)
		{
			if (show)
			{
				map.addOverlay(this.createPolyline());
				map.addOverlay(this.createLabel());
			}
			else
			{
				map.removeOverlay(this.polyline);
				map.removeOverlay(this.label);
			}
		}
	}
}

Project.prototype.setVisible = function(show)
{
	if (show != this.visible)
	{
		this.visible = show;
		if (show)
		{
			this.show()
		}
		else
		{
			this.hide()
		}
	}
}

Project.prototype.show = function()
{
	if (this.visible)
	{
		map.addOverlay(this.createMarker());
		if (this.showLabel)
		{
			map.addOverlay(this.createPolyline());
			map.addOverlay(this.createLabel());
		}
	}
}

Project.prototype.hide = function()
{
	if (! this.visible)
	{
		map.removeOverlay(this.marker);
		if (this.showLabel)
		{
			map.removeOverlay(this.polyline);
			map.removeOverlay(this.label);
		}
	}
}
