// ************* HISTORY *********

function grlHistory() {
 this.current=-1;
 this.last=0;
 this.pages=new Array;
 this.canback = 0;
 this.canforward = 0;
}

grlHistory.prototype.store=function() {
 var n=++this.current;
 this.pages[n]=new Object;
 for(var i in grl_maps) {
  this.pages[n][i]= new Object;
   for(var k in grl_maps[i].region) {
     this.pages[n][i][k] = grl_maps[i].region[k];
   } 
 }
 this.last=this.current;
 this.whatcan();
}

grlHistory.prototype.read=function(n) {
 for(var i in this.pages[n]){
   for(var k in this.pages[n][i]) { 
     grl_maps[i].region[k] = this.pages[n][i][k];
   }
 }
 this.current=n;
 this.whatcan();
 grl_drawAll(1);
}

grlHistory.prototype.back=function() { 	
 if(this.current>0) this.read(--(this.current)); 
}

grlHistory.prototype.home=function() { 
 this.current=0; 
 this.read(0); 
}

grlHistory.prototype.forward=function() { 
 if(this.current<this.last) this.read(++(this.current));
}

grlHistory.prototype.whatcan=function() {
 if(this.current > 0) this.canback = 1; else this.canback = 0;
 if(this.current >= 0 && this.current < this.last)
   this.canforward = 1;
 else 
   this.canforward = 0;
}

var grl_history=new grlHistory();


