
$(document).ready(function(){
    
    //var text = $('h2 a').html();
	//$('h2 a').html(text.replace(/\b([A-Za-z0-9])/g,'<span class="caps">$1</span>'));
	//$('.caps').css('font-size',30);

    //Cufon('.stream .tags h3, .featured h3, .stream h2 a');
Cufon.replace(['.stream .tags h3, .featured h3, .stream h2 a'], {fontFamily:'Arial CE',fontWeight:'700'});

	//create_carousel('.featured',0,0);

	/* środkowanie paginacji */
	$('.pagination ul').each(function(){
		$(this).css('margin-left',$(this).width()/2);
	});	
});

function create_carousel(id,speed,czy_bullets){
	
	if (speed != 0){
		var run = setInterval('rotate(\''+id+'\')', speed);
	}
	var maxi = $(id+" .carousel>li").size()
	var pos = 0;
	
	$(id).append("<div class='carousel-nav'><a href='' class='browse prev'><span>poprzednie</span></a><a href='' class='browse next'><span>następne</span></a></div>");
	
	if (czy_bullets == 1){
		var list = $(id).append("<ul class='nav'></ul>").find('ul.nav');
		for (var i = 0; i < maxi; i++)
			list.append('<li><a href="">'+i+'</a></li>');
	}
	  
	$(id+" .carousel>li").hide();
	$(id+" .carousel>li:eq("+pos+")").show(); 
	$(id+' .nav li:first a').addClass("active");		
	
	function showpost(){
		$(id+" .carousel>li").hide();
		$(id+" .carousel>li:eq("+pos+")").show();
		$(id+" .nav>li a").removeClass("active");
		$(id+" .nav>li:eq("+pos+") a").addClass("active");	
	}
	
	$(id+" .nav>li").click(function(){
		pos = $(id+" .nav>li").index(this);
		showpost();
		return false;
	});
	
	$(id+">.carousel-nav a.prev").click(function() {
	    if (pos == 0) { pos=maxi-1; } else { pos = pos-1; }
		showpost();
		return false;    
	});
	
	$(id+">.carousel-nav a.next").click(function() {
		if (pos == maxi-1) { pos=0; } else { pos = pos+1; };
		showpost();
		return false;
	});        
	
	if (speed != 0){
		$(id).hover(
			function() {
				clearInterval(run);
			}, 
			function() {
				run = setInterval('rotate(\''+id+'\')', speed);	
			}
		);
	}
}

function rotate(id) {
	$(id+'>.carousel-nav a.next').click();
}
