item_cache = new Array();
var currentItem;

function set_item_text(s) {
    theDiv.innerHTML = s;
}

function show_item(obj,id) {
    if(!ns6 && !ie) return;

    currentItem = id;
    
    

    theBody = document.getElementsByTagName('body')[0];
    theDiv = document.getElementById('tbitem');
    
    obj = theBody;

    if(!theDiv) {
        theDiv = document.createElement("div");
        theDiv.setAttribute("id", "tbitem");
        theBody.appendChild(theDiv);

        if (ie || ns6)
            tipobj=document.all? document.all["tbitem"] : document.getElementById? document.getElementById("tbitem") : "";
    }

    if(item_cache[id]) {
        enabletip = true;
        theDiv.style.display = "";
        set_item_text(item_cache[id]);
        return;
    }

    // if we got this far, we are fetching a new item

    enabletip = true;
    theDiv.style.display = "";
    set_item_text('<div style="background-color: #000;padding:.5em;">Loading...</div>');

    var responseSuccess = function(o) {
        item_cache[id] = o.responseText;

        // don't display this new item if there has been a mouseover since the request started
        if(o.argument == currentItem) {
            set_item_text(item_cache[id]);
        }
    }

    var responseFailure = function(o) {
        theDiv.innerHTML = "Failure.";
    }

    var callback = {
        success: responseSuccess,
        failure: responseFailure,
        argument: id
    }

    var url = 'item.php?id='+id;
    YAHOO.util.Connect.asyncRequest('GET',url,callback,null);
}

function hide_item() {
    if(!ns6 && !ie) return;

    enabletip = false;

    theDiv = document.getElementById('tbitem');
    theDiv.style.display = "none";
}

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=10; //Customize x offset of tooltip
var offsetypoint=10; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;

var tipobj;

if (ie || ns6)
    var tipobj=document.all? document.all["tbitem"] : document.getElementById? document.getElementById("tbitem") : "";

function ietruebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function positiontip(e){
    if (enabletip) {
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;

        //Find out how close the mouse is to the corner of the window
        var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
        var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;

        var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<tipobj.offsetWidth)
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
        else if (curX<leftedge)
            tipobj.style.left="5px";
        else
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left=curX+offsetxpoint+"px";

        //same concept with the vertical position
        //if (bottomedge<tipobj.offsetHeight)
        //    tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
        //else
            tipobj.style.top=curY+offsetypoint+"px";

        tipobj.style.visibility="visible";
    }
}

document.onmousemove=positiontip;

/* END DYNAMIC DRIVE */
