$(document).ready(function(){
	$('.dhover').hover(function(){
		$(this).addClass('dh')
	});
	$('.dhover').mouseleave(function(){
		$(this).removeClass('dh')
	});

	$('#menu li').hover(function(){
		$(this).addClass('sfhover');
	});
	$('#menu li').mouseleave(function(){
		$('ul', this).fadeOut();
		$(this).removeClass('sfhover');
	});
	$('#menu li').click(function(){
		$('ul', this).fadeIn();
	});
	$(' li:last a', '#menu ul').addClass('ws');
	$('ul', '#menu').append('<li class="umr"></li>');
	$('ul', '#menu').prepend('<li class="uml"></li>');
	
	$('#wiecej_opcji').click(function(){$('#opcje').fadeIn(); $(this).addClass('wo')});
	$('#opcje').mouseleave(function(){$(this).fadeOut(); $('#wiecej_opcji').removeClass('wo');});
	
	$('.up, .down').hover(function(){
		$(this).addClass('dmm');
	});
	$('.up, .down').mouseleave(function(){
		$(this).removeClass('dmm');
	});
	$('.t1:first, .t2:first, .t3:first, .t4:first, .t5:first').addClass('rb');
	
	scroller = function(o, id, nr, poz) {
		var imageHeight = parseInt(nr);
		var imageSum = $(""+id+" ul > li").size();
		if (id == '#tabela'){imageSum = imageSum/5;}
		var imageReelHeight = imageHeight * imageSum;
		if (id == '#shoutbox'){imageReelHeight = $('#shoutbox ul').height();}
		$(""+id+" ul").css({'height' : ''+imageReelHeight+'px'});
		var aktualTop = parseInt($(""+id+" ul").css('top').replace('px', ''));
		
		if(o == 'up') { var image_reelPosition = aktualTop - imageHeight}
	    if(o == 'down') { var image_reelPosition = aktualTop + imageHeight; }
		if (image_reelPosition > 0){ image_reelPosition = 0;}
		var zak = parseInt('-'+imageReelHeight) + poz*imageHeight;
		
		if (image_reelPosition < zak){image_reelPosition = zak;}
		
		$(""+id+" ul").animate({
        	top: image_reelPosition+'px'
    	}, 500 );
	};
	$('#utabela').click(function(){
		scroller('down', '#tabela', 28, 8);
	});
	$('#dtabela').click(function(){
		scroller('up', '#tabela', 28, 8);
	})
	
	$('#uzawodnicy').click(function(){
		scroller('down', '#zawodnicy', 242, 1);
	});
	$('#dzawodnicy').click(function(){
		scroller('up', '#zawodnicy', 242, 1);
	})
	
	$('#uforum').click(function(){
		scroller('down', '#forum', 28, 6);
	});
	$('#dforum').click(function(){
		scroller('up', '#forum', 28, 6);
	})
	
	$('#utyper').click(function(){
		scroller('down', '#typer', 28, 6);
	});
	$('#dtyper').click(function(){
		scroller('up', '#typer', 28, 6);
	})
	
	$('#input_szukajka').click(function(){	
		var tresc = $(this).attr('value');		
		if(tresc == '...') $(this).attr('value', '');
	});
	$('#input_szukajka').blur(function(){	
		var tresc = $(this).attr('value');		
		if(tresc == '') $(this).attr('value', '...');
	});
	
	$('#szukaj').hover(function(){
		$(this).addClass('hov')
	});
	$('#szukaj').mouseleave(function(){
		$(this).removeClass('hov')
	});
	$('#publicystyka li').hover(function(){
		$(this).addClass('pubodd');
	});
	$('#publicystyka li').mouseleave(function(){
		$(this).removeClass('pubodd');
	});
	$('#shoutbox ul li:even').addClass('shoutodd');
	
	$('#ushoutbox').click(function(){
		scroller('down', '#shoutbox', 30, 6);
	});
	$('#dshoutbox').click(function(){
		scroller('up', '#shoutbox', 30, 6);
	})
	
	$('#stats li:even').addClass('statsodd');
	
	$('.galeria li').hover(function(){
		$('a', this).fadeIn();
		$('div', this).fadeIn();
	});
	$('.galeria li').mouseleave(function(){
		$('a', this).fadeOut();
		$('div', this).fadeOut();
	});
	
	$('#wyloguj').hover(function(){
		$(this).addClass('wl');
	});
	$('#wyloguj').mouseleave(function(){
		$(this).removeClass('wl');
	});
	
	$('.komentarz:odd').addClass('komentarzodd');
	
	$('#add_com input, .dodaj').hover(function(){
		$(this).addClass('dod');
	});
	$('#add_com input, .dodaj').mouseleave(function(){
		$(this).removeClass('dod');
	});
	
	$('.ods').hover(function(){
		$(this).addClass('sdo');
	});
	$('.ods').mouseleave(function(){
		$(this).removeClass('sdo');
	});
	
	$('.glosuj').hover(function(){
		$(this).addClass('gls');
	});
	$('.glosuj').mouseleave(function(){
		$(this).removeClass('gls');
	});
	
	$('#wyb span').click(function(){
		$('span', '#wyb').removeClass('zaz');
		$(this).addClass('zaz');
		var size = $(this).text();
		$('p', '#news_tresc').css('font-size', size+'px');
	});
	
	$('#wyb2 span').click(function(){
		$('span', '#wyb2').removeClass('zaz');
		$(this).addClass('zaz');
		var size = $(this).text();
		$('p', '#podstrona').css('font-size', size+'px');
	});
	
});
