jQuery(document).ready(function() {
  var hideDelay = 1500;  
  var currentID;
  var hideTimer = null;

  // One instance that's reused to show info for the current person
  var container = jQuery('<div id="belme-tooltip-container"><div id="belme-tooltip-content"></div></div>');
  jQuery('body').append(container);

  jQuery('.belme').live('click', function()
  {

      // If no guid in url rel tag, don't popup blank
      if (currentID == '')
          return;

      if (hideTimer)
          clearTimeout(hideTimer);

      var pos = jQuery(this).offset();
      var width = jQuery(this).width();
      container.css({
          left: (pos.left + 20) + 'px',
          top: pos.top -140 + 'px'
      });

      jQuery('#belme-tooltip-content').html('&nbsp;');

      jQuery.ajax({
          type: 'GET',
          url: '/' + language + '/contact/belmeajax/',
          data: 'ajax=1',
          success: function(data)
          {
    	  	if (data) {
    	  		if (/\S/.test(data)) {
    	  			jQuery('#belme-tooltip-content').html(data);
    	  			container.css('display', 'block');
    	  		} else {
    	  			container.css('display', 'none');
    	  		}
    	  	}
          }
      });

  });

  jQuery('.belme').live('mouseout', function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });

  // Allow mouse over of details without hiding details
  jQuery('#belme-tooltip-container').mouseover(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
  });

  // Hide after mouseout
  jQuery('#belme-tooltip-container').mouseout(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });
});

function closePhone() {
	jQuery('#belme-tooltip-container').css('display', 'none');	
}

function submitPhone() {
    jQuery.ajax({
        type: 'POST',
        url: '/' + language + '/contact/mailphone/',
        data: 'ajax=1&phone=' + jQuery('#phone').val(),
        success: function(data) {
        	jQuery('#belme-tooltip-content').html(data);
        }
    });
}

