YAHOO.namespace("ich.ToolTip");

function tipInit() {
	YAHOO.ich.ToolTip.teamTip = new YAHOO.widget.Overlay("teamTip", {context: ["tip-1001", "tl", "br"],
																					  visible:false,
																					  width:"250px" } );
	YAHOO.ich.ToolTip.teamTip.render();

    YAHOO.ich.ToolTip.manager = new YAHOO.widget.OverlayManager();
    YAHOO.ich.ToolTip.manager.register([YAHOO.ich.ToolTip.teamTip]);
	
    allTips = YAHOO.util.Dom.getElementsByClassName("teamTipClass", "img");
	         
    for (i = 0; i < allTips.length; i++)
    {
		YAHOO.util.Event.addListener(allTips[i].id, "click", showTip, YAHOO.ich.ToolTip.teamTip, true);
	}
}

YAHOO.util.Event.addListener(window, "load", tipInit);
		
var tipShow = false;
var currentTeam;
		
function showTip(e, obj)
{
	tip = YAHOO.util.Dom.get("teamTip");
	tip.innerHTML = "<div style=\"background: #546678; color: #fff; font: bold 12px Verdana; padding: 2px; text-align:left;\">Loading ...</div>";
	 
	obj.cfg.setProperty("context", [YAHOO.util.Event.getTarget(e, 1).id, "tl", "br"]);
		  
	var splitId = YAHOO.util.Event.getTarget(e, 1).id.split("-");

    var transaction = YAHOO.util.Connect.asyncRequest('GET', '/college/basketball/teamTips/' + splitId[1] + '.html', tipCallback, null); 
          
	hideTips();
	obj.show();

    if (!document.all) {
    	YAHOO.util.Event.addListener(window, "click", hideTips);
    } else {
    	YAHOO.util.Event.addListener(document, "click", hideTips);
    }
		  
	tipShow = true;
}
		
var tipResponseSuccess = function(o){
	tip = YAHOO.util.Dom.get("teamTip");
	tip.innerHTML = o.responseText;
};

var tipResponseFailure = function(o){
    tip = YAHOO.util.Dom.get("teamTip");
	tip.innerHTML = "<div style=\"background: #546678; color: #fff; font: bold 12px Verdana; padding: 2px; text-align:left;\">An Error has occured: " + o.status + "</div>";
}

var tipCallback =
{
	success:tipResponseSuccess,
  	failure:tipResponseFailure
};
		
function hideTips()
{
	if (!tipShow)
	{
    	YAHOO.ich.ToolTip.manager.hideAll();
    	if (!document.all) {
        	YAHOO.util.Event.removeListener(window, "click", hideTips);
        } else {
        	YAHOO.util.Event.removeListener(document, "click", hideTips);
        }
	}
	
	tipShow = false;
}
