var funcA = function(iterable) {
  if (!iterable) return [];

  var results = [];
  for (var i = 0, length = iterable.length; i < length; i++) results.push(iterable[i]);
  return results;

}

    Function.prototype.bind = function() {
  var __method = this, args = funcA(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat(funcA(arguments)));
  }
}

    function cScroller () {
  this.objects = {};
  this.speed = 10;

  this.init = function (objID,state) {
    var obj = {};
    obj.obj = document.getElementById(objID);
    obj.state = state;
    obj.timer = null;
    obj.maxVertScroll = parseInt(obj.obj.scrollWidth) - parseInt(obj.obj.offsetWidth);
    obj.maxHorizScroll = (parseInt(obj.obj.scrollWidth) - parseInt(obj.obj.offsetWidth));
    this.objects[objID] = obj;
  }

  this.down = function (id,timer) {
    if (this.objects[id] == undefined) {
      this.init(id,1);
    }
    var obj = this.objects[id];
    if (timer == undefined) {
      obj.state = 1;
    }

    if ((obj.maxVertScroll > obj.obj.scrollLeft) && (obj.state == 1)) {
      obj.obj.scrollLeft = (obj.obj.scrollLeft + this.speed);
      obj.timer = setTimeout(this.down.bind(this,id,true),50);
    }

  }

  this.right = function (id,timer) {
    if (this.objects[id] == undefined) {
      this.init(id,-2);
    }
    var obj = this.objects[id];
    if (timer == undefined) {
      obj.state = -2;
    }

    if ((obj.maxHorizScroll > obj.obj.scrollLeft) && (obj.state == -2)) {
      obj.obj.scrollLeft = (parseInt(obj.obj.scrollLeft) + this.speed);
      obj.timer = setTimeout(this.right.bind(this,id,true),50);
    }

  }


  this.up = function (id,timer) {
    if (this.objects[id] == undefined) {
      this.init(id,-1);
    }
    var obj = this.objects[id];
    if (timer == undefined) {
      obj.state = -1;
    }

    if ((obj.obj.scrollLeft > 0) && (obj.state == -1)) {
      obj.obj.scrollLeft = (parseInt(obj.obj.scrollLeft) - this.speed);
      if (obj.obj.scrollLeft < 0) obj.obj.scrollLeft = 0;
      obj.timer = setTimeout(this.up.bind(this,id,true),50);
    }
  }


  this.left = function (id,timer) {
    if (this.objects[id] == undefined) {
      this.init(id,2);
    }
    var obj = this.objects[id];
    if (timer == undefined) {
      obj.state = 2;
    }

    if ((obj.obj.scrollLeft > 0) && (obj.state == 2)) {
      obj.obj.scrollLeft = (parseInt(obj.obj.scrollLeft) - this.speed);
      if (obj.obj.scrollLeft < 0) obj.obj.scrollLeft = 0;
      obj.timer = setTimeout(this.left.bind(this,id,true),50);
    }
  }

  this.stop = function (id) {
    if (this.objects[id]) {
      clearTimeout(this.objects[id].timer);
      this.objects[id].state = 0;
    }
  }



}

function mailErr(){
  document.zayavka.onsubmit = function(){
        var eMail = document.getElementById('e-mailerror').value;
        var letter = /^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\.)+[a-z]{2,4}$/;
        var mails = document.getElementById('mails');
        if(!letter.exec(eMail) == false && letter.exec(eMail).length > 0){
          mails.style.display = 'none';
            return true;
        }
        else{
          mails.style.display = 'block';
            return false;
        }     
      }
}

