function tips(id){
	this.id=id;	
	this.cache=[];
	var self=this;	
	DOMReady(function(){
		self.init();
	});
}

tips.prototype.init= function(){
	if (!op.lock(this.id+'__init')) return;	
	this.div=DOM(this.id);
	this.blockID=this.div.getAttribute('rev');
	this.exclude=this.div.getAttribute('rel');	
	
	this.a=this.div.first('a','next');
	
	this.title=DOM(this.id+'_title');
	
	this.body=DOM(this.id+'_body');
	
	this.cache= new Array({id:this.id, title:this.title.innerHTML, body:this.body.innerHTML});
	this.useCache=false;
	this.i=1;
	
	var self=this;
	
	this.a.listen('click', function(e){self.next();return false;});
	if (op.lock('keyboardEvent')){
		DOM(null).listen('keyup',function(e){
			if (e.ctrlKey&&e.keyCode==keyCode.right) self.next();
		});
	}
}

tips.prototype.next= function(e){		
	if (this.useCache){
		this.nextCached();
		return false;
	}
	else if (!op.lock(this.id)) return false;
	
	this.div.attachClass('loading');	
	var self=this;
	this.div.attachClass('loading');	
	op.query(this.a.getAttribute('rel')+'?exclude_'+this.blockID+'='+this.exclude, function(result){
		if (op.select('id',result)){
			var id=op.select('id',result);
			
			self.cache[self.cache.length]={
				id:id, 
				title:op.select('title', result), 
				body: op.select('body',result)
			};
			self.exclude+=','+id;
			self.nextCached();
		}
		else {	
			self.useCache=true;
			self.nextCached();
		}
		self.div.detachClass('loading');		
		op.free(self.id);
	})
}

tips.prototype.nextCached= function(){
	if (this.i>=this.cache.length) this.i=0;
	this.title.innerHTML= this.cache[this.i].title;
	
	this.body.innerHTML=this.cache[this.i].body;
	this.i++;
}
