﻿$(document).ready(function () {
    $.get("/ncee/wwc/handlers/GlossaryHandler.ashx", 
        function (data) { GlossaryHighlight(data, "hover"); }  //On success, execute this function with returned data
        );
});
function GlossaryHighlight(data, event) {
    try {
        var options = {
            exact: "partial",
            style_name_suffix: false,
            keys: data
        }

        var rtn = $(document).SearchHighlight(options);

        if (event == "hover") {
            //Trigger definition on hover of span
            $(".hilite").hover(
                    function () {  //what to do when cursor enters object
                        var wrd = this;  //this = highlighted text being hovered
                        var selWord = $(this).text();
                        var attr = $(wrd).attr('title');

                        if (typeof attr == 'undefined' || attr == false || attr == "")  //only hit the database the first time the word needs defined
                        {
                            $.get("/ncee/wwc/handlers/GlossaryHandler.ashx", { q: selWord }, //query string q=selected word
                                function (data) { $(wrd).attr("title", data); }  //data = returned definition
                            );
                        }
                        else {
                            // "stop"
                            return;
                        }
                    },
                    function () { } //what to do when cursor leaves object
           );
        }
//        else if (event == "click") {
//            //To trigger definition on click of span
//        $(".hilite").click(function () {
//            var wrd = this;  //this = highlighted text being clicked
//            var selWord = $(this).text();
//            if ($(wrd).attr("title") == "")  //only hit the database the first time the word needs defined
//            {
//                $.get("handlers/GlossaryHandler.ashx", { q: selWord }, //query string q=selected word
//                                    function (data) {//data = returned definition
//                                        $(wrd).attr("title", data); //set the title=definition
//                                        $(wrd).mouseover(); //force hover to show tooltip
//                                    }  
//                                );
//            }
//            else {
//                // "stop"
//                return;
//            }

//        }
//               );
//        }

    }
    catch (e) {
        return false;
    }

    finally {
        return this;
    }
}
function eventFire(el, etype) {
    if (el.fireEvent) {
        el.fireEvent('on' + etype);
    } else {
        var evObj = document.createEvent('Events');
        evObj.initEvent(etype, true, false);
        el.dispatchEvent(evObj);
    }
}
// => examples
// => eventFire(myDiv,'mouseover');
// => eventFire(myButton,'click');

