function Info(infoDom) {
	this.dom = infoDom;
	this.map = null;
	this.clicker = null;
	this.content = null;
	this.visible = true;
	this.animation = null;
	this.click_in = new Image();
	this.click_out = new Image();
	this.current = null;
}

Info.prototype = new GControl();
Info.HIDDEN_X = -296;

Info.prototype.initialize = function(map) {
	this.map = map;
	this.map.getContainer().appendChild(this.dom);
	this.content = document.getElementById("infoContent");
	this.clicker = document.getElementById("Clicker");
	YAHOO.util.Event.addListener(this.clicker, "click", function() {
		NYE.info.toggle();
	});
	YAHOO.util.Event.addListener(this.dom, "click", function(e) {
		NYE.info.hide();
	});
	YAHOO.util.Dom.setStyle(this.dom, "opacity", 0.95);
	YAHOO.util.Dom.setStyle(this.content, "display", "none");
	this.click_in.src = "img/click_in.png";
	this.click_out.src = "img/click_out.png";
	this.visible = false;
	return this.dom;
}

// Remove the main DIV from the map pane
Info.prototype.remove = function() {
	this.dom.parentNode.removeChild(this.dom);
}

Info.prototype.redraw = function(force) {
	if (!force) return;
}

Info.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(Info.HIDDEN_X, -4)); // -292
}

Info.prototype.toggle = function() {
	if (this.visible) 
		this.hide();
	else
		this.show();
}

Info.prototype.show = function() {
	if (this.visible) return;

	if (this.content.childNodes.length == 0) {
		NYE.loader.flashText("<b>This is no info to currently show. Select a map marker to view more info.</b>");
		this.animation = new YAHOO.util.Anim(this.clicker);
		this.animation.attributes.opacity = {to: 0.5};
		this.animation.duration = 0.25;
		this.animation.method = YAHOO.util.Easing.easeOut;
		this.animation.onComplete.subscribe(function() {
			NYE.info.animation = new YAHOO.util.Anim(NYE.info.clicker);
			NYE.info.animation.attributes.opacity = {to: 1.0};
			NYE.info.animation.duration = 0.25;
			NYE.info.animation.method = YAHOO.util.Easing.easeOut;
			NYE.info.animation.onComplete.subscribe(function() {
				
			});
			NYE.info.animation.animate();
		});
		this.animation.animate();
		return;
	}

	if (this.animation != null) {
		if (this.animation.isAnimated()) 
			this.animation.stop(true);
	}

	this.clicker.src = this.click_in.src;
	YAHOO.util.Dom.setStyle(this.content, "display", "");
	YAHOO.util.Dom.setStyle(this.dom, "right", "0px");
	this.visible = true;
}

Info.prototype.hide = function() {
	if (!this.visible) return;
	this.clicker.src = this.click_out.src;
	YAHOO.util.Dom.setStyle(this.content, "display", "none");
	YAHOO.util.Dom.setStyle(this.dom, "right", Info.HIDDEN_X + "px");
	//setTimeout("YAHOO.util.Dom.setStyle(NYE.info.dom, 'display', '');", 5);
	this.visible = false;
}

Info.prototype.open = function(marker) {
	if ((marker == this.current) && (this.visible == true)) {
		this.hide();
		return;
	}
	var nodes = marker.point.selectNodes("*");
	this.clearContainer();
	if (marker.point.childNodes.length == 0) {
		this.addTitle(marker.category.getName());
		this.addLine(null, "There is no additional information to display for this point.");
		this.addLine(null, "Click to close this panel.");
	} else {
		for (var i=0; i<nodes.length; i++ ) {
			var name = nodes[i].nodeName.replace(/_/g, " ");
			var text = XmlUtil.getText(nodes[i]);
			if (name == "Title") {
				this.addTitle(text);
			} else {
				this.addLine(name, text);
			}
		}
	}
	this.current = marker;
	this.show();
}

Info.prototype.addTitle = function(text) {
	var line = document.createElement("div");
	Loader.setClass(line, "infoLine");
	this.content.appendChild(line);

	var title = document.createElement("span");
	Loader.setClass(title, "infoTitle");
	title.innerHTML = text;
	line.appendChild(title);

	var close = document.createElement("a");
	Loader.setClass(close, "infoClose");
	close.innerHTML = "[close]";
	YAHOO.util.Event.addListener(close, "click", function() {
		NYE.info.toggle();
	});
	line.appendChild(close);

	var hr = document.createElement("hr");
	Loader.setClass(hr, "infoHR");
	line.appendChild(hr);
}

Info.prototype.addLine = function(name, text) {
	var line = document.createElement("div");
	Loader.setClass(line, "infoLine");
	this.content.appendChild(line);
	
	if (name != null) {
		var fieldName = document.createElement("span");
		Loader.setClass(fieldName, "infoFieldName");
		fieldName.innerHTML = name;
		line.appendChild(fieldName);
	}

	var fieldText = document.createElement("span");
	Loader.setClass(fieldText, "infoFieldText");
	var infoText = text;
	infoText = infoText.replace(/(www.[^\s]+)/g, "<a href='http://$1'>$1</a>");
	fieldText.innerHTML = infoText;
	line.appendChild(fieldText);
}

Info.prototype.clearContainer = function() {
	while (this.content.childNodes.length > 0) {
		this.content.removeChild(this.content.childNodes[0]);
	}
}