
function startLedChain()
{
	ledChain = new ledChainPrototype(pArray,'PROBAND');
	// flow();
	peak();
}

function flow()
{
	for(i=0;i < ledChain.ledArray.length; i++)
	{
		if (zf(1000) >  997)
		{
		//	led[i].brightness(100);
		}
		else
		{
			led[i].lightChange();		
		}	
	}
	window.setTimeout('flow()',10);
}


function peak()
{
	bWidth=3;
	normalBrightness=30;

	
	ledChain.peakCenter += ledChain.peakDir;

	if (ledChain.peakCenter >= ledChain.ledArray.length)	
	{
		ledChain.peakCenter=0;
	}
	if (ledChain.peakCenter <= (bWidth * -1))	
	{
		ledChain.peakCenter=ledChain.ledArray.length -1;
	}

	for (k=0;k <= 2; k++)
	{
	pc=ledChain.peakCenter + (k * (Math.floor(ledChain.ledArray.length/2)));
	if (pc >= ledChain.ledArray.length)	
	{
		pc = pc - ledChain.ledArray.length;
	}
	



		
	if (zf(1000) > 1997)	
	{
		ledChain.peakDir *= -1;
	}
	i=pc;
	endW=i-bWidth-1;
	startW=i+bWidth;
	counter=0;
	for (j = endW; j <= startW; j+=4)
	{
		lj=j;
		if (j < 0)
		{
			lj = ledChain.ledArray.length-bWidth+counter+i -1;
		}
		if (j >= ledChain.ledArray.length)
		{
			lj = i+bWidth  - ledChain.ledArray.length;
		}
		
		// document.F.FF.value=startW+" -- "+endW+" -- "+i+" --- "+lj;		
		
		if (j == endW)
		{
			// document.F.FF.value=lj;
			led[lj].brightness(normalBrightness);
		}
		else
		{
			// document.F.FF2.value=lj;
			led[lj].brightness(100-zf(10));
		}	
		
		if (zf(1000) > 900)			
		{
			czf=zf(3);
			if (czf < 1)
			{
				led[lj].ledColor('ffffff');
			}
			if (czf == 1)
			{
				led[lj].ledColor('AF0000');
			}
			if (czf == 2)
			{
				led[lj].ledColor('00AF00');
			}
		}
		else
		{
			led[lj].ledColor('dec38c');
		}
		
		// dd=eval('document.F.F'+counter);
		// dd.value=counter+"--"+led[lj]._id+" --- "+lj+" -- "+endW;
		// dd.value=counter+"--"+" --- "+lj+" -- "+j+" -- "+i+"--"+(ledChain.ledArray.length-bWidth+j -1);
		// dd.value=counter+" --- "+(ledChain.ledArray.length-bWidth+counter-1);
		counter ++;
		
	}
	}
	window.setTimeout('peak()',200);
}



function ledChainPrototype(ledArray,_parent)
{
	this.ledArray=ledArray;
	this._parent=_parent;
	this.peakCenter=-1;
	this.peakDir=1;
	startVal=0;
	// ledChar='&bull;';
	ledChar='*';
	for (i=0;i < this.ledArray.length; i++)
	{
		_pA=this.ledArray[i];
		led[i]=new ledPoint('P'+_pA.substr(0,4),_pA.substr(4,4)*1,_pA.substr(8,4)*1,ledChar,blinkElementSize,this._parent);
		// led[i].brightness(i);
		led[i].brightness(30); 
		led[i].ledColor('dec38c');
	}
}

function ledPoint(_id,xp,yp,form,size,_parent)
{
	this._id=_id;
	this.xp=xp;
	this.yp=yp;
	this.pSign=form;
	this.pSize=size - 4 + zf(6);
	this.opVal=0;
	this.pColor='888888';
	this.status=0;

	this.brightness=brightness;
	this.lightChange=lightChange;
	this.ledColor=ledColor;
		 
	var wMain=document.createElement("span");
	nI = document.createAttribute("id");
	nI.nodeValue = this._id;
	wMain.setAttributeNode(nI);
	var nI = document.createAttribute("style");
	nI.nodeValue ="position:absolute;left:"+this.xp+"px;top:"+this.yp+"px;color:#"+this.pColor+";font-family:fantasy;font-size:"+this.pSize+"px;opacity:"+(this.opVal/100)+";";
	if (document.all)
	{
		wMain.style.position='absolute';
		wMain.style.top=this.yp+'px';
		wMain.style.left=this.xp+'px';
		wMain.style.color='#'+this.pColor;
		wMain.style.fontFamily='fantasy';
		wMain.style.fontSize=(this.pSize+8)+'px';
		wMain.style.filter='alpha(opacity='+this.opVal+')';
	}
	else
	{
		wMain.setAttributeNode(nI);
	}	
	document.getElementById(_parent).appendChild(wMain);
	document.getElementById(this._id).innerHTML=this.pSign;
}


function brightness(v)
{
	this.opVal = v;
	if (document.all)
	{
		document.getElementById(this._id).style.filter='alpha(opacity='+this.opVal+')';
	}
	else
	{
		document.getElementById(this._id).style.opacity=this.opVal/100;
	}
}

function ledColor(v)
{
	document.getElementById(this._id).style.color='#'+v;
}

function lightChange()
{
	if (this.status == 0)
	{
		if (this.opVal < 100)
		{
			this.opVal += 1;
			if (document.all)
			{
				document.getElementById(this._id).style.filter='alpha(opacity='+this.opVal+')';
			}
			else
			{
				document.getElementById(this._id).style.opacity=this.opVal/100;
			}
		}
		else
		{
			this.status = 1;
		}	
	}
	else
	{
		if (this.opVal >  0)
		{
			this.opVal -= 1;
			if (document.all)
			{
				document.getElementById(this._id).style.filter='alpha(opacity='+this.opVal+')';
			}
			else
			{
				document.getElementById(this._id).style.opacity=this.opVal/100;
			}
		}
		else
		{
			this.status=0;
		}	
	}
	return this.opVal;
}

function zf(range)
{return Math.floor(Math.random()*range);}

