$(function() {
	var path = window.location.pathname;
	var page = path.substring(path.lastIndexOf('/') + 1);
	var count = $("td.row1 > img[title='Nieprzeczytane posty']").size();
	
	if( page == 'index.php' || page == '' ) {
		$("#ud-unread-posts").empty().text("Działy z nieprzeczytanymi postami [ " + count + " ]");
	}

	$(".cap-div").find("a").after("&nbsp;<span style=\"color: white; cursor: pointer; font-weight: normal;\">[zwiń]</span>");

	$(".cap-div").each(
		function() {
			var href = $(this).find("a").attr("href");
			if( ! href )
				return;
			var forum = href.substring(href.lastIndexOf('=') + 1);
			if( ! forum )
				return;
			//var fold = $.readCookie('ud_fold_' + forum);
			var fold = $.jStorage.get('ud_fold_' + forum, 'false');
			if( fold == 'true' ) {
				$(this).next("table").css("display", "none");
				$(this).find("span").html("[rozwiń]");
			}
		}
	);

	$(".cap-div").find("span").click(
		function () {
			var href = $(this).prev("a").attr("href");
			if( ! href )
				return;
			var forum = href.substring(href.lastIndexOf('=') + 1);
			if( ! forum )
				return;

			var table = $(this).parents(".cap-div").next("table");
			if( table.css("display") == 'none' ) {
				$(this).html("[zwiń]");
				//$.delCookie('ud_fold_' + forum );
				$.jStorage.set('ud_fold_' + forum, 'false');
				table.fadeIn("slow");
			} else {
				$(this).html("[rozwiń]");
				//var c = $.setCookie('ud_fold_' + forum, 'true', { duration: 3650 } );
				$.jStorage.set('ud_fold_' + forum, 'true');
				table.fadeOut("slow");
			}
		}
	);
});

