﻿$(document).ready(function() {
    var $dialog = $('<div style="display: none;" id="modalDialog"></div>').dialog({ autoOpen: false, modal: true })
    $.ajax({
        url: "http://brucejackson.info/Vocabulator.ashx"
        , success: MarkupWordOrPhrase
        , dataType: "jsonp"
    });
})
function MarkupWordOrPhrase(data, textStatus) {
    var currentContent = $("#content").html();
    for (var i = 0; i < data.length; i++) {
        var term = data[i].item;
        var shortDef = data[i].shortDefinition;
        var longDef = data[i].longDefinition.replace(new RegExp("'", "g"), "\\'");
        longDef = longDef.replace(new RegExp("\"", "g"), "\\'");
        if (currentContent.indexOf(term) > 0) {
            var newstr = "<a href=\"\" title=\"" + shortDef + "\nClick the link for a more detailed definition.\" onclick=\"return showFullDefinition('" + term + "','" + longDef + "')\">" + term + "</a>";
            currentContent = currentContent.replace(term, newstr);
        }
    }
    $("#content").html(currentContent);
}
function showFullDefinition(term, def) {
    $("#modalDialog").dialog("option", "width", "500");
    $("#modalDialog").dialog("option", "resizable", false);
    $("#modalDialog").dialog("option", "closeOnEscape", true);
    $("#modalDialog").dialog("option", "height", "auto");
    $("#modalDialog").data("title.dialog", "Definition of " + term);
    $("#modalDialog").text(def);
    $("#modalDialog").dialog("open");
    $("#modalDialog").dialog("option", "position", "top");
    return false;
}

