//###########################################################################
//# js.tooltip.js
//###########################################################################
//# display tooltip instead of alt
//###########################################################################
Tooltip = function(){ 
    if (!document.body.getAttribute) return false; 
	this.tooltip = this.createTipbox();
    this.offsetX = this.offsetY = 10; 
    if (document.getElementsByTagName) 
    { 
        this.init(document.getElementsByTagName("a")); 
        this.init(document.getElementsByTagName("img")); 
        this.init(document.getElementsByTagName("div")); 
        this.init(document.getElementsByTagName("span")); 
        this.init(document.getElementsByTagName("input"));
		this.init(document.getElementsByTagName("label"));
    } 
} 
Tooltip.prototype.createTipbox = function()
{
	var box=document.createElement("div");
	// box ¼Ó¼º.. (style)
	box.style.display = "none";
	box.style.position = "absolute";
	box.style.fontFamily = "»õ±¼¸²";
	box.style.fontSize = "9pt";
	box.style.lineHeight = "170%";
	box.style.padding = "3px";
	box.style.borderStyle = "solid";
	box.style.borderWidth = "1px";
	box.style.borderColor = "black";
	box.style.backgroundColor = "white";
	box.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";

	document.body.appendChild(box);
    return box;
}
Tooltip.prototype.setAlpha = function(alpha)
{
	this.tooltip.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + alpha + ")";
}
Tooltip.prototype.init = function(){ 
    Tooltip.object = this; 
    Tooltip.element = null; 
    for (var i=0, s=arguments[0].length; i<s; i++) 
    { 
        Tooltip.element = arguments[0][i]; 
        if (arguments[0][i].getAttribute("tip") !== null) 
        { 
            arguments[0][i].onmouseover = function(){ 
                Tooltip.object.show(event.srcElement, event.x, event.y); 
            } 
            arguments[0][i].onmousemove = function(){ 
                Tooltip.object.move(event.x, event.y); 
            } 
            arguments[0][i].onmouseout = function(){ 
                Tooltip.object.hide(); 
            } 
        } 
    } 
} 
Tooltip.prototype.show = function(source, x, y) 
{ 
    this.tooltip.innerHTML = source.getAttribute("tip"); 
    this.tooltip.style.display = "inline"; 
    this.move(x,y); 
} 
Tooltip.prototype.move = function(x, y) 
{ 
    var width = this.tooltip.clientWidth; 
    var height = this.tooltip.clientHeihgt; 
    var cx = document.body.clientWidth; 
    var cy = document.body.clientHeight; 
    var sy = document.body.scrollTop; 
    var tx = x + this.offsetX; 
    var ty = y + this.offsetY + sy; 
    if (tx + width >= cx) tx -= (tx + width - cx); 
    if (ty + height >= cy + sy) ty -= (ty + height - (cy+sy)); 
    
    this.tooltip.style.left = tx; 
    this.tooltip.style.top = ty; 
} 
Tooltip.prototype.hide = function() 
{ 
    this.tooltip.innerHTML = ""; 
    this.tooltip.style.display = "none"; 
}
