var curPos = 0; var curPage = 0; var curTo = null; var curNew = 0; function scrollAds (dir) { var obj = document.getElementById('featuredDiv'); // In case they click while it's moving... if (curTo) { clearTimeout(curTo); document.getElementById('featuredDiv').style.left = curNew + 'px'; curPos = curNew; } var newPos = curPos + ( dir * 661 ); if ((dir < 0 && curPage < maxPage - 1) || (dir > 0 && curPage)) { curNew = newPos; curPage -= dir; moveAds(newPos); } } function moveAds (newPos) { var delay = 100; var diff = Math.abs(newPos - curPos); var pos = Math.floor((newPos - curPos) / 2) + curPos; // If it's within 5 pixles..... if (diff < 5) pos = newPos; document.getElementById('featuredDiv').style.left = pos + 'px'; curPos = pos; if (curPos != newPos) curTo = setTimeout('moveAds('+ newPos +')',delay); else curTo = null; }