$(document).ready(function() {
  var hidden_image = $('<img src="../images/mouseover.png" class="dodatek" alt=""/>');
  $('.hover-img').hover(function(){
    hidden_image.appendTo($(this)).show();
  },function(){
    hidden_image.hide();
  });
  setInterval(function(){
    $('#bottom-next').animate(
      {top:155}, 50, 
      function(){
        $('#bottom-next').animate({top:158}, 50)
      });
   }, 700);
  setInterval(function(){
    $('#animacja-play').animate(
      {rotate: '+=5deg'}, 50, 
      function(){
        $('#animacja-play').animate({rotate: '-=5deg'}, 50)
      });
  }, 1000);
  $('#bottom-cycle').hover(function(){
    $("#animacja-tlo").attr('src', 'images/bottom-bg-kolor.png');
    $("#bottom-cycle *").css('color','#fff');
    $(".animacja-element").show();
  });
  $('#animacja-play, #samolot').click(function(){
    var i=0;
    $("#animacja-play").hide();
    $('#samolot').animate({
      right: 1300,
      top: 15
    }, 5000, function() {});
    $('#chmura').animate({
      left: 1200
    }, 9000, function() {});
    $('#ptak').animate({
      opacity: 0,
      left: 600,
      top: 10,
      height: 'toggle',
    }, { 
      duration: 5000, step: function(){
      i++;
      if (i==20)
      {
        $('#ptak').rotate('2deg');
        i=-40
      }
      if (i==-20) $('#ptak').rotate('-2deg');
      }
    });
  });
  $('#bottom-cycle').cycle({ 
    fx:     'scrollBothWays', 
		timeout: 0,
    next:   '#bottom-next',
    prev: '#bottom-previous'
  });
  $('#cycler').cycle({ 
    fx:     'scrollBothWays', 
    timeout: 5000, 
    pager:  '#navigation'
  });
  $('#navigation a').text('');	
  $('#pracujemy-cycler').cycle({ 
    fx:     'fade', 
    timeout: 3000
  });
  $('.co-robimy').hover(
    function(){
      src = $(this).attr("src").match(/[^\.]+/) + "active.png";
      $(this).attr("src", src);
    },
    function(){
      src = $(this).attr("src").replace("active", "");
      $(this).attr("src", src);
  });
  $("#formularz").validate();
});
$.fn.cycle.transitions.scrollBothWays = function($cont, $slides, opts) {
  $cont.css('overflow','hidden');
  opts.before.push($.fn.cycle.commonReset);
  // custom transition fn (trying to get it to scroll forward and backward)
  opts.fxFn = function(curr, next, opts, cb, fwd) {
    var h = $cont.height();
    opts.cssFirst = { top: 0 };
    opts.animIn	  = { top: 0 };
    if(fwd){
      opts.cssBefore= { top: h, left: 0 };
      opts.animOut  = { top: 0-h };
    }else{
      opts.cssBefore= { top: -h, left: 0 };
      opts.animOut  = { top: h };
    };
    var $l = $(curr), $n = $(next);
    var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;
    $n.css(opts.cssBefore);
    var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};
    $l.animate(animOut, speedOut, easeOut, function() {
      if (opts.cssAfter) $l.css(opts.cssAfter);
      if (!opts.sync) fn();
    });
    if (opts.sync) fn();
  };
};
