  $j(function()  
   {  
       var hideDelay = 500;  
       var currentID;  
       var hideTimer = null;  
       var ajax = null;  
       var hideFunction = function()  
       {  
           if (hideTimer)  
               clearTimeout(hideTimer);  
           hideTimer = setTimeout(function()  
           {  
               currentPosition = { left: '0px', top: '0px' };  
               container.css('display', 'none');  
           }, hideDelay);  
       };  
     
       var currentPosition = { left: '0px', top: '0px' };  
     
       // One instance that's reused to show info for the current item  
       var container = $j('<div id="itemPopupContainer">'  
           + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="itemPopupPopup">'  
           + '<tr>'  
           + '   <td class="corner topLeft"></td>'  
           + '   <td class="top"></td>'  
           + '   <td class="corner topRight"></td>'  
           + '</tr>'  
           + '<tr>'  
           + '   <td class="left">&nbsp;</td>'  
           + '   <td ><div id="itemPopupContent"></div></td>'  
           + '   <td class="right">&nbsp;</td>'  
           + '</tr>'  
           + '<tr>'  
           + '   <td class="corner bottomLeft">&nbsp;</td>'  
           + '   <td class="bottom">&nbsp;</td>'  
           + '   <td class="corner bottomRight"></td>'  
           + '</tr>'  
           + '</table>'  
           + '</div>');  
     
       $j('body').append(container);  
     
       $j('.itemPopupTrigger').live('mouseover', function()  
       {  
           if (!$j(this).data('hoverIntentAttached'))  
           {  
               $j(this).data('hoverIntentAttached', true);  
               $j(this).hoverIntent  
               (  
                   // hoverIntent mouseOver  
                   function()  
                   {  
                       if (hideTimer)  
                           clearTimeout(hideTimer);  
     
                       // format of 'rel' tag: pageid,itemguid  
                       var settings = $j(this).attr('rel').split(',');  
                       //var pageID = settings[0];  
                       currentID = settings[0];  
     
                       // If no guid in url rel tag, don't popup blank  
                       if (currentID == '')  
                           return;  
     
                       var pos = $j(this).offset();  
					   
					   //gg fix align popup
					   
					   
					   var scrollB=$j(window).scrollTop()+$j(window).height();
					   var limit=$j(window).scrollTop() + (scrollB-$j(window).scrollTop())/2;
					   
					   if (pos.top>limit) pos.top=pos.top-250;
					   if (pos.top<$j(window).scrollTop()) pos.top=$j(window).scrollTop();
					   if (pos.top+250>scrollB) pos.top=post.top-(pos.top+250-scrollB);
					   
					      
					   
					   var newpos=pos;
					   //gg fix align popup
					   
                       var width = $j(this).width();  
                       var reposition = { left: (pos.left + width) + 'px', top: pos.top - 5 + 'px' };  
     
                       // If the same popup is already shown, then don't requery  
                       if (currentPosition.left == reposition.left &&  
                           currentPosition.top == reposition.top)  
                           return;  
     
                       container.css({  
                           left: reposition.left,  
                           top: reposition.top  
                       });  
     
                       currentPosition = reposition;  
     
                       $j('#itemPopupContent').html('<table style="width:250px;height:250px"><tr><td valign="middle" align="center"><img src="/img/ajax-loader.gif"/><br/>Kérem várjon..</td></tr></table>');  
     
                       if (ajax)  
                       {  
                           ajax.abort();  
                           ajax = null;  
                       }  
     
                       ajax = $j.ajax({  
                          type: 'GET',  
						  dataType:'html',
                          url: '/items/nagyit/'+ currentID,  

						    error: function(XMLHttpRequest, textStatus, errorThrown) {
								//alert(XMLHttpRequest.status+" @@ "+errorThrown);
								//alert(XMLHttpRequest.HTML)
							},
                           success: function(data)  
                          {  

                              if (data.indexOf('itemPopupResult') < 0)  
                              {  
                                  $j('#itemPopupContent').html('Hiba betöltés közben..');  
                              }  
                              if (data.indexOf('|'+currentID+'|') > 0)  
                              { 

								  var text = $j(data).html();  
								  
                                  $j('#itemPopupContent').html(text);  
								  
								  //gg fix align popup
								  var scrollB=$j(window).scrollTop()+$j(window).height();
								  //var limit=$j(window).scrollTop() + (scrollB-$j(window).scrollTop())/2;
								  
								  if ((newpos.top+$j('#itemPopupContent').height()+30)>scrollB ) {
										var cor=newpos.top - ((newpos.top+$j('#itemPopupContent').height())+30-scrollB);
										if ((cor)<$j(window).scrollTop()) cor=$j(window).scrollTop();
									  
									    container.css({  
                           
											top: cor
										}); 
								  }
								  //gg fix align popup
								  
                              }  
                          }  
                      });  
    
                      container.css('display', 'block');  
                  },  
                  hideFunction  
              );  
              $j(this).trigger('mouseover');  
          }  
      });  
    
      // Allow mouse over of details without hiding details  
      $j('#itemPopupContainer').mouseover(function()  
      {  
          if (hideTimer)  
              clearTimeout(hideTimer);  
     });  
    
     // Hide after mouseout  
     $j('#itemPopupContainer').mouseout(hideFunction);  
  });  
