/*
Name: Domtooltips
URI: http://rubensargsyan.com/domtooltips/
Author: Ruben Sargsyan
Author URI: http://rubensargsyan.com/
Version: 1.0
Created: 18.11.2009

Domtooltips by Ruben Sargsyan is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
*** modified by sophisco/ah to allow highlighting of table cells with the class "explanatory" ***
*/
function load_domtooltips(){
    all_spans = document.getElementsByTagName("span");

    if(all_spans.length>0){
        for(var i=0; i<all_spans.length; i++){
            /* section modified by sophisco to improve training schedule */
            if(all_spans[i].className.indexOf("domtooltips")>-1){
                if(all_spans[i].parentNode.className.indexOf("domtooltips")==-1){

                    if(all_spans[i].parentNode.className.indexOf("explanatory")>-1){
                        domparentnode = all_spans[i].parentNode
                        temptooltipsspan = all_spans[i].cloneNode(false);
                        all_spans[i].removeAttribute("title");
                        temptooltipsspan.innerHTML = domparentnode.innerHTML;
                        domparentnode.innerHTML = "";
                        domparentnode.appendChild(temptooltipsspan);
                        domtooltipsspan = domparentnode.firstChild;

                    } else {
                        domtooltipsspan = all_spans[i];
                    }
                    /* end of the first change in modified section*/
                    domtooltipsspan.id = "domtooltipsspan"+i;

                    domtooltipsspan.onmouseover = function(event){
                        domtooltipsdiv = document.createElement("div");
                        domtooltipsdiv.className = "domtooltips_tooltip";
                        domtooltipsdiv.innerHTML = this.title;
                        this.title = "";

                        var e = event || window.event;

                        mouse_position = get_mouse_position(e);

                        domtooltipsdiv.style.left = (mouse_position.x+15) + "px";
                        domtooltipsdiv.style.top = (mouse_position.y+15) + "px";

                        document.body.appendChild(domtooltipsdiv);

                        /* beginning of the second change in modified section*/
						var currentclass = this.className;
						var selectedclass = currentclass.replace("domtooltips", "domtooltip-selected")
                        for(var i=0; i<all_spans.length; i++){
                            if(all_spans[i].className==currentclass){
                                all_spans[i].className = selectedclass;
						    }
						}
                        /* end of the second change in modified section*/
                    };

                    domtooltipsspan.onmouseout = function(){
                        this.title = domtooltipsdiv.innerHTML;
                        document.body.removeChild(domtooltipsdiv);

                        /* beginning of the third change in modified section*/
						var currentclass = this.className;
						var unselectedclass = currentclass.replace("domtooltip-selected", "domtooltips")
                        for(var i=0; i<all_spans.length; i++){
                            if(all_spans[i].className==currentclass){
                                all_spans[i].className = unselectedclass;
						    }
						}
                        /* end of the third change in modified section*/
                    };

                } else {

                    /* fourth change in modified section*/
                    all_spans[i].removeAttribute("title");

                }

            }
            /* end of modified section */
        }
    }
}

function get_mouse_position(e){
    return e.pageX ? {'x':e.pageX, 'y':e.pageY} : {'x':e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft, 'y':e.clientY + document.documentElement.scrollTop + document.body.scrollTop};
}
