interval=10;
px_step=3;
padding=18;

function move(mv, ln, direction, m_type) {
  var move=document.getElementById(mv);
  var line_width=document.getElementById(ln).offsetWidth;
  var move_block_width=parseInt(move.offsetWidth/2);
  var left_pos=move_block_width;
  var i;
  if (move.style.left) left_pos=-parseInt(move.style.left);

  if (m_type=="smooth") timer=setInterval(function() {
    if (direction=="right") left_pos+=px_step; else left_pos-=px_step;
    if (left_pos>2*move_block_width-line_width) left_pos-=move_block_width;
    if (left_pos<  move_block_width-line_width) left_pos+=move_block_width;
    move.style.left=-left_pos+"px";
  }, interval)
  else { /* jump */
    stop();
    imgList=move.getElementsByTagName("IMG");
    if (direction=="right") {
      for (i=0;imgList[i].offsetLeft+imgList[i].offsetWidth<left_pos+line_width;i++);
      left_pos=imgList[i].offsetLeft+imgList[i].offsetWidth-line_width+padding;
      if (left_pos>2*move_block_width-line_width-imgList[i].offsetWidth) left_pos-=move_block_width;
    }
    else { /* left */
      for (i=0;imgList[i].offsetLeft+imgList[i].offsetWidth<left_pos-padding;i++);
      left_pos=imgList[i].offsetLeft-padding;
      if (left_pos<move_block_width-line_width-padding) left_pos+=move_block_width;
    }
    move.style.left=-left_pos+"px";
  }
}

function stop() { clearInterval(timer) };
