I can't figure out what is wrong with this code. Firefox's error console tells me: "this.animateImgSlider is not a function".
What I would like is to call this.selectImage() with jsItems[0].selectImage(0) and then have this.animateImgSlider() be called some number of times until selfCall is false:
function WindowItem(inId) { this.id = inId; this.imgSliderTarget = 0; this.imgSlider = document.getElementById("imgSlider"+inId); this.animateImgSlider = function() { var selfCall = true; var currLeft = parseInt(this.imgSlider.style.left, 10); if (currLeft < this.imgSliderTarget) { currLeft += 8; if (currLeft >= this.imgSliderTarget) { currLeft = this.imgSliderTarget; selfCall = false; } } else { currLeft -= 8; if (currLeft <= this.imgSliderTarget) { currLeft = this.imgSliderTarget; selfCall = false; } } this.imgSlider.style.left = currLeft+"px"; if (selfCall) setTimeout("this.animateImgSlider()", 0); } this.selectImage = function(inImg) { this.imgSliderTarget = -inImg*488; this.animateImgSlider(); } } var jsItems = new Array(); jsItems.push(new WindowItem(0)); This line is the one that throws the error:
if (selfCall) setTimeout("this.animateImgSlider()", 0);