var GET=function(id){
	var elm=document.getElementById(id);
	return elm;
}

window.onload=function(){
	d=new Demo();
	d.start();	
}

var Demo=function(){
	this.start=function(){
		this.table=GET('scr');
		this.introFadeStep=2;
		this.currentOpacity=100;
		this.intro();
	}
	this.startDemo=function(){
		var op=Math.random();
		var px=this.getRandomPixel();
		px.style.opacity=op;
		px.style.filter='alpha(opacity = '+Math.floor(op*100)+')';
		var self=this;
		var  timeoutFunc=function(){ self.startDemo(); }
		this.time=setTimeout (timeoutFunc, 40 ); // edit this line to change speeed
	}
	this.getRandomPixel=function(){
		var rndX = Math.floor(Math.random() * 16)+1;
		var rndY = Math.floor(Math.random() * 16)+1;
		var elID=rndX+'-'+rndY;
		var el=GET(elID);
		return el;
	}
	this.stop=function(){
		clearTimeout(this.time);
	}
	this.stopIntro=function(){
		clearTimeout(this.introTime);
	}
	this.intro=function(){
		var self=this;
		var  tf=function(){ self.intro(); }
		this.currentOpacity-=this.introFadeStep;
		if(this.currentOpacity>=1){
			this.introTime=setTimeout (tf, 50 ); // edit this line to change speeed
			this.table.style.opacity=this.currentOpacity/100;
			this.table.style.filter='alpha(opacity = '+this.currentOpacity+')';
		}else{
			this.stopIntro();
			this.table.style.opacity=0.2;
			this.table.style.filter='alpha(opacity = 20)';
			this.startDemo();
		}
	}
}
