$(document).ready(function() {

 var $o_newsSlidebar = $('#body > div.body > div.left > div.right > div.newsContent');
 var $o_newsSlidebarNavigation = $('#body > div.body > div.left > div.right > div.newsHeader > ul > li');

 $o_newsSlidebar.slidebar({
  callbackOnAutoroll: function(o_self) { $($o_newsSlidebarNavigation.removeClass('active').get(o_self.getCurrentIndex())).addClass('active'); }
 });
 $o_newsSlidebarNavigation.each(function(index) {
  var i_index = index;
  $(this)
   .click(function() {
    if ($(this).hasClass('active')) return false;
    $o_newsSlidebarNavigation.removeClass('active');
    $o_newsSlidebar.goTo(i_index);
    $(this).addClass('active');
    return false;
   })
   .bind('mouseenter', function() { $o_newsSlidebar.pause(); return false; })
   .bind('mouseleave', function() { $o_newsSlidebar.unPause(); return false; });
 });

 $o_newsSlidebarNavigation.first().addClass('active');

 $('a[href$=#back]').click(function() {
  history.back(-1);
  return false;
 });

 $('#ogloszeniaForm').submit(function() {
  var $o_agree = $(this).find('input[type=checkbox][name=agree]');

  if ($o_agree.length > 0 && !$o_agree.attr('checked')) {
   alert("Musisz zaakceptować politykę prywatności!\nYou have to accept privacy policy!");
   return false;
  }

  return true;
 });

 $('#ogloszeniaForm2').submit(function() {
  if ($("input[type=text][value='']", this).length > 0) {
   alert("Musisz wypełnić wszystkie pola!\nYou have to fill all fields!");
   return false;
  }

  return true;
 });

 $('a.fancybox').fancybox();

});
