//-- Map Structure Classes -------------------------------------------
if(!Terrascape) {
	var Terrascape = {};
}
Terrascape.MapData = {};
Object.extend(Terrascape.MapData, {
	initialize: function() {
		this.Mapper = null;
		this.Parent = window;
		this.LoadLabels = null;
		this.categories = [];
		this.rasterImages = [];
		this.zoomRanges = [];
	},

	getLayer: function(id) {
		for(var i=0; i<this.categories.length; ++i) {
			for(var ii=0; ii<this.categories[i].layers.length; ++ii) {
				if(this.categories[i].layers[ii].id == id) {
					return this.categories[i].layers[ii];
				}
			}
		}
		return null;
	},

	getLayersScaledAt: function(scale) {
		var layers = [];
		for(var i = 0; i < this.categories.length; ++i) {
			for(var ii = 0; ii < this.categories[i].layers.length; ++ii) {
				if(this.categories[i].layers[ii].minScale >= scale) {
					layers.add(this.categories[i].layers[ii]);
				}
			}
		}
		return layers;
	},

	getLabelsScaledAt: function(scale) {
		var layers = [];
		for(var i = 0; i < this.categories.length; ++i) {
			for(var ii = 0; ii < this.categories[i].layers.length; ++ii) {
				if(this.categories[i].layers[ii].labelMinScale >= scale) {
					layers[layers.length] = this.categories[i].layers[ii];
				}
			}
		}
		return layers;
	},

	getLayersNotScaledAt: function(scale) {
		var layers = [];
		for(var i = 0; i < this.categories.length; ++i) {
			for(var ii = 0; ii < this.categories[i].layers.length; ++ii) {
				if(this.categories[i].layers[ii].minScale != -1 && this.categories[i].layers[ii].minScale < scale) {
					layers[layers.length] = this.categories[i].layers[ii];
				}
			}
		}
		return layers;
	},

	getLabelsNotScaledAt: function(scale) {
		var layers = [];
		for(var i = 0; i < this.categories.length; ++i) {
			for(var ii = 0; ii < this.categories[i].layers.length; ++ii) {
				if(this.categories[i].layers[ii].labelMinScale != -1 && this.categories[i].layers[ii].labelMinScale < scale) {
					layers[layers.length] = this.categories[i].layers[ii];
				}
			}
		}
		return layers;
	}
});

Terrascape.Category = Class.create();
Terrascape.Category.prototype = {
	initialize: function(id, name, display) {
		this.id = id;
		this.name = name;
		this.display = display;
		this.layers = [];
	},

	getLayer: function(id) {
		for(var i = 0; i < this.layers.length; ++i) {
			if(this.layers[i].Id == id) {
				return this.layers[i];
			}
		}
		return null;
	}
};

Terrascape.Layer = Class.create();
Terrascape.Layer.prototype = {
	initialize: function(id, name, icon, visible, size, field, minScale, labelMinScale) {
		this.id = id;
		this.name = name;
		this.visible = visible;
		this.size = size;
		this.field = field;
		this.icon = icon;
		this.minScale = minScale;
		this.labelMinScale = labelMinScale;

		this.layersLoaded = false;
		this.labelsLoaded = false;

		this.fields = [];
		this.ranges = [];
		this.points = null;
	},

	getField: function(name) {
		for(var i = 0; i < this.fields.length; ++i) {
			if(this.fields[i].name == name) {
				return this.fields[i];
			}
		}
		return null;
	}
};

Terrascape.Field = Class.create();
Terrascape.Field.prototype = {
	initialize: function(name, display) {
		this.name = name;
		this.display = display;
	}
};

Terrascape.Range = Class.create();
Terrascape.Range.prototype = {
	initialize: function(name, icon) {
		this.name = name;
		this.icon = icon;
	}
};

Terrascape.RasterImage = Class.create();
Terrascape.RasterImage.prototype = {
	initialize: function(id, name, x, y, width, height) {
		this.id = id;
		this.name = name;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.visible = false;
		this.loaded = false;
	},

	show: function(mapDisplay) {
		if(!this.loaded) {
			var image = mapDisplay.getShape(this.id);
			image.x = this.x - mapDisplay.bounds.x;
			image.y = mapDisplay.bounds.y - this.y;
			image.width = this.width;
			image.height = this.height;
			image.src = "image.aspx?object=rasters&action=image&id=" + this.id + "&rnd=" + Math.random();
			mapDisplay.applyShape(image);
			this.loaded = true;
		}
		mapDisplay.setLayerVisibility("r" + this.id, true);
		this.visible = true;
	},

	hide: function(mapDisplay) {
		mapDisplay.setLayerVisibility("r" + this.id, false);
		this.visible = false;
	}
};

Terrascape.ZoomRange = Class.create();
Terrascape.ZoomRange.prototype = {
	initialize: function(id, name, x0, y0, x1, y1) {
		this.id = id;
		this.name = name;
		this.x0 = x0;
		this.y0 = y0;
		this.x1 = x1;
		this.y1 = y1;
	}
};

