$(document).ready(function() {
	$('#news .post_body').hide();
	$('#news .post_comment').hide();

	$('#news.0 .post_body').show();
	$('#news.0 .post_comment').show();

	var overlink;
	$('a').mouseover(function(){ overlink = true; });
	$('a').mouseout(function(){ overlink = false; });

	$('#news .post_title').parent().click(function(){
		if ($(this).attr("val") != "0" && overlink == false) {
			$(this).find('.post_body').slideToggle();
			$(this).find('.post_comment').slideToggle();
		}
	});
	
	// licznik do odpalenia katanii
	var kat_y = 2010;
	var kat_m = 3;
	var kat_d = 1;
	var kat_h = 12;
	var katania_time = new Date(kat_y, kat_m, kat_d, kat_h, 0, 0, 0);
	var current_time = new Date();
	katania_time = katania_time.getTime()/1000;
	current_time = current_time.getTime()/1000;
	
	//setTimeout('updateCountdown('+Math.floor(katania_time-current_time)+')',1000);
});

function updateCountdown(x) {
	if(x<0) return;
	var y = x;
	var sekundy = y%60;
	y = Math.floor(y/60);
	var minuty = y%60;
	y = Math.floor(y/60);
	var godziny = y%24;
	y = Math.floor(y/24);
	var dni = y;

	var tekst = 'Do otwarcia <b>Katanii</b> pozostalo:<br/>';

	if(dni > 0)
		tekst += dni+((dni==1)?' dzien ':' dni ');
	if(godziny > 0)
		tekst += godziny+((godziny==1)?' godzina ':(((godziny<10 || godziny>20) && godziny%10>1 && godziny%10<5)?' godziny ':' godzin '));
	if(minuty > 0)
		tekst += minuty+((minuty==1)?' minuta ':(((minuty<10 || minuty>20) && minuty%10>1 && minuty%10<5)?' minuty ':' minut '));
	tekst += sekundy+((sekundy==1)?' sekunda ':(((sekundy<10 || sekundy>20) && sekundy%10>1 && sekundy%10<5)?' sekundy ':' sekund '));
	
	document.getElementById('countdownDiv').innerHTML = tekst;
	setTimeout('updateCountdown('+(x-1)+')',1000);
}
