dsFlip = {
	
	d: document,
	imgSets: new Object(),
	flipping: false,
	currFlipID: null,
	flipTimer: 0,
	flipInterval: 800,
	
	regTrgt: function(imgID, startIndex){
		
		// verify that the image target exists
		var trgt = this.d.getElementById(imgID);
		var entryExists = this.imgSets[imgID];
		var startIndex = startIndex ? startIndex : 0;		

		if(trgt && !entryExists){
			
			this.imgSets[imgID] = new Object();
			
			this.imgSets[imgID].trgt = trgt;
			this.imgSets[imgID].images = [trgt.src];
			this.imgSets[imgID].lastIndex = startIndex;
			this.imgSets[imgID].imagesLen = 1;
			
		}
	},
	
	regImg: function(imgID, imgLoc){
		
		var entryExists = this.imgSets[imgID];
		
		if(entryExists){
			
			this.imgSets[imgID].images.push(imgLoc);
			this.imgSets[imgID].imagesLen = this.imgSets[imgID].images.length;
					
		}
		
	},
	
	trimFirst: function(imgID){
		
		var entryExists = this.imgSets[imgID];
		
		if(entryExists){
			
			this.imgSets[imgID].images.shift();
			this.imgSets[imgID].imagesLen = this.imgSets[imgID].images.length;
			
		}
		
	},
	
	startFlip: function(imgID){
		
		if(this.flipTimer != null){
			
			window.clearTimeout(this.flipTimer);
			this.flipTimer = null;
			
		}
		
		this.flipping = true;
		this.currFlipID = imgID;
		
		this.doFlip();
		
	},
	
	stopFlip: function(){
		
		this.flipping = false;
		
	},
	
	doFlip: function(){
		
		if(dsFlip.flipping){
			
			var thisImgSet = dsFlip.imgSets[dsFlip.currFlipID];
			
			if(thisImgSet){
				
				var nextID = thisImgSet.lastIndex + 1;
				
				thisImgSet.lastIndex = (nextID > (thisImgSet.imagesLen - 1)) ? 0 : nextID;
				thisImgSet.trgt.src = thisImgSet.images[thisImgSet.lastIndex];
				
				dsFlip.flipTimer = window.setTimeout(dsFlip.doFlip, dsFlip.flipInterval);
				
			}
			
		}
		
	}
	
}

dsFlip.stopFlip();
