(function($){
 $.fn.itemPopup = function(){

 function showPopup(popup){
 var img = popup.find('img'),
 trigger = popup.parents('.listitem').find('img')

 thumbs = popup.find('.popupThumbsGallery > a'),
 t = trigger.position().top;
 p = popup.height(); //popup.hasClass('withoutThumb') ? 60 : 372,
 s = $(window).scrollTop();
 w = $(window).height();
 var top_pos = t - p + 9;// + trigger.height() / 2;
 var left_pos = trigger.position().left + trigger.width() / 2 - popup.width() / 2;
 
 popup.css({top: top_pos, left: left_pos});

 popup.fadeIn(200);
 }

 
 return this.each(function(){
 var popup = $(this);
 var timer;
 var trigger = $(this).parents('.listitem');
 
 trigger
 .bind('mouseenter', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ showPopup(popup); }, 500);
 })
 .bind('mouseleave', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ popup.fadeOut(200); }, 500);
 });
 popup
 .bind('mouseenter', function(){
 clearTimeout(timer);
 })
 .bind('mouseleave', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ popup.fadeOut(200); }, 500);
 });
 });

 };

 $(function(){
 $('.popupbox').itemPopup();
 });
})(jQuery);

