var unit = "px";
var keepScrolling = true;
var moveAmount = 2;

function scrollImages(groupID, imageHeight, scrollDelay, imageDelay){
    var counter = 1;
    var images = new Array();
    
    while(document.getElementById(groupID + counter) != null){
		images[counter - 1] = document.getElementById(groupID + counter);
		counter++;
    }

    images[0].style.top = 0 + unit;
    images[0].style.display = "block";
    for(counter = 1; counter < images.length; counter++){
        images[counter].style.top = imageHeight + unit;
        images[counter].style.display = "block";
    }
    
	setTimeout(function(){scroll(images, 0, imageHeight, scrollDelay, imageDelay)}, imageDelay);
}

function scroll(images, firstImage, imageHeight, scrollDelay, imageDelay){
	var image1 = images[firstImage];
	var secondImage = 0;
	var thirdImage = 0;
	var image2 = null;
	
	if(firstImage + 1 < images.length){
		secondImage = firstImage + 1;
	}
	
	image2 = images[secondImage];
	
	if(keepScrolling){
		image1.style.top = (image1.style.top.replace(unit,"") - moveAmount) + unit;
		image2.style.top = (image2.style.top.replace(unit,"") - moveAmount) + unit;
	}
	
	if(image2.style.top != "0px"){
		setTimeout(function(){scroll(images, firstImage, imageHeight, scrollDelay, imageDelay)}, scrollDelay);
	}
	
	if(image2.style.top == "0px"){
		if(secondImage + 1 < images.length){
			thirdImage = secondImage + 1;
		}
		
		image1 = images[thirdImage];
		image1.style.top = (image2.style.top.replace(unit,"") + imageHeight) + unit;
		setTimeout(function(){scroll(images, secondImage, imageHeight, scrollDelay, imageDelay)}, imageDelay);
	}
}

function pause(){
	keepScrolling = false;
}

function unPause(){
	keepScrolling = true;
}	
