/*
Event Horizon Fight Statistics - World of Warcraft combat log parser and report generator
Copyright (C) 2008-2009 Maik Schreiber

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

function createTextToolTip(element) {
	element.addEvents({
		"mouseenter": function(event) {
			var x = event.page.x + 10;
			var y = event.page.y + 10;
			var tooltip = new Element("div", { "class": "toolTip" })
				.grab(new Element("div", { "class": "toolTip-title" })
					.appendText(element.getAttribute("toolTipTitle")))
				.grab(new Element("div", { "class": "toolTip-contents" })
					.appendText(element.getAttribute("toolTipText")))
				.setStyle("visibility", "hidden")
				.inject(document.body);
			var size = tooltip.getSize();
			var windowSize = window.getSize();
			x = Math.max(Math.min(x, windowSize.x - size.x - 5), 0);
			y = Math.max(Math.min(y, windowSize.y - size.y - 5), 0);
			tooltip.setStyles({
				"left": x,
				"top": y,
				"visibility": "visible"
			});
			element.store("tooltip", tooltip);
		},
		
		"mouseleave": function() {
			element.retrieve("tooltip").dispose();
		}
	});
}

function hideAllPets() {
	var els = $$("table");
	for (var i = 0; i < els.length; i++) {
		var el = els[i];
		if (el.id) {
			if (el.id.indexOf("pet_") == 0) {
				el.style.display = "none";
			}
		}
	}
}

function showPet(id) {
	hideAllPets();
	$("pet_" + id).style.display = "";
}

window.addEvent("domready", function() {
	$$(".hasToolTip").each(createTextToolTip);
});

