function HxSynchroniser(szName, uiInterval){
	this.vCommands = new Array();
	this.oTimer = null;
	this.uiCnt = 0;
	this.Name = szName;
	this.uiInterval = uiInterval;
}
function outText(szText){
		var pp = document.createElement("p");
		var tt = document.createTextNode(szText);
		document.body.appendChild(pp).appendChild(tt);
}
HxSynchroniser(0, 0);
pr = HxSynchroniser.prototype;
function addC(szCommand, szCondition){
	//alert(szCommand + "," + szCondition);
	try{
	this.vCommands.push({con:szCondition, com:szCommand, del:false});
	if(this.oTimer)clearTimeout(this.oTimer);
	this.oTimer = setTimeout(this.Name+".Work()", this.uiInterval);
	}catch(e){
		for(k in e){
			outText(k+": ->"+ e[k]);
		}
	}
}
pr.addCommand = addC;
function wo(){
	var i = 0;
	var notMade = 0;
	while(i<this.vCommands.length){
		//alert(eval(this.vCommands[i].con)+","+this.vCommands[i].del);
		if(eval(this.vCommands[i].con)&&!this.vCommands[i].del){
			try{	
				eval(this.vCommands[i].com);
				this.vCommands[i].del = true;
			}catch(e){}
		}else if (!this.vCommands[i].del) notMade++;
		i++;
	}
	if(notMade>0){
		clearTimeout(this.oTimer);
		this.oTimer = setTimeout(this.Name+".Work()", this.uiInterval);
	}else{
		//clear allready done
		i = this.vCommands.length-1;
		while(i >= 0){
			try{
				if(this.vCommands[i].del) this.vCommands.splice(i,1);
			}catch(e){
				for(k in e){
					outText(k+": ->"+ e[k]);
				}
			}
			i--;
		}
	}	
}
pr.Work = wo;
delete pr;
oSync = new HxSynchroniser("oSync", 100);
oSync500 = new HxSynchroniser("oSync500", 500);

oSync1 = new HxSynchroniser("oSync1", 100);
oSync2 = new HxSynchroniser("oSync2", 100);



