var obj = null;
var hoverTimeout = null;
$=jQuery;
function checkHover() {
	if (obj) {
		obj.fadeOut('fast');
		hoverTimeout=null;
		obj=null;
	} //if
} //checkHover

$(function() {  // Coments
	$('#commentsForm').fadeOut('fast');
    $('#comments').add('#comments > a').click(function () {
    	var commentsBlock = $('#commentsForm');
    	commentsBlock.fadeIn('fast');
    });
});

$(function() {  // Tabs
    $('#cat_tabs > li > a').click(function () {
		var tabContainers = $('#categories_tab').add('#specials_tab');
		tabContainers.hide();
		tabContainers.filter(this.hash+'_tab').show();
		var tabs=$('#cat_tabs li');
		tabs.removeClass('selected');
		tabs.filter(this.hash+'_btn').addClass('selected');
		return false;
    }).filter(':first').click();
});
$(function() { // Popup menu
	$('.online_content li').hover(function() {
		var li=$(this);
		$('.online_content li').removeClass('selected');
		$('#onlineimage').attr('src',li.attr("id"));
		li.addClass('selected');
	}, function() {
	});
});

$(function() { // Popup menu
	$('a.cat_menu_popupitem').hover(function() {
		var popup=$(this.hash+'_popup');
		if (obj) {
			if (obj[0]!=popup[0]) {
				obj.fadeOut('fast');
			}
			obj = null;
		}
		popup.fadeIn('fast');
	}, function() {
		var popup=$(this.hash+'_popup');
		obj = popup;
		hoverTimeout=setTimeout("checkHover()",200);
	});
	
	$('.popup').hover(function() {
		if (hoverTimeout) {
			clearTimeout(hoverTimeout);
			hoverTimeout=null;
		}
	}, function() {
		obj = $(this);
		hoverTimeout=setTimeout("checkHover()",200);
	});
	$('.cat_menu li').hover(function() {
		$(this).addClass('selected');
	}, function() {
		$(this).removeClass('selected');
	});
});
function setReclamas(dir) {
	reclama_current+=dir;
	if (reclama_current<0) {
		reclama_current=reklamas.length-1;
	} else if (reclama_current>=reklamas.length) {
		reclama_current=0;
	}
	$('#reclama').attr({href:reklamas[reclama_current].big});
	$('#reclama>img').attr({src:reklamas[reclama_current].small});
	return false;
}
function autoupload(url){
	$(function() {
		setTimeout(autoupload1,300);
	});
}
function autoupload1(url){
	var uploadcount=$('#uploadcount');
	var cnt=uploadcount.html();
	if (cnt>1) {
		uploadcount.html(cnt-1);
		setTimeout(autoupload1,1000);
	} else {
		uploadcount.parent().remove();
		var ref=$('div.pdf a');
		document.location.href=ref.attr('href');
	}
}

