/**
 * 
 * @param aMap
 * @return
 */
function EventPlace(aMap)
{
	this.map = aMap;
	
	this.id;
	this.name;
	this.type;
	this.url;
	this.marker;
	this.googlepoint;
	this.events = [];
	this.sb = new StringBuffer();
	
	this.disabled = false;
}

EventPlace.prototype.id;
EventPlace.prototype.name;
EventPlace.prototype.type;
EventPlace.prototype.url;
EventPlace.prototype.marker;
EventPlace.prototype.disabled;

EventPlace.prototype.getId = function()
{
	return this.id;
}

EventPlace.prototype.getName = function()
{
	return this.name;
}

EventPlace.prototype.getType = function()
{
	return this.type;
}

EventPlace.prototype.getUrl = function()
{
	return this.url;
}

EventPlace.prototype.getMarker = function()
{
	return this.marker;
}

EventPlace.prototype.getMap = function()
{
	return this.map;
}

EventPlace.prototype.construct = function(pid, pname, ptype, purl, pshowurl, googlepoint)
{
	this.id = pid;
	this.name = pname;
	this.type = ptype;
	this.url = purl;
	this.googlepoint = googlepoint;
	this.marker =  new google.maps.Marker({
		position: createMarker(googlepoint)[0],
		map : this.map,
		icon : im.getIcon(this.type),
		shadow : im.getShadow(this.type)
	}); 
	
	var sb = new StringBuffer();
	this.sb.append("<DIV STYLE='width:400px;height:100px'><DIV STYLE='overflow:auto;width:400px;height:100px'>")
	this.sb.append("<table><tr><td valign='top'>")
	this.sb.append("<img src='/images/icons/"+this.type+".png' align='left'/>");
	this.sb.append("<b>"+this.name+"</b>");
	this.sb.append(" <a href='"+pshowurl+"'>view</a>");
	if (this.url)
	{
		this.sb.append(", <a href='http://"+this.url+"'>www</a>");
	}
	this.sb.append("</td></tr></table>");
	
	var mark = this.marker;
	var mmap = this.map;
	var infowindow = new google.maps.InfoWindow({
	    content: sb.toString()
	});
	google.maps.event.addListener(mark, 'click', function() {
	 	infowindow.open(mmap, mark);
	});
};

/**
 * Add an Event row to the Place. An Event can be in more than one place, and a Place
 * can have more than one event. Because only Places are spatial in nature (directly),
 * we only want to place one Place on the map and show all Events through it, the 
 * reverse of the hierarchy.
 * 
 * @param eid
 * @param etitle
 * @param etype
 * @param ewhen
 * @param eurl
 */
EventPlace.prototype.addEvent = function(eid, etitle, etype, ewhen, eurl)
{
	var event = new Event(true);
	event.construct(eid, etitle, etype, ewhen, eurl);
	
	this.events.push(event);
	
	var table = new StringBuffer();
	table.append(this.sb.toString());
	
	table.append("<table>");
	table.append("<th>Event</th>");
	table.append("<th>Type</th>");
	table.append("<th>When</th></tr>");
	var len = this.events.length;
	for (var i = 0; i < len; i++)
	{
		table.append("<tr><td><a href='"+this.events[i].eurl+"'>"+this.events[i].etitle+"</a></td>");
		table.append("<td>"+this.events[i].etype+"</td>");
		table.append("<td>"+this.events[i].ewhen+"</td></tr>");
	}
	table.append("</table></div>");	
	
	var mark = this.marker;
	var mmap = this.map;
	var infowindow = new google.maps.InfoWindow({
	    content: table.toString()
	});
	google.maps.event.addListener(mark, 'click', function() {
	 	infowindow.open(mmap, mark);
	});
};
