var DPopups = {

  init : function() {
    $('.popup').each(function(){
        var popup = $(this);
        var container = $(this).parent();
        var link = $(this).prev('a');

        link.hoverIntent({
          over : DPopups.show,
          out: function(){},
          sensitivity: 3, 
          interval: 200, 
          timeout: 400, 
        });
        
        popup.hoverIntent({
          over : function(){},
          out : DPopups.hide,
          sensitivity: 3, 
          interval: 200, 
          timeout: 400, 
        });

        // add close link
        popup.append('<a href="#" class="close">close</a>');
        popup.find('a.close').click(function(){
                                      $(this).parents('.popup').fadeOut();
                                      return false;
                                    });
      });
  },

  /* Show popup */
  show : function() {
    var popup = $(this).next('.popup');
    /*
    $(popup).css('left', $(this).position().left + $(this).width() + 'px');
    $(popup).css('top', $(this).position().top + $(this).height() + 'px');
    */
    $(popup).fadeIn();
  
  },

  /* Hide popup */
  hide : function(trigger) {
    $(this).fadeOut();
  }

}

$(document).ready(function(){
                    DPopups.init();
                  });

