$(document).ready(function(){
	
	// PRZYDATNE LINKI		
	// globalna zmienna z indeksem pierwszego pokazywanego elementu
	var index = 0;
	
	// akcja 'natępny'
	$('.footer .useful_links .next').click(function(){
		var elems = $(this).parent().children().not('.prev, .prev_hide, .next, .next_hide')
		var countAll = $(elems).length;
		var countShow = 5;
		
		if ((index + countShow) < countAll) {
			$(elems).filter(':eq(' + index + ')').addClass('hide');		
			index++;
			if(index > 0) $('.footer .useful_links .prev_hide').removeClass('prev_hide').addClass('prev');
		} 
		if((index + countShow) == countAll) $(this).removeClass('next').addClass('next_hide');
		
		return false;
	});	
	
	// akcja 'poprzedni'
	$('.footer .useful_links .prev').live('click', function(){
		var elems = $(this).parent().children().not('.prev, .prev_hide, .next, .next_hide')
		var countAll = $(elems).length;
		var countShow = 5;
		
		if (index > 0) {
			$(elems).filter(':eq(' + (index - 1) + ')').removeClass('hide');
			index--;			
			if ((index + countShow) < countAll) $('.footer .useful_links .next_hide').removeClass('next_hide').addClass('next');
		}	
		if(index == 0)  $(this).removeClass('prev').addClass('prev_hide');

		return false;
	});	
	
	$('.footer .useful_links .prev_hide, .footer .useful_links .next_hide').live('click', function(){
		return false;
	});
	
	// SELECT MENU
	$('.select_menu ul').css('display','none');
	$('.select_menu p').click(function(){
		$(this).next('ul').slideToggle('fast');
	});
	
	// POWIEKSZENIE/ZMNIEJSZENIE TEKSTU	
	// pobranie klasy czcionki z ciasteczka
	var fontSize = $.cookie('textsizer');
	if (typeof fontSize != "undefined" && fontSize != null && fontSize != "") {
		$('.content .text').addClass(fontSize);
	}
	
	// obsługa zmiany wiekosci fontu
	$('.textSizer li a').click(function(){
		var select = $(this).parent('li').attr('class');

		switch(select){
			case 'maly':
			fontSize = 'font_small';
			break;			
			case 'duzy':
			fontSize = 'font_large';
			break;
			default:
			fontSize = 'standard';
			break;
		}
		
		if(fontSize != 'standard'){
			$('.content .text, .content .left_menu').removeClass('font_small');
			$('.content .text, .content .left_menu').removeClass('font_large');
			$('.content .text, .content .left_menu').addClass(fontSize);
			$.cookie('textsizer', fontSize, {expires: 1, path: '/'});
		}else{
			$('.content .text, .content .left_menu').removeClass('font_small');
			$('.content .text, .content .left_menu').removeClass('font_large');
			$.cookie('textsizer', null, {path: '/'});
		}
		
		return false;
	});
	
	// KOLOROWE OBRAZKI NA MOUSEOVER
	$('.footer .useful_links li canvas, .footer .useful_links li img').live('mouseover',function(){
		Pixastic.revert(this);
	});

	$('.footer .useful_links li img').mouseout(function(){
		$(this).pixastic('desaturate');
	});
	
	// KALENDARZ
	// pokaż/ukryj chmurkę
	$('.tx-cal-controller .eventDay').not('.monthOff').hover(function(){
	  $(this).children().addClass('relative');
		$(this).children().children('.info').css('display', 'block');
	}, function(){
	  $(this).children().removeClass('relative');
		$(this).children().children('.info').css('display', 'none');
	});	
	
	// dodawanie hasha do nawigacji między miesiącami
	var view_href = $('.tx-cal-controller .view_type a').eq(0).attr('href');
	$('.tx-cal-controller .view_type a').eq(0).attr('href', view_href+location.search);
	
	view_href = $('.tx-cal-controller .view_type a').eq(1).attr('href');
	$('.tx-cal-controller .view_type a').eq(1).attr('href', view_href+location.search);
	
	// bugfix - podmiana wykrzaczonych nazw polskich miesiecy
	var month = $('.tx-cal-controller .month_nav span');
  var str_month = $(month).text();
  var eventDay = $('.eventDay span.date, .calendar_list span.date');
  var str_eventDay;
  switch (str_month.slice(0,2)) {
    case 'st':
    $(month).text('styczeń');
    $(eventDay).each(function(){
      $(this).text('styczeń' + $(this).text().slice($(this).text().length-3));
    });
    break;
    case 'kw':
    $(month).text('kwiecień');
    $(eventDay).each(function(){
      $(this).text('kwiecień' + $(this).text().slice($(this).text().length-3));
    });
    break;
    case 'si':
    $(month).text('sierpień');
    $(eventDay).each(function(){
      $(this).text('sierpień' + $(this).text().slice($(this).text().length-3));
    });
    break;
    case 'wr':
    $(month).text('wrzesień');
    $(eventDay).each(function(){
      $(this).text('wrzesień' + $(this).text().slice($(this).text().length-3));
    });
    break;
    case 'pa':
    $(month).text('październik');
    $(eventDay).each(function(){
      $(this).text('październik' + $(this).text().slice($(this).text().length-3));
    });
    break;
    case 'gr':
    $(month).text('grudzień');
    $(eventDay).each(function(){
      $(this).text('grudzień' + $(this).text().slice($(this).text().length-3));
    });
    break;
    default:
    
  } 

	
	// MENU 'NA SKROTY'
	$('.main_menu .shortcuts p:first').toggle(
  function(){
    $('.headline .select_menu').hide();
		$('.main_menu .shortcuts ul.shortcut_links').show();
		$(this).addClass('shortcuts_active');		
	},
	function(){		
		$('.main_menu .shortcuts ul.shortcut_links').hide();
		$(this).removeClass('shortcuts_active');
		$('.headline .select_menu').show();
	});
	
	// WYRÓWNANIE BLOKÓW MENU
	var menu_i = 0;
	$('.teaser_menu li').each(function(){
		if($(this).height() < $(this).next().height() && menu_i%2 == 0){
			$(this).height($(this).next().height());
		} else if($(this).height() > $(this).next().height() && menu_i%2 == 0){
			$(this).next().height($(this).height());
		}		
		menu_i++;
	});
	
	// POLEĆ ZNAJOMEMU KOPIOWANE ZE STOPKI
	$('.article_tools .mail a').attr('href', $('.footer_links .last a').attr('href'));
		
  
  // PDF PRINT
  if($('.article_tools .pdfprint a').length > 0){
    var pdf_href = $('.article_tools .pdfprint a').attr('href');
    pdf_href = pdf_href.slice(0,pdf_href.length-1);
    if(pdf_href.indexOf("?") != -1){      
    	$('.article_tools .pdfprint a').attr('href', pdf_href+'&type=110');
    } else{
      $('.article_tools .pdfprint a').attr('href', pdf_href+'?type=110');
    }
  }
  
});

$(window).load(function(){
	
	// DESATURACJA ZDJĘĆ
	$('.footer .useful_links img').pixastic('desaturate');
	
	// PRAWA KOLUMNA W NEWSACH 
	// jeżeli prawa kolumna jest dłuższa niż content div z contentem ma przypisaną wysokość
	if($('.news_article').length > 0){
  	if($('.news_article .stuff').height() > $('.news_article').height()){
      $('.news_article').height($('.news_article .stuff').height()+'px');
    }
  }

});