$(document).ready(function(){
  //FANCYBOX
  $(".termek .img_container a").fancybox({
    'titleShow' : true,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn' : 'easeOutBack',
    'easingOut' : 'easeInBack',
    'titlePosition' : 'over' 
  });  
  

  //config variables
  var autoscroll_on = true;
  var autoscroll_speed = 5000; //speed in millisec
  
  
  //script variables
  kepek_szama = $("#header .img_container img").length-1; 
  aktualis_szam = 0;


  /******AUTO SCROLL START******/
  if (autoscroll_on && kepek_szama > 1) {
    var timer;

    
    //autoscroll function
    function autoscroll () {
      timer = setInterval(next, autoscroll_speed);
      
      return timer;
    }
    
    
    //scrolls to 0 position
    function resetslide () {$(".img_container img").hide();}
    
    
    //scrolls items right
    function next () {
      //when last item displayed autoscroll starts over 
      if (aktualis_szam == kepek_szama) {
        resetslide (); 
        $(".img_container img:eq(0)").show();
        aktualis_szam = 0;
      }
      
      else {
        resetslide (); 
        aktualis_szam = aktualis_szam + 1;
        
        $(".img_container img:eq(" + aktualis_szam + ")").show();
      }
    }
    
    
    //hover function, stops autoscroll on mouseover / starts autoscroll on mouseout
    $(".news").hover(
      function() {clearInterval(timer);},
      function() {autoscroll ();}
    );
    
    autoscroll ();
  }
  /******AUTO SCROLL END******/
});
