﻿        var floatDiv=null;
        (function ($) {
            var myObjects = new Array();
            


            var html = "<table  id='draggablex' class='ui-widget-content' cellpadding='0' cellspacing='0' style='border-radius:20px; box-shadow: 10px 10px 5px #707070; width: 380px; font-family: KaiTi;  background-color:#f0f0f0';'>" +
              "<tr><td valign='middle' style='width: 100%; cursor: move;  id='dragHandlex'>" +
             "<span id='BCV' style='cursor: pointer; font-size:10pt; float: left; padding: 8px 4px 0px 10px; font-size:1em'></span>" +
              "<span id='closeSpan' style='cursor: pointer; font-size:10pt; float: right; padding: 8px 14px 0px 0px; font-size:1em'> <img src='img/closeicon.png' /></span>" +
              "</td></tr><tr><td><hr></td></tr><tr><td><div id='dragDivx' style='padding: 5px'><div></td></tr></table>";

            var parent;
            var currentIndex;
            return $.fn.bibleTips = function () {
                    //var size=floatDiv = $('#draggablex').size();
                if ($('#draggablex').size()==0) {
                    $('body').append(html);                   
                    $("#draggablex").draggable({ handle: '#dragHandlex' });
                    $("#draggablex").show();                   
                    $("#draggablex").hide();
                    $("#closeSpan").bind('click', function () { $('#draggablex').hide(); });
                    floatDiv = $('#draggablex');
                    floatDiv.offset({ top: 100, left: 100 });
                }
                else floatDiv = $('#draggablex');
                //floatDiv.offset({ top: 100, left: 100 });
                //$('body').append("<div id='obvfjehgrhq'  style='position: absolute; top: 0px; left: 0px; width: 380px;  background-color:#f0f0f0;font-family: KaiTi; color:#000060; padding:5px 5px 5px 5px; display: none; border: 1px solid #a0a0a0'> </div>");
                this.each(function (index) {
                    myObjects[index] = $(this);
                    $(this).bind('click', function () { Show(index); });
                    //$(this).bind('mouseover', function () { Show(index); });
                    //$(this).bind('mouseout', function () { hide(index); });
                    if ($(this).attr('alt') != null) $(this).data('text', $(this).attr('alt'));
                    else $(this).data('text', $(this).text());
                    $(this).data('top', $(this).offset().top);
                    $(this).data('left', $(this).offset().left);
                    $(this).data('width', $(this).width());
                    $(this).data('height', $(this).height());
                    $(this).data('tips', null);
                })
            }
            function Show(index) {
                var thisobject = myObjects[index];
                if (thisobject.data('tips') != null) {
                    floatDiv.show();

                    var html = "";
                    var thisData = thisobject.data('tips').d;
                    $('#BCV').html(thisData.BCV);
                    for (list in thisData.RefList) {
                        html += "<span style='color:#a00000'>" + thisData.RefList[list].Book + '</span><br/>';
                        for (list2 in thisData.RefList[list].Verses) html += thisData.RefList[list].Verses[list2] + '<br/>';
                    }
                    //floatDiv.html(html);
                    $('#dragDivx').html(html);
                    //return;
                    if (escape(thisobject.data('text')).indexOf('A') == -1)
                        floatDiv.css('top', thisobject.offset().top + thisobject.data('height') + 3 + 'px');
                    else
                        floatDiv.css('top', thisobject.offset().top - thisobject.data('height') * 2 - $('#draggablex').height() + 'px');
                    //floatDiv.css('top', thisobject.data('top') + thisobject.data('height') + 'px');
                    if (thisobject.data('left') < 650)
                        floatDiv.css('left', thisobject.data('left') + 'px');
                    else
                        floatDiv.css('left', thisobject.data('left') + thisobject.data('width') - 350 + 'px');
                }
                else {
                    currentIndex = index;
                    $.ajaxSetup({ crossDomain: "true" });
                    jQuery.support.cors = true;
                    //http://localhost:49546/WebBible
                    //$.get("http://localhost:49546/WebBible/GetVerses.ashx", function (data) { myObjects[currentIndex].data('tips', data); Show(currentIndex); })
                    $.get("http://srechurch.org/BibleVersesService.svc/GetTipsNew?key=" + escape(thisobject.data('text')).replace('A', ''), function (data) { myObjects[currentIndex].data('tips', data); Show(currentIndex); })
                    //$.get("http://srechurch.org/BibleVersesService.svc/GetTips?key=12345", function (data) { myObjects[currentIndex].data('tips', data); Show(currentIndex); })
                    //$.getJSON("http://localhost:58617/WebBible/BibleVersesService.svc/?Callback=GetTips", { key: "12345", format: "json" }, function (data) { myObjects[currentIndex].data('tips', data); Show(currentIndex); })
                    //$.getJSON("http://srechurch.org/BibleVersesService.svc/?Callback=GetTips", { key: "12345", format: "json" }, function (data) { myObjects[currentIndex].data('tips', data); Show(currentIndex); })

                }
            }
            function hide(index) {
                //floatDiv.hide();
                //floatDiv.css('display', 'none');
            }
        })(jQuery)

  
