<script>
function resizeGraphIFrame(obj) {
  try {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  } catch(e) {}
}
jQuery(document).ready(function() {
  jQuery("a.histou_tips, a.tips").hover(
    function(e){
      var popup_width   = 600;
      var popup_height  = 200;
      var url           = this.rel;
      var screen_width  = jQuery(window).width();
      var popup_pos_x   = e.pageX + 5;
      if(e.pageX + popup_width > screen_width) {
        popup_pos_x  = e.pageX - popup_width - 5;
      }

      var showPopup = function(url) {
        jQuery("#tooltip").remove();
        jQuery("body").append("<div id='tooltip'><iframe src='"+url+"' width='"+popup_width+"' height='"+popup_height+"' frameBorder='0' scrolling='no' onload='resizeGraphIFrame(this)'><\/iframe><\/div>");
        jQuery("#tooltip")
          .css("position","absolute")
          .css("z-index","15")
          .css("top",(e.pageY - 10) + "px")
          .css("left", popup_pos_x + "px")
          .fadeIn("fast");
      };

      var params = toQueryParams(url);
      if(params["panelId"] && !jQuery.isNumeric(params["panelId"])) {
        fetchHistouPanelId(url, params["panelId"], params["host"], params["service"], function(newId) {
          if(newId === "null") {
          } else {
            url = url.replace("&panelId="+params["panelId"], "&panelId="+newId);
            showPopup(url);
          }
        });
      } else {
        showPopup(url);
      }
    },
    function(){
      jQuery("#tooltip").remove();
    }
  );
});
</script>
