$(function(){
    var hideDelay = 400;
    var currentID;
    var hideTimer = null;
    var hideFunction = function() {
		$('#page_PopupContainer_tooltip').hover(function(){
			$('#page_PopupContainer_tooltip').data('hoverIntentAttached',1); //active
		}, function() {
			$.shop_popup("close");
			$('#page_PopupContainer_tooltip').data('hoverIntentAttached',0);  //close - default
		});
        if (hideTimer) {
            clearTimeout(hideTimer);
		}
       	hideTimer = setTimeout(function() { 
			if($('#page_PopupContainer_tooltip').data('hoverIntentAttached')!=1) {
				$.shop_popup("close");
				$('#page_PopupContainer_tooltip').data('hoverIntentAttached',0);  //close - default
			}
		}, hideDelay);
    };

    $('.page_PopupTrigger').live('mouseover', function() {
        if (!$(this).data('hoverIntentAttached'))
        {
            $(this).data('hoverIntentAttached', true);
			$('#page_PopupContainer_tooltip').data('hoverIntentAttached',0);  //close - default
            $(this).hoverIntent ({
                over: function() {
                    if (hideTimer)
                        clearTimeout(hideTimer);

                    currentID = $(this).attr('rel');
                    if (currentID == '')
                        return;
					
					$.shop_popup("open",{
						id:'PopupContainer_tooltip',
						ajax_url:shop_url_main+'/shop_artdet.php',
						ajax_data:'ajax_tooltip=1&cikk=' + currentID + '&change_lang=' + actual_lang
					})
                },
				out: hideFunction,
				interval: 400,
				sensitivity: 8
			});
            $(this).trigger('mouseover');
        }
    });	
});
