var Space = function(name, description, latitude, longitude, zoom) {
	this.type = "SPACE"
	this.name = name;
	this.description = description;
	this.latitude = latitude;
	this.longitude = longitude;
	this.zoom = zoom;
	this.children = [];
	this.parent = null;
	this.draggable = false;
	this.icon = null;
	this.renderProjectMarkers = false;
}

Space.prototype = new Object();
		
Space.prototype.addChild = function(child) {
	this.children.push(child);
	child.parent = this;
}

Space.prototype.isSibling = function(space) {
	var sibling = false;
	if(space.parent.name == this.parent.name) {
		sibling = true;
	}
	return sibling;
}

Space.prototype.getAllProjects = function(projects) {
	var i=0;
	while(this.children != null && i<this.children.length) {
		var child = this.children[i];			
		if(child.type == "PROJECT") {
			projects.push(child);
		} 
		child.getAllProjects(projects);
		i++;
	}		
}

Space.prototype.getSpaces = function(spaces) {
	spaces.push(this);
	var i=0;
	while(this.children != null && i<this.children.length > 0) {
		var child = this.children[i];
		child.getSpaces(spaces);
		i++;
	}
}

Space.prototype.getSiblings = function() {		
	return (this.parent != null) ? this.parent.children : null;
}

Space.prototype.getCity = function() {
	if(this.type === "CITY") return this;
	else {
		return (this.parent != null) ? this.parent.getCity() : null;
	}
}

Space.prototype.toString = function() {
	if(this.type != "PROJECT") {
		var str = "<div style='font-family: Arial;font-size:11pt;color:#000;font-weight:bold'><strong>" + this.name + "</strong></div>";
		return str;
	} else {
		var str = "<div style='font-family: Arial;font-size:10pt;color:#000'>Name: " + this.name + "\n\n<br/><br/>";
		str += "Address: " + this.address + "\n<br/>";
		//str += "Area: " + this.area + "\n<br/>"; 
		str += "Development Period: " + this.period + "\n<br/>";
		str += "Sale Status: " + this.salesStatus + "\n<br/>";
		if(this.url != "#") {
			str += "<a href=\"#\" onClick=\"openFullScreenWindow('" + this.url + "')\">Click for project details</a>";
		}
		str += "</div>";
		return str;
	}
}

Space.prototype.debug = function() {
	var str = "Name: " + this.name + "\n\n<br/><br/>";
	str += "Type: " + this.type + "\n<br/>";
	str += "Description: " + this.description + "\n<br/>";
	str += "Latitude: " + this.latitude + "\n<br/>";
	str += "Longitude: " + this.longitude + "\n<br/>";
	str += "Zoom: " + this.zoom;
	return str;
}
