﻿// script for tooltips on windows internet-explorer beta

// initially hide all tooltips
document.write('<style type="text/css">.tooltip{display:none;}</style>');

// global variables
var AllTriggers=new Array();
var timer;

// milliseconds allowed before tooltip dissapears
var timerInterval=1;

// onload function to prepare the image triggers of the tooltips
function prepareToolTips(){
    if(!document.getElementsByTagName)return;
    
    var divs=document.getElementsByTagName("div");
    if(divs){
        var triggers=new Array();
        var tooltips=new Array();
        
        // loop through all designated divs, assumes they are consecutive
        for(var i=0;i<divs.length;i++){
            var div=divs[i];
            if(div.className=="tooltip-container"){
                var link=div.getElementsByTagName("a")[0];
                link.onclick = function() { return false };
                // pushes all images in the tables to the triggers and AllTriggers arrays
                triggers.push(link);
                AllTriggers.push(link);

                var popup=div.getElementsByTagName("div")[0];
                // pushes the tooltip to the tooltips and AllTriggers arrays
                tooltips.push(popup);
                AllTriggers.push(popup);
            }
        }
        for(var i=0;i<triggers.length;i++){
        
            // trigger is the link that triggers the tooltip
            var trigger=triggers[i];
            var tooltip=tooltips[i];
            
            // sets events on triggers and tooltips
            trigger.onmouseover=function(){
                toggleTooltip(this, true);
            }
            trigger.onmousemove=function(){
                toggleTooltip(this, true);
            }
            trigger.onmouseout=function(){
                toggleTooltip(this, false);
            }
            tooltip.onmouseover=function(){
                clearTimeout(timer);
            }
            tooltip.onmouseout=function(){
                toggleTooltip(null, false, this);
            }
        }
    }
}

// function which takes in an link trigger, whether or not you are on the trigger, and an optional tooltip itself if no trigger image is provided
function toggleTooltip(trigger,On,tooltip){
    if(trigger!==null){
        var tooltip=trigger.parentNode.nextSibling;
        if(tooltip.className !== "tooltip"){
            tooltip=tooltip.nextSibling;
        }
    }
    if(On){
        tooltip.style.display='block';
    }else{
        // sets a timeout to hide the tooltip
        timer=setTimeout(function(){offTrigger(tooltip)},timerInterval);
    }
}

// function to hide the tooltip, if showTooltip is false
function offTrigger(tooltip){
    tooltip.style.display='none';
}

// Loadevent handler to stack multiple window.onload events
function addLoadEvent(func){
    var oldonload = window.onload;  
    if (typeof window.onload != 'function'){
	    window.onload = func;
	}
    else{
	    window.onload = function(){
		    oldonload(); func()
		} 
	} 
}

// calls prepareToolTips on page load
addLoadEvent(prepareToolTips);