$('.tabs .tab h2').click(function() 
{
  $('.tabs .tab').removeClass('tab-open');  
  $(this).parent().addClass('tab-open');  
  return false;    
});

$.tools.validator.localize('pl', {
  '*'          : 'Popraw tę wartość',
  ':email'     : 'Wprowadź poprawny adres e-mail',
  ':number'    : 'Wprowadź wartość numeryczną',
  ':url'       : 'Wprowadź poprawny URL',
  '[max]'      : 'Wprowadź wartość mniejszą niż $1',
  '[min]'      : 'Wprowadź wartość większą niż $1',
  '[required]' : 'To pole jest wymagane'
});

// initialize validator and add a custom form submission logic
$("#newsletter").validator({lang: 'pl'}).submit(function(e) {

  var form = $(this);

  // client-side validation OK.
  if (!e.isDefaultPrevented()) {
    
    // submit with AJAX
    $.getJSON(TA_BASE_DIR+"/newsletter?" + form.serialize(), function(json) {
      
      // everything is ok. (server returned true)
      if (json === 1)  {
        form.html('<p class="ok">Twój adres e-mail został dodany.</p>');
      // server-side validation failed. use invalidate() to show errors
      } else {
        form.data("validator").invalidate(json);
      }
    });

    // prevent default form submission logic
    e.preventDefault();
  }
});

if ($(".slidedots").length) 
{
  $(".slidedots").tabs(".slide", {
    interval: "8000",
    autoplay: true,
    rotate: true
  }).slideshow({autoplay: true});
}

if ($("#realizacja").length) 
{
  $("#realizacja .dots").tabs("#realizacja .images img", {
    effect: 'fade',
    fadeOutSpeed: "slow",
    interval: "1000",
    autoplay: true,
    rotate: true
  }).slideshow({autoplay: true});
}


$("#historia .lata").tabs("#historia .tab");

var current2 = 0;
$('#historia .prev').click(function()
{
  var left = parseInt($("#historia .lata ul").css('left'));
  if (current2 > 0 ) 
  {
    current2 = current2 - 1;  
    $("#historia .lata ul").animate({left: (left + 50) + "px"}, 0);      
  }  
  return false;
});

$('#historia .next').click(function()
{
  var count = $("#historia .lata li").length;
  var left = parseInt($("#historia .lata ul").css('left'));
  if (current2 < count - 13) 
  {
    current2 = current2 + 1;  
    $("#historia .lata ul").animate({left: (left - 50) + "px"}, 0);      
  }  
  return false;
});
