var cP = 0; //current position
var his = new Array(); // history array
var undef;

function back() {
  if(!(his.length < 1) && his[cP-1] != undef) {
  if(belenusHome.currentTreePath == his[(cP-1)]) { // if u go the first time backward
    cP =   cP-2;
  }else {
    cP--;
  }
    belenusHome.belLocateInCatalog(his[cP]);
  }
}

function forward() {
  if(!(cP > (his.length-1)) && his[cP+1] != undef) {
    cP++;
    belenusHome.belLocateInCatalog(his[cP]);    
  } 
}

function add(treepath) {
  if(treepath == his[cP] || treepath == his[cP-1]) {
  } else {
  	if(his.length != cP) {
    	his = his.slice(0,eval(cP+1));
  }
    cP++;
    his[his.length] = treepath;
  }
  var laGatta = "";
  for(var i = 0; i < his.length; i++) {
  	laGatta += i+":"+his[i]+"\n";
  }
  	laGatta += "\n\ncP:"+cP;
}

function IPHistory() {
  this.back = back;
  this.forward = forward;
  this.add = add;
}

var IPH = new IPHistory();

/*
* e.g.
* var IPH = new IPHistory();
* IPH.back();
* IPH.forward();
* IPH.add(treepath),
*/
