//popup for contact us page
$(function()
{
  var hideDelay = 500;  
  var currentID;
  var hideTimer = null;

  var container = $('<div id="PopupContainer" class="jquery_popup_spacing">'
      + '<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">'  
      + '<tr>'
      + '   <td align="left"><div id="PopupContent"></div></td>'
      + '</tr>'
      + '</table>'
      + '</div>');

  $('body').append(container);

  $('.PopupTrigger').live('mouseover', function()
  {
      //format of 'rel' tag
    var settings = $(this).attr('rel').split(',');  
    var name = settings[0];  
    var popup_position = settings[1];
    var image = settings[2];
    var image_width = settings[3];
    var page = settings[4];
    
      if (hideTimer)
          clearTimeout(hideTimer);
       
     // var pos = $(this).offset();      
     // var width = $(this).width();
     
      var pos = $('.map').offset();      
      var width = $('.map').width();
      
      if(page == "pan")
      {
        if(popup_position == 1) // BOT
        {        
            container.css({
              left: (pos.left + width - 470) + 'px',
              //left: (pos.left + width - 0) + 'px',
              top: (pos.top + 280) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');          
          container.css('display', 'block');
        }
        else if(popup_position == 2)
        {
            container.css({
              //left: (pos.left + width - 480) + 'px',
              left: (pos.left + width - 480) + 'px',
              top: (pos.top + 335) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }
        
        else if(popup_position == 3)
        {
            container.css({
              left: (pos.left + width - 520) + 'px',
              top: (pos.top + 265) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }  
        else if(popup_position == 4)
        {
            container.css({
              left: (pos.left + width - 460) + 'px',
              top: (pos.top + 230) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }  
        else if(popup_position == 5)
        {
            container.css({
              //left: (pos.left + width - 375) + 'px',
              left: (pos.left + width - 381) + 'px',
              top: (pos.top + 135) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }  
        else if(popup_position == 6)
        {
            container.css({
              //left: (pos.left + width - 375) + 'px',
              left: (pos.left + width - 661) + 'px',
              top: (pos.top + 85) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }
		else if(popup_position == 7)
        {
            container.css({
              //left: (pos.left + width - 375) + 'px',
              left: (pos.left + width - 633) + 'px',
              top: (pos.top + 100) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }
		else if(popup_position == 8)
        {
            container.css({
              //left: (pos.left + width - 375) + 'px',
              left: (pos.left + width - 417) + 'px',
              top: (pos.top + 135) + 'px'
          });
          
          //minipulate popup
          $('#PopupContent').html('<div>'+name+'</div>');
          $('#PopupContainer').css('background','url(/img/'+image+') no-repeat');
          $('#PopupContainer').css('width',image_width+'px');
          container.css('display', 'block');
        }
     }
  });

  $('.PopupTrigger').live('mouseout', function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });

  // Allow mouse over of details without hiding details
  $('#PopupContainer').mouseover(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
  });

  // Hide after mouseout
  $('#PopupContainer').mouseout(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });
});

