$(document).ready(function() {

  var scroller = $('.scrolling');
  scroller.each(function() {
    var container = $(this).find('.scrolling-container');
    var oneline = $(this).is('.scrolling-oneline');
    var tape = $(this).find('.scrolling-tape');

    var next = $(this).find('.next');
    var prev = $(this).find('.prev');

	//Begin
	/*check*/
    var elLength = $(this).find('.scrolling-tape ul:first li').length;
    if (elLength==0) elLength = 16;
    var elWidth = 178;

    var scrollStep = 4 * elWidth;
    var scrollMax,
        scrollPosition = 0;
	/*check*/

    if ($('ul', tape).length < 2) {
      if (oneline) {
        scrollMax = elWidth * elLength - scrollStep;
        tape.width(elWidth * elLength);
      } else {
        scrollMax = elWidth * (elLength / 2) - scrollStep;
        tape.width(elWidth * (elLength / 2));
      };
    } else {
      scrollMax = elWidth * elLength - scrollStep;
      tape.width(elWidth * elLength);
    }
    //step
    // container.scrollLeft(scrollPosition);
    prev.addClass('prev-disabled');
    next.click(function() {
    	//var content = $.get('index_ajax1.php');
		//$('#in_99999').load('index_ajax1.php');

      if (!$(this).is('.next-disabled')) {
        prev.removeClass('prev-disabled');

		if (scrollPosition + scrollStep < scrollMax) {
          scrollPosition = scrollPosition + scrollStep;

			if (scrollMax > 2000) {
          //scrollPosition = scrollPosition + scrollStep;
			//next.addClass('next-disabled');
			}

        } else {
          scrollPosition = scrollMax;
          next.addClass('next-disabled');
        };


        tape.animate({
          left: scrollPosition * -1
        }, 'slow');
      };
    });
	//End
    prev.click(function() {
      if (!$(this).is('.prev-disabled')) {
        next.removeClass('next-disabled');
        if (scrollPosition - scrollStep > 0) {
          scrollPosition = scrollPosition - scrollStep;
        } else {
          scrollPosition = 0;
          prev.addClass('prev-disabled');
        };
        tape.animate({
          left: scrollPosition * -1
        }, 'slow');
      };
    });
  });

});
