

<!--
Cufon.replace('#header > ul > li:not(.selected) > a', {
  color: '#353536',
  hover: {
    color: '#4e8800'
  }
});
Cufon.replace('#header > ul > li.selected > a', {
  color: '#4e8800'
});
Cufon.replace('h2, h3, #sidelink, #error404 *');
$(function(){
  $('ul.slider > li > p').click(function(){
    var p = $(this), li = p.parent();
    li.toggleClass('active');
    p.next().slideToggle();
  });
  
  $('#content div.news a.more').click(function(){
    var a = $(this), txt = a.text();
    a.text( txt === 'rozwiń' ? 'zwiń' : 'rozwiń');
    a.prev().slideToggle();
    return false;
  });
  
  $('.support > div.img > img').each(function(){
    var img = $(this), alt = img.attr('alt');
    if (alt) {
      img.after('<span>' + alt + '</span>');
    }
  });
  $('#content ul.support-container').each(function(){
    var c = $(this),
      li = c.find('li'),
      rows = Math.floor(li.length/6),
      foo = li.length - 7,
      items = foo < 0 ? ':eq(0), :gt(0)' : ':gt(' + foo + ')';
    li.filter(':nth-child(6n), :last').addClass('nobr-right');
    li.filter(items).addClass('nobr-bottom');
  });
  
  $('#content ul.support-container .support-link img').hover(
    function(){
      var i = $(this);
      if ($.browser.msie) {
        i.css('z-index', '1').stop().animate({
          width: 177,
          height: 121,
          top: -11,
          left: -11,
          border: '1px solid #dbdbdb'
        }, 100);
      } else {
        i.css('z-index', '1').stop().animate({
          width: 177,
          height: 121,
          top: -11,
          left: -11,
          border: '1px solid #dbdbdb',
          '-webkit-box-shadow': '0 0 20px #aaa',
          '-moz-box-shadow': '0 0 20px #aaa',
          'box-shadow': '0 0 20px #aaa'
        }, 100);
      }
    },
    function(){
      var i = $(this);
      if ($.browser.msie) {
        i.css('z-index', '0').stop().animate({
          width: 155,
          height: 99,
          left: 0,
          top: 0,
          border: 0
        }, 100);
      } else {
        i.css('z-index', '0').stop().animate({
          width: 155,
          height: 99,
          left: 0,
          top: 0,
          border: 0,
          '-webkit-box-shadow': '0 0 0 #000',
          '-moz-box-shadow': '0 0 0 #000',
          'box-shadow': '0 0 0 #000'
        }, 100);
      }
    }
  );
  
  
  $('#sitemap > ul > li:last').addClass('last');
  
  $('#captcha a').click(function(){
    $('#captcha-img').attr('src', '/captcha.php?x=' + Math.random().toString().slice(2));
    return false;
  });
  if ($.fn.validate) {
    $('#contact').validate({
      rules: {
        email: {
          required: true,
          email: true
        },
        pytanie: 'required',
        captcha: 'required'
      },
      highlight: function(el, errorClass) {
        if ($(el).is(':checkbox')) {
          $(el).next('label').addClass('error');
        } else {
          $(el).addClass('error');
        }
      },
      unhighlight: function(el, errorClass) {
        if ($(el).is(':checkbox')) {
          $(el).next('label').removeClass('error').show();
        } else {
          $(el).removeClass('error');
        }
      },
      errorPlacement: function() {
        return false;
      },
      submitHandler: function(form){
        $.ajax({
          url: '/wyslij.php',
          data: $(form).serialize(),
          dataType: 'json',
          type: 'post',
          beforeSend: function(){
            $('.error', form).removeClass('error');
          },
          success: function(re){
            if (re.wynik === 'blad') {
              $.each(re.bledy, function(id, val){
                $(':text[name=' + val + '], textarea[name=' + val + ']', form).addClass('error');
              });
            } else if (re.wynik === 'ok') {
              $('fieldset', form).replaceWith('<h4 id="contact-thanks" style="display: none;">Wiadomość wysłana pomyślnie. Dziękujemy!</h4>')
              $('#contact-thanks').fadeIn();
            }
          }
        });
        return false;
      }
      
    });
    $('#payment-form').validate({
      rules: {
        first_name: {
          required: true,
          namePL: true
        },
        last_name: {
          required: true,
          namePL: true
        },
        kwota: {
          required: true,
          amount: true
        },
        desc: 'required',
        post_code1: {
          postcodeFirst: true,
          maxlength: 2
        },
        post_code2: {
          postcodeLast: true,
          maxlength: 3
        },
        street: {
          cityPL: true
        },
        street_hn: {
          street_hn: true
        },
        city: {
          cityPL: true
        },
        email: {
          email: true
        },
        zgoda: 'required'
      },
      highlight: function(el, errorClass) {
        if ($(el).is(':checkbox')) {
          $(el).next('label').addClass('error');
        } else {
          $(el).addClass('error');
        }
      },
      unhighlight: function(el, errorClass) {
        if ($(el).is(':checkbox')) {
          $(el).next('label').removeClass('error').show();
        } else {
          $(el).removeClass('error');
        }
      },
      errorPlacement: function() {
        return false;
      },
      submitHandler: function(form){
        var a = $("#kwota-id").val();
        a = Math.round(parseFloat(a.replace(/,/g, ".")) * 100);
        b = $("#post_code1").val() + "-" + $("#post_code2").val();
        $("#amount").val(a);
        $("#post_code").val(b);
        $(form).unbind('submit').submit();
        return false;
      }
    });
  }
    function requirePostcode(changed, required) {
        if (changed.val().length > 0) {
            required.rules('add', {
                required: true
            });
        } else {
            required.rules('add', {
                required: false
            });
            if (required.val().length == 0) required.removeClass('error');
        }
    }
  
    if ($('form#payment-form').length > 0) {
        requirePostcode($('#post_code1-id'), $('#post_code2-id'));
        requirePostcode($('#post_code2-id'), $('#post_code1-id'));
        $('#post_code1-id').keyup(function() {
            requirePostcode($(this), $('#post_code2-id'));
        });
        $('#post_code2-id').keyup(function() {
            requirePostcode($(this), $('#post_code1-id'));
        });
    }
  $('#payment-form input[name=js]').val(1);
  $('#content a[href*=.doc]').addClass('doc');
  $('#content a[href*=.pdf]').addClass('pdf');
  $('body.home div.col').click(function(){
    window.location = '/aktualnosci.html';
  });

  var img = new Image();
  var src = $('.home #slider img:first').attr('src');
  
  function slide(){
    if ($('.home #slider img:visible').next().length) {
      $('.home #slider img:visible').fadeOut(4000).next().fadeIn(4000);
    } else {
      $('.home #slider img:visible').fadeOut(4000).siblings('img:eq(0)').fadeIn(4000);
    }
  }
  
  $(img).load(function(){
    $('.home #slider img:first').replaceWith(this);
    var o = $('.home #slider img:first');
    o.parent().css('background', '#fff');
    o.fadeIn(4000, function(){
      var run;
      run = setInterval(slide, 10000);
    });
  }).attr('src', src);
  $('body.home div.columns p').each(function(){
    var p = $(this), t = p.text();
    if (t.length > 175) {
      p.text(t.slice(0,175) + '...');
    }
  });
if ($('.galleries.single').length > 0) {
if (rd == false) {
    var params = [];
    var url = document.location.search.substr(1);
    url = url.split('&');
    $.each(url, function(i, val) {
        val = val.split('=');
        params[val[0]] = val[1];
    });
    var l           = $('.galleries li').size(),
        perPage     = 12;
    
    var pages = Math.ceil(l/perPage);    
    //params.page = parseInt(params.page);
    if (params.page < 1 || params.page == '' || params.page == undefined) params.page = 1; 
    if (params.page > pages) params.page = pages; 
    
    
    if (pages > 1) {
        var firstPage = (params.page - 1) * perPage;
        for (i = 0; i < firstPage; i++) $('.galleries li:first-child').remove();
        $('.galleries li').each(function() {
            if ($(this).index()+1 > perPage) $(this).remove();
        });
    
        $('.galleries').after('<ul class="pagination"></ul>');
        for (i = 1; i <= pages; i++) {
            $('.pagination').append('<li><a href="?page='+i+'">'+i+'</a></li>');      
            if (i == params.page) $('li:last-child a').addClass('active');
        }
        
        if (pages >= 10) {
            $('.pagination li').each(function() {
                if ($(this).index()+1 > 3 && $(this).index() < pages-3) {
                    $(this).hide();
                }
            });
            $('.pagination li').eq(params.page-1).show().next().show().prev().prev().show();
            if (!$('.pagination li').eq(3).is(':visible')) $('.pagination li').eq(2).after('<li class="dots">...</li>')
            if (!$('.pagination li').eq(pages-3).is(':visible')) $('.pagination li').eq(pages-2).before('<li class="dots">...</li>')
            if ($('.dots').length > 1)  $('.dots').eq(0).remove();
        }
        
        $('.pagination li:visible').not(':last-child').after('<li class="slash">/</li>');
        
        if (params.page != 1) $('.pagination').prepend('<li class="prev"><a href="?page='+(params.page-1)+'">poprzednia</a></li>');
        if (params.page != pages) $('.pagination').append('<li class="next"><a href="?page='+(params.page+1)+'">następna</a></li>');
        
    }
}
}
var l = $('.galleries').length;
$('.galleries li:nth-child(4n)').css('border-right', '0');
$('.galleries li:nth-child(4n)').css('border-right', '0');
$('.galleries li:nth-child(4n + 1) a').css('padding-left', '15px');
var l = $('.galleries li').size();
var mod = l % 4;
if (mod == 0) {
    for (i = 0; i < 4; i++) {
        $('.galleries li:nth-child('+(l-i)+')').css('border-bottom', '0');
    }
} else {
    for (i = 0; i < mod; i++) {
        $('.galleries li:nth-child('+(l-i)+')').css('border-bottom', '0');
    }
}
if($('.galleries.open').length > 0) $('.galleries li a.open').fancybox({
    'padding': '15',
    'overlayOpacity': '0.8',
    'overlayColor': '#ffffff',
    'centerOnScroll': true
});
$('#fbIcon a').click(function() {
    window.open ("http://www.facebook.com/sharer.php?u=http://www.fundacja10kwietnia.pl/index.html&t=Fundacja%2010%20kwietnia","fbshare","width=500,height=400");
    return false
});
});
//-->

