/**
 * @author Matthew Foster
 * @date   October 24th 2007
 */

var CapsuleIteration = Class.create();
				
Object.extend(Object.extend(CapsuleIteration.prototype, Capsule.prototype),
				{
					initialize : function(){
						
						this.reset();
					
					},
					setData : function(set){
				
						Capsule.prototype.setData.apply(this, arguments);
						this.index = 0;
				
					},
					reset : function(){ 
						
						this.index = 0;
					
					},
					getIndex : function(){
						
						return this.index;
						
					},
					setIndex : function(index){
						
						if(typeof this.dataset[index] == "undefined")
							return false;
						
						this.index = index;
						
						return true;
						
					},
					current : function(){
						
						return this.dataset[this.index];
						
					},
					next : function(){
						
						try{
							return this.dataset[++this.index];
						} 
						catch(e){
							this.index = 0;
							return this.dataset[this.index];								
						}
						
					},
					prev : function(){
						
						try{
							return this.dataset[--this.index];
						}
						catch(e){
							this.index = this.getLength() - 1;
							return this.dataset[this.index];								
						}
						
					},
					hasNext : function(){
						
						return (typeof this.dataset[this.index+1] == "undefined") ? false : true;
													
					},
					hasPrev : function(){
						
						return (typeof this.dataset[this.index-1] == "undefined") ? false : true;
						
					}
				
				
				}
			);