/*
Object State v 1.2
copyright 2007 Thomas Frank

This program is free software under the terms of the 
GNU General Public License version 2 as published by the Free 
Software Foundation. It is distributed without any warranty.
*/
objState={
	mem:[],
	objMem:function(obj){
		var m=this.mem;
		for(var i=0;i<m.length;i++){
			if(obj===m[i].obj){return m[i]}
		};
		m.push({obj:obj});
		return m[m.length-1];
	},
	multiGet:function(obj,steps,steps2){
		var a=[];
		for(var i=steps;i<=steps2;i++){
			a.push(this.get(obj,i))
		};
		return a;
	},
	add:function(obj,noRec){
		if(noRec===undefined){noRec=this.noRecursion};
		var x=function(){};
		x.prototype=obj;
		var obj2=new x();
		this.objMem(obj).newobjState=obj2;
		this.objMem(obj2).oldobjState=obj;
		for(var i in obj2){
			if(noRec && typeof obj2[i]=="object"){
				obj2[i]=this.add(obj2[i]);
			}
		};
		return obj2;
	},
	get:function(obj,steps,steps2){
		if(steps2!=undefined){return this.multiGet(obj,steps,steps2)};
		var t=steps<0?"oldobjState":"newobjState";
		var x=this.objMem(obj)[t];
		if(steps>0){steps--};
		if(steps<0){steps++};
		if(steps!=0){x=this.get(x,steps)};
		return x?x:obj;
	}
};
