$(document).ready(function(){

$('#topoferta #bb2').css('display', 'none');
$('#topoferta #bb3').css('display', 'none');

    /* ##########################################
     * WYSZUKIWARKA
     * ##########################################*/

    $('#search_box :text').focus(function(){
	if($(this).val()=="Szukaj..") {
	    $(this).val('');
	}
    });
    $('#search_box :text').blur(function(){
	if( $(this).val() == '') {
	    $(this).val('Szukaj..');
	}
    });
    
    
    /* ##########################################
     * SKALOWANIE TEKSTU
     * ##########################################*/
    
    var size_from_cookie = $.cookie('fontsize');
    if(size_from_cookie) {
	$("#column2").css("font-size", size_from_cookie);
    }
    $("#skaluj span").click(function(){
	var size = $(this).attr("id").replace("p","");
	$("#column2").css("font-size",size+"%");
	$.cookie('fontsize', size+"%", { path: '/' });
    });
    
    
    
    /* ##########################################
     * DRUKOWANIE
     * ##########################################*/
    
    $("#print").click(function(){
	window.print();
    });
    
    
    
    /* ##########################################
     * BANERY
     * ##########################################*/
    
    lol = function ZmienBaner(){
	var numer = parseInt($('#topoferta #timer span.tw').text());
	numer = numer+1;
	if (numer == 4){
	    numer = 1;
	}
	$('#topoferta .baner.tw').hide().removeClass('tw');
	$('#topoferta #timer span.tw').removeClass('tw');
	$('#topoferta #timer #t'+numer).addClass('tw');
	$('#topoferta #bb'+numer).show().addClass('tw');
    }
    
    $("#topoferta #timer span").click(function(){
	clearInterval(intervalID);
	intervalID = setInterval(lol, 10000);
	$('#topoferta #timer span.tw').removeClass('tw');
	$(this).addClass('tw');
	var numerek = parseInt($(this).text());
	$('#topoferta .baner.tw').hide().removeClass('tw');
	$('#topoferta #bb'+numerek).show().addClass('tw');
	
    });

    intervalID = setInterval(lol, 10000); 


    /* ##########################################
     * 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();

		
})
