var width = 6; var direction = 1; function scroll() { var elem = document.getElementById('imagescroll'); if(elem) { var left = getPosition(elem); if(left-1024<-getObjectWidth(elem) || left>=0) { direction = direction * -1 } elem.style.left = left + (width*direction) + 'px'; setTimeout('scroll()',250); } } function getPosition(element) { var tleft = parseInt(element.style.left); if (isNaN(tleft)) tleft = 0; return tleft; } function getObjectWidth(obj) { var result = 0; return parseInt(obj.offsetWidth); } setTimeout('scroll()',250);