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.sendMessage("Tree","SelectNode","ItemPath="+his[cP]);
  }
}

function forward() {
  if(!(cP > (his.length-1)) && his[cP+1] != undef) {
    cP++;
    belenusHome.sendMessage("Tree","SelectNode","ItemPath="+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 resetHistory() {
	cp = 0;
	his = new Array();
}

function IPHistory() {
  this.back = back;
  this.forward = forward;
  this.add = add;
  this.resetHistory = resetHistory;
}

var IPH = new IPHistory();

/*
* e.g.
* var IPH = new IPHistory();
* IPH.back();
* IPH.forward();
* IPH.add(treepath),
*/
