﻿$(document).ready(function() {
    setupInfoPopups();
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
   function endRequestHandler(sender, args){
       setupInfoPopups();
   }
});

function setupInfoPopups(){
	$(".info").click(function(e) {
        var cssclass = $(this).attr('class').split(' ').slice(-1);
        var currentelement = this;
        if (typeof window.currentvisibleinfo !== 'undefined') {
            if (window.currentvisibleinfo != null) {
                window.currentvisibleinfo.remove();
            }
        }
        
        window.currentvisibleinfo = null;
        $.ajax({
            type: "GET",
            url: "LegendHandler.ashx",
            data: "itemkey=" + cssclass,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
            var newelement = $('<div class="tooltip"><a class="close" href="#">' + msg.CloseText + '</a>' + msg.Html + '</div>');
            //var iframeelement = $('<iframe></iframe>');
                $(newelement).children('a.close').click(function() {
                    newelement.remove();
                    window.currentvisibleinfo = null;
                });
                leftVal = e.pageX + "px";
                topVal = (e.pageY - 20) + "px";
                newelement.css({ left: leftVal, top: topVal });
	            //iframeelement.css = newelement.css;
	            newelement.insertAfter($(window.document.body).children('form').get(0));
	            //iframeelement.insertAfter($(window.document.body).children('form').get(0));
            }
        });
    });
}
