function Category(name, loader) {
	this.name = name;
	this.points = new Array();
	this.loader = loader;
	this.icon = null;
	this.loadQueue = new Array();
	this.visible = false;
	this.markers = new Array();
}

Category.OPACITY_VISIBLE = 1.0;
Category.OPACITY_HIDDEN = 1.0;
Category.OPACITY_LOADING = 1.0;
Category.ICON_WIDTH = 56;
Category.ICON_WIDTH = 96;
Category.MARKER_WIDTH = 20;
Category.MARKER_HEIGHT = 30;

Category.prototype.createIcon = function() {
	this.icon = document.createElement("img");
	this.icon.setAttribute("src", this.getIconUrl());
	Loader.setClass(this.icon, "categoryIcon");
	this.icon.setAttribute("title", "Click to show/hide " + this.points.length + " " + this.getName() + "s");
	this.icon.setAttribute("width", Category.ICON_WIDTH  + "px");
	this.icon.setAttribute("height", Category.ICON_HEIGHT  + "px");
	
	this.icon.category = this;

	YAHOO.util.Event.addListener(this.icon, "click", function() {
		if (this.category.visible)
			this.category.hide();
		else
			this.category.show();
	});

	YAHOO.util.Event.addListener(this.icon, "mouseover", function() {
		NYE.loader.setText("" + this.category.points.length + " <b>" + this.category.getName() + "s</b>");
		this.category.setMouseOverStyle();
	});

	YAHOO.util.Event.addListener(this.icon, "mouseout", function() {
		NYE.loader.setText("");
		this.category.setMouseOutStyle();
	});
}

Category.prototype.getName = function() {
	return this.name.replace("_", " ");
}

Category.prototype.addPoint = function(point) {
	this.points.push(point);
	this.loadQueue.push(point);
}

Category.prototype.getIconUrl = function() {
	return "icons/" + this.name + "_icon.png";
}

Category.prototype.getMarkerUrl = function(point) {
	if (NYE.showOnMapPoint == point)
		return "icons/showOnMap.png";
	else
		return "icons/" + this.name + ".png";
}

Category.prototype.setOpacity = function(opacity) {
	YAHOO.util.Dom.setStyle(this.icon, "opacity", opacity);
}

Category.prototype.getLatLng = function(point) {
	var lat = parseFloat(point.getAttribute("lat"));
	var lng = parseFloat(point.getAttribute("lng"));
	return new GLatLng(lat, lng);
}

Category.prototype.createMarker = function(point) {
	var icon = new GIcon(G_DEFAULT_ICON);
	icon.image = this.getMarkerUrl(point);
	icon.shadow = "icons/shadow.png";
	icon.iconSize = new GSize(Category.MARKER_WIDTH, Category.MARKER_HEIGHT);
	icon.shadowSize = new GSize(Category.MARKER_WIDTH, Category.MARKER_HEIGHT);
	icon.iconAnchor = new GPoint(5,29);
	var marker = new GMarker(this.getLatLng(point), {"icon":icon, "title":this.getName()});
	marker.point = point;
	marker.category = this;
	NYE.map.addOverlay(marker);
	if (NYE.showOnMapPoint == point) 
		NYE.showOnMapMarker = marker;
	if (!this.visible)
		marker.hide();
	this.markers.push(marker);

	GEvent.addListener(marker, "click", function() {
		NYE.info.open(this);
	});
}

Category.getPointPosition = function(point) {
	for (var i=0; i<NYE.points.length; i++ ) {
		if (NYE.points[i] == point) 
			return i + 1;
	}
	return -1;
}

Category.prototype.setMouseOverStyle = function() {
	YAHOO.util.Dom.setStyle(this.icon, "border", "1px " + (this.visible ? "solid #ffffff" : "dashed #ffffff"));
	YAHOO.util.Dom.setStyle(this.icon, "margin", "0px");
	YAHOO.util.Dom.setStyle(this.icon, "cursor", "pointer");
}

Category.prototype.setMouseOutStyle = function() {
	YAHOO.util.Dom.setStyle(this.icon, "border", "");
	YAHOO.util.Dom.setStyle(this.icon, "margin", "");
	YAHOO.util.Dom.setStyle(this.icon, "cursor", "");
}

Category.prototype.hide = function() {
	for (var i=0; i<this.markers.length; i++ ) {
		this.markers[i].hide();
	}
	this.visible = false;
	this.setOpacity(Category.OPACITY_HIDDEN);
	this.setMouseOverStyle();
}

Category.prototype.show = function() {
	for (var i=0; i<this.markers.length; i++ ) {
		this.markers[i].show();
	}
	this.visible = true;
	this.setOpacity(Category.OPACITY_VISIBLE);
	this.setMouseOverStyle();
}