$(document).ready(function(){

    /* ##########################################
     * MENU
     * ##########################################*/

	var config = {    
	     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 100, // number = milliseconds for onMouseOver polling interval    
	     over: MenuIn, // function = onMouseOver callback (REQUIRED)    
	     timeout: 500, // number = milliseconds delay before onMouseOut    
	     out: MenuOut // function = onMouseOut callback (REQUIRED)    
	};
	function MenuIn() {
	    $(this).children('ul').show().parent().addClass('active');
	}; 
	function MenuOut() {
	    $(this).removeClass('active').children('ul').hide();
	};
	$('#header .menu ul > li').hoverIntent(config);


    /* ##########################################
     * 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();
    });



    /* ##########################################
     * ROTATOR BANEROW
     * ##########################################*/

    lol = function ZmienBaner(){
	var ilosc = parseInt($('#banery a').size())-2;
	var id = parseInt($('#banery .active').attr('id').replace('baner-',''));
	if (ilosc == id) {
	    id = 1;
	} else {
	    id = id+1;
	}
	$('#banery .lewo').hide();
	$('#banery .prawo').hide();
	$('#banery').animate({backgroundPosition: '-=250% 0'}, 2000);
	$('#banery .active').animate({left: '-=100%'}, 2000, function(){
	    $(this).css('left','100%').removeClass('active');
	});
	$('#banery #baner-'+id).animate({left: '0%'}, 2000, function(){
	    $(this).addClass('active');
	    $('#banery .lewo').show();
	    $('#banery .prawo').show();
	});
    }
    
    $('#banery .lewo').click(function(){
	lol();
	clearInterval(intervalID);
	intervalID = setInterval(lol, 10000);
    });
    
    $('#banery .prawo').click(function(){
	var ilosc = parseInt($('#banery a').size())-2;
	var id = parseInt($('#banery .active').attr('id').replace('baner-',''));
	if (id == 1) {
	    id = ilosc;
	} else {
	    id = id-1;
	}
	$('#banery .lewo').hide();
	$('#banery .prawo').hide();
	$('#banery').animate({backgroundPosition: '+=250% 0'}, 2000);
	$('#banery .active').animate({left: '+=100%'}, 2000, function(){
	    $(this).css('left','100%').removeClass('active');
	});
	var width = $('body').width();
	$('#banery #baner-'+id).css('left','-'+width+'px').animate({left: '0px'}, 2000, function(){
	    $(this).addClass('active');
	    $('#banery .lewo').show();
	    $('#banery .prawo').show();
	});
	clearInterval(intervalID);
	intervalID = setInterval(lol, 10000);
    });
    
    intervalID = setInterval(lol, 7000);

		
})

