var newClass = function() {
	return function() {
		return this.init.apply(this, arguments);
	}
}
// JavaScript Для прокрутки логотипов на главной странице сайта ===================>>>
var logoList = newClass();
logoList.prototype = {
  init: function() {
	 var t = this;

     t.ElementGL = $("div.RamkaGray");
     t.GaleryList = $("div.SlideOC");
     t.ContGalery = $("div.GalleryOC");
     t.scrollStarted = false;
     t.global = false;
     t.prevStop = false;
     t.first = true;
     t.documentWidth = document.documentElement.clientWidth || document.body.clientWidth;

     $(".RightOC").click(function(e){
       e.preventDefault();
       e.stopPropagation();
       t.arrowClick(true);
     });

     $(".LeftOC").click(function(e){
       e.preventDefault();
       e.stopPropagation();
       t.arrowClick(false)
     });

     t.ContGalery.mouseleave(function(){
       t.stopScrolling();
     });

     t.ContGalery.mouseenter(function(){
       t.startScrolling();
     });

     $('document').ready(function(){
        t.changeSpeed();

        t.ContGalery.mousemove(function(e){
          t.setSpeed(e);
        });

     });

  },

  arrowClick: function(param) {
    var t = this;
    if(param)
      t.direction = 1;
    else
      t.direction = -1;

    t.startScrolling();
    t.stopScrolling();
  },

  startScrolling: function() {
    var t = this;

    if(t.scrollStarted == false) {
         t.scrollStarted = true;
         t.prevStop = false;
         t.global = true;
         t.Scrolling();
    }
  },

  stopScrolling: function(hardStop) {
    var t = this;
      if(t.prevStop == true) {
         t.global = false;
         t.scrollStarted = false;
      } else if(hardStop == true) {
         t.global = false;
         t.scrollStarted = false;
      }
         t.prevStop = true;
  },

  setSpeed: function(e) {
    var t = this;
    t.global = true;
    t.prevStop = false;
    var pageCoords = e.pageX;
    var clientCoords = e.clientX;

    percentSpeed = (100 * (e.pageX - t.documentWidth/2)) / (t.ContGalery.width() / 2);
    percentSpeedNormal = 100 - Math.abs(percentSpeed);

    //t.motionTime = Math.ceil(percentSpeedNormal * 100 / 100) ;

    if(percentSpeed < 0)
      t.direction = -1;
    else
      t.direction = 1;
  },

  changeSpeed: function()
  {
    var t = this;

    t.direction = 1;
    t.widthDiv = 165;
    t.Offset = 1;
    t.motionTime = 10;

    t.replaceTime = t.motionTime * t.widthDiv / t.Offset;

    t.countOffset = null;
  },

  Scrolling: function()
  {
    var t = this;

    if(t.global == true) {

      leftPosition = t.GaleryList.css("left").replace('px', '') * 1 - ((t.Offset) * t.direction);
      t.GaleryList.css("left", leftPosition);

      if(t.direction == -1 && t.countOffset == null && t.first) {
         t.countOffset = 0;
         t.first = false;
      }

      if(((Math.abs(t.countOffset) >= t.widthDiv - 1) || t.countOffset == 0)) {
        t.replace();
        t.countOffset = null;
      } else {
        t.countOffset = t.countOffset + ((t.Offset ) * t.direction );
      }

      t.inter = setTimeout(function(){ t.Scrolling(); }, t.motionTime);
    }
  },

  replace: function()
  {
    var t = this;

    if(t.prevStop == true)
        t.stopScrolling();

    n = t.GaleryList.css("left").replace('px', '') * 1 + t.widthDiv * t.direction;
    t.GaleryList.css("left", n);

      if(t.direction > 0) {
        k = $("div.RamkaGray:last").attr('id');
        $("div.RamkaGray:first").insertAfter("#" + k);
      } else {
        k = $("div.RamkaGray:first").attr('id');
        $("div.RamkaGray:last").insertBefore("#" + k);
      }
  }
};
// <<<=================== JavaScript Для прокрутки логотипов на главной странице сайта
