function move(i){
  if(i > 0)
  {
    frameNumber ++;
  }
  else if(i < 0)
  {
    frameNumber --;
  }
    
  
  if(frameNumber > totalFrames){
    frameNumber = 1;
  }
  
  $(".arrowLeft").show();
  $(".arrowRight").show();
  
  if(frameNumber == totalFrames){
    $(".arrowRight").hide();
  }
  
  if(frameNumber == 1) {
    $(".arrowLeft").hide();
  }
  
  $(".scrollSet").animate({marginLeft: (-1)*(frameNumber - 1)*$(".scrollWrapper").width() + 'px'}, 500);
}

function startTimer(interval){
	auto = setInterval(function() { move(1) }, interval, 1);
}

function stopTimer(){
	clearInterval(auto);
}

$(document).ready(function(){
  
  startTimer(10000);
  
  $(".arrowLeft").hide();
  if(totalFrames == 1) $(".arrowRight").hide();
  
  $(".arrowLeft").click(
    function(){
      move(-1);
      stopTimer();
    }
  );

  $(".arrowRight").click(
    function(){
      move(1);
      stopTimer();
    }
  );

  $("#listing-Filter select").each(
    function(){
      $(this).change(
        function(){
          window.location = filter_url + '' + this.value;
        }
      );
    }
  );
  
  
  $(".listing-AdListing").each(
    function(){
      $(this).click(
        function(){
          window.location = $(this).children(".listing-AdListing-Title").children("a").attr("href");
        }
      );
      /*
      $(this).hover(
        function(){
          $(this).addClass('listing-AdListing-Hover');
        },
        function(){
          $(this).removeClass('listing-AdListing-Hover');
        }
      );
      */
    }
  );
  
 
});
