iScore = 1;

$(document).ready(function(){
	$('#main').pngFix(); 
	$('#changer li').pngFix();
	$('.news .img').pngFix();
	$('.galeria .img').pngFix();
	$('#opennews .img').pngFix();
	
	$('#leftbox .header:first').addClass('first');
	
	$('#szukaj_input').click(function(){
		var tresc = $(this).attr('value');
		var szukana = $('#szukana').text();
		if(tresc == szukana) $(this).attr('value', '');						 
	});
	$('#szukaj_input').blur(function(){	
		var tresc = $(this).attr('value'); 
		var szukana = $('#szukana').text();
		if(tresc == '') $(this).attr('value', szukana);
	});
	
	$('.log').click(function(){
		var tresc = $(this).attr('value');
		if(tresc == 'login') $(this).attr('value', '');						 
	});
	$('.log').blur(function(){	
		var tresc = $(this).attr('value'); 
		if(tresc == '') $(this).attr('value', 'login');
	});
								 

	$('#menu li').hover(function(){
		if(!$(this).hasClass('sfhover')){
			var szer = $(this).width();
			$('a:first', this).width(szer +'px');
			
			$(this).addClass('sfhover');	
			$('a:first', this).prepend('<span class="pl"></span>').prepend('<span class="pr"></span>');
			$('ul .pl', this).remove();
			$('ul .pr', this).remove();
			$('ul', this).fadeIn();
		}
	});
	
	$('#menu li').mouseleave(function(){
		if($(this).hasClass('sfhover')){
			var szer = $(this).width() - 32;
			$('a:first', this).width(szer +'px');
			
			$(this).removeClass('sfhover');
			$('.pl', this).remove();
			$('.pr', this).remove();
			$('ul', this).fadeOut();
		}
	});
	
	$('li', '#changer').addClass('minhov');
	$('#changer li').hover(function(){
		$('span', this).fadeIn('fast');	
		$(this).removeClass('minhov');
	});
	
	$('#changer li').mouseleave(function(){
		$('span', this).fadeOut('fast');	
		$(this).addClass('minhov');
	});
	
	$('#changer li').click(function(){
		var title = $(this).attr('title');	
		if($('#main'+title).css('display') == 'none'){
			for(i=1; i<6; i++){$('#main'+i).fadeOut();}
			$('#main'+title).fadeIn();
		}
	});
	
	$('#archiwum li:even').addClass('archodd');
	$('#tabela li:even').addClass('tabodd');
	$('#coments li:even').addClass('comodd');
	
	$('li', '#font-size').click(function(){
		var tresc = $(this).text();
		$('#opennews p').css('font-size', tresc+'px');					 
	});
	
	$('#loginform').bind('submit', function() {
	  var o = $(this);
	  $.post(o.attr('action'), o.serialize(), function(sResponse) {
	    aResponse = sResponse.split("\n");
      
      if(aResponse[0] == 1)
        window.location.reload();
      else
        alert(aResponse[1]);
	  });
	  
	  return false;
	});
	
	$('#comment').bind('submit', function() {
	  var o = $(this);
	  $.post(o.attr('action'), o.serialize(), function(sResponse) {
	    aResponse = sResponse.split("\n");
      
      if(aResponse[0] == 1)
        window.location.reload();
      else
        alert(aResponse[1]);
	  });
	  
	  return false;
	});
});

