$(".colorbox").colorbox();

$('input').placeholder();

Cufon.set('fontFamily', 'MyriadPro');
Cufon.replace('#nav a', {hover: true});
Cufon.replace('footer .copy');
Cufon.replace('footer label');
Cufon.replace('footer .slowa h2');
Cufon.replace('footer .btn');

Cufon.set('fontFamily', 'MyriadProCond');
Cufon.replace('aside nav > ul >li > a');
Cufon.replace('aside h2');


$('footer .btn').click(function(){
	$('#footer_links').slideToggle();
	return false;
})


$('aside nav .sub > a').click(function()
{		
  $(this).parent().parent().find('ul:visible').each(function(){ 
    $(this).slideUp(function(){
			$(this).parent().removeClass('sub-active');
    });
  });

	$(this).parent().find('ul:hidden').slideDown(function(){
		$(this).parent().addClass('sub-active');
	});

})

// IMAGES LIST prev/next

if ($('ul.gal').length) 
{
	
	$('ul.gal li').each(function(){
		var src = $(this).find('img').attr('src');
		$(this).find('span').css('background-image', 'url('+src+')');		
		$(this).find('img').css('opacity', 0)	;
	});
	
  var total = $('ul.gal li').length;
  var per_page = 9;
  var pages = Math.ceil(total / per_page);

  if (pages > 0) 
  {
    var html = '<div class="pnav"><div><span>Zobacz więcej zdjęć:</span> ';
    for (i=1;i<=pages;i++) {
			html += '<a rel="'+i+'"'+(i == 1 ? ' class=current' : null)+'>'+i+'</a>';	
    }
    
    html += '</div></div>';
    $('ul.gal').parent().append(html);    
    
    var page_no = 0;
    var from = page_no * per_page;
    var to = from + per_page < total ? from + per_page : total;
    
    $('ul.gal li').hide();
    $('ul.gal li').slice(from,to).show();
    
    $('.pnav a').click(function(){
    	$('.pnav a').removeClass();
    	$(this).addClass('current');
      var page_no = $(this).attr('rel') - 1;
      var from = page_no * per_page;
      var to = from + per_page < total ? from + per_page : total;
	    $('ul.gal li').hide();
	    $('ul.gal li').slice(from,to).show();
    });
  }
};


/* TA Slideshow v.1.0 */
(function($){
  $.fn.ta_slideshow = function() 
  {    
    var settings = {
      'interval' : 5000,
      'speed'    : 'slow'
    };
    
    var id = this;
    var els = id.children();

    var count = id.children().length;
    var current = 0;

    els.hide();
    els.eq(0).show();
    
    setInterval(function(){
    
        next = current + 1 >= count ? 0 : current + 1;

        els.eq(current).fadeOut(settings['speed'])
        els.eq(next).fadeIn(settings['speed']);
        current = current + 1 >= count ? 0 : current + 1;
        
      }, settings['interval']
    );

  };
})(jQuery);
$('#slideshow').ta_slideshow();

$('#slider').nivoSlider();

