/*
 *	ツールチップクラス (要 jQuery)
 *
 *	Hirotaka Yamashita.
 *	2011-04-26.
 */
function Tooltip () {	}

Tooltip.prototype = {
	//////////////////////////////////////////////////////////////////////
	//	ツールチップ本体
	//////////////////////////////////////////////////////////////////////
	tooltip: function (elm, id, width, height, pos) {


		if ((typeof width) == "undefined") {
			width = 180;
		}
		if ((typeof height) == "undefined") {
			height = 45;
		}
		if ((typeof pos) == "undefined") {
			pos = 'b';
		} else {
			pos = pos.toLowerCase ();
		}

		var hint = $('div.' + id);

		switch (pos) {
		case 't':
			$(hint).css('margin-bottom', '8px');
			break;
		case 'l':
			$(hint).css('margin-right', '8px');
			break;
		case 'r':
			$(hint).css('margin-left', '8px');
			break;
		default:
			$(hint).css('margin-top', '8px');
			break;
		}

		$(function () {
			$(elm).hover (
				function (ev) {
					texts = $(this).attr('title');
					$(this).attr('title', '');
					$(hint).text(texts);
					var hintW = 180;
					var hintH = $(hint).height();
					var y = $(this).offset().top + height - 5;
					var x = $(this).offset().left;
					switch (pos) {
						case 't':
							y = $(this).offset().top - hintH - 25;
							break;
						case 'l':
							var y = $(this).offset().top;
							var x = $(this).offset().left - width;
							break;
						case 'r':
							var y = $(this).offset().top;
							var x = $(this).offset().left + width;
							break;
						default:
							break;
					}

					$(hint).stop(true,true)
    		         .css({display: 'block', position: 'absolute', top: y, left: x});

				},
				function (ev) {
					$(hint).css('display', 'none');
					$(this).attr('title', texts);
				}
			);
		});
	}
}

