$(document).ready(function(){

    /* ##########################################
     * OŚRODKI MENU
     * ##########################################*/
     
    $('#osrodki a:not(.active)').mouseover(function(){
	pozycja_x = $(this).css('background-position').split(' ')[0];
	$(this).animate({backgroundPosition: pozycja_x+' 0'}, {duration:500});
    }).mouseout(function(){
	$(this).animate({backgroundPosition: pozycja_x+' -48px'}, {duration:500});
    });

     
    /* ##########################################
     * WYSZUKIWARKA
     * ##########################################*/

    $('#search_box :text').focus(function(){
	if($(this).val()=="Wpisz szukaną frazę") {
	    $(this).val('');
	}
    });
    $('#search_box :text').blur(function(){
	if( $(this).val() == '') {
	    $(this).val('Wpisz szukaną frazę');
	}
    });
    
    
    /* ##########################################
     * SKALOWANIE TEKSTU
     * ##########################################*/
    
    var size_from_cookie = $.cookie('fontsize');
    if(size_from_cookie) {
	$(".text").css("font-size", size_from_cookie);
    }
    $("#skaluj span").click(function(){
	var size = $(this).attr("id").replace("p","");
	$(".text").css("font-size",size+"%");
	$.cookie('fontsize', size+"%", { path: '/' });
    });
    
    
    
    /* ##########################################
     * DRUKOWANIE
     * ##########################################*/
    
    $("#print").click(function(){
	window.print();
    })



    /* ##########################################
     * LICZNIK KOMENTARZY
     * ##########################################*/
    
    var COMMENT_MAX_LENGTH = 1000;

    $('.comment_form form textarea').keyup(function () {
	var i = $(this).val().length;
	var areatext = $(this).val();

	$(this).parent('p').find('.counter').remove();

	if (i>COMMENT_MAX_LENGTH) {
	    $(this).parent('p').find('.c').css('background-color', '#ff0000');

	    if (i=COMMENT_MAX_LENGTH+1) {
		$(this).val(areatext.substring(0, i-1));
	    } else {
		$(this).val(areatext.substring(0, COMMENT_MAX_LENGTH));
	    }
	} else {
	    $(this).parent('p').find('.c').remove();
	    $(this).parent('p').append('<span class="c">'+i+'/'+COMMENT_MAX_LENGTH+'</span>');
	}
    }).keyup();

		
})

