var ready = false;
function Item(id, name, os, lat, lng, location, displayDate, category, era) {
	this.id = id;
	this.name = name;
	this.os = os;
	if (lat == 0) {
		var osref = getOSRefFromSixFigureReference(this.os);
		var latlng = osref.toLatLng();
		this.lat = latlng.lat;
		this.lng = latlng.lng;
		}
	else {
		this.lat = lat;
		this.lng = lng;
		}
	this.location = location;
	this.displayDate = displayDate;
	this.category = category;
	this.era = era;
	this.marker = null;
	this.engineers = new Array();

	this.addEngineer = ItemAddEngineer;
	this.getEngineerNames = ItemGetEngineerNames;
	this.select = ItemSelect;
	this.deselect = ItemDeselect;
	this.open = ItemOpen;
	this.setArrow = ItemSetArrow;
	this.getPoint = ItemGetPoint;
	this.getMarker = ItemGetMarker;
	this.getHTML = ItemGetHTML;
}
function ItemSelect(fromList) {
	if (!ready) return;
	if (fromList) {
		// var arrow = getStyleObject(this.arrowName);
		// arrow.left = this.arrowX;
		// arrow.top = this.arrowY;
		// arrow.visibility = 'visible';
		}
	var html = this.getHTML();
	this.marker.openInfoWindowHtml(html);
	window.status = this.name;
	return true;
}
function ItemDeselect() {
	window.status = '';
	// getStyleObject(this.arrowName).visibility = 'hidden';
	// this.marker.closeInfoWindow();
	return true;
}
function ItemOpen() {
	// openCC(this.id);
	window.location = "../scripts/engineeringItem.asp?id=" + this.id;
}
function ItemSetArrow(name, x, y) {
	this.arrowName = name;
	this.arrowX = x;
	this.arrowY = y;
}
function ItemGetPoint() {
	return new GLatLng(this.lat, this.lng);

}
function ItemGetMarker() {
	if (this.marker == null) {
		var marker = new GMarker(this.getPoint());
		marker.item = this;
		var html = this.getHTML();
		GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html);});
		GEvent.addListener(marker, "click", function() {marker.item.open();});
		this.marker = marker;
		}
	return this.marker;
}
function ItemGetEngineerNames() {
	var result = "";
	for (i = 0; i < this.engineers.length; i++)
		result += "<span class='itemEngName'>" + this.engineers[i] + "</span><br />"
	return result;
}

function ItemGetHTML() {
	return "<div class='ItemName'>" + this.name + "</div>" +
		"<div class='ItemLocation'>" + this.location + "</div>" +
		"<div class='ItemEngineer'><span class='ItemCategory'>associated engineer</span><br />" + this.getEngineerNames() + "</div>" +
		"<div class='ItemData'>" +
			"<span class='ItemCategory'>date</span> &nbsp;" + this.displayDate + "<br />" +
			"<span class='ItemCategory'>era</span> &nbsp;" + this.era + " &nbsp;|&nbsp;" +
			"<span class='ItemCategory'>category</span> &nbsp;" + this.category + " &nbsp;|&nbsp;" +
			"<span class='ItemCategory'>OS grid reference</span>&nbsp;" + this.os +
		"</div>";
}
function ItemAddEngineer(engineerName) {
	this.engineers.push(engineerName);
}
var items = new Array();
var item = null;
var batch = new Array();
