var LEDonColor='url(images/yellow.gif)';
var LEDonColor2='url(images/blue.gif)';
var LEDoffColor='url(images/blank.gif)';
startXPos=448;
startYPos=20;

// check browser type
var IE=(document.all) ? true:false; var NS=(document.layers) ? true:false; var W3C=((document.getElementById) && (!IE)) ? true:false; 
var d=document; if (window.offscreenBuffering) window.offscreenBuffering = true;
function getCSS(id) {
	if (IE) 	 return d.all[id]			//IE
	else if (NS) return d.layers[id]		//NS4
	else		 return d.getElementById(id)//W3C
} 

// setup letters array 7 by variable size
// will need extention to take account of bigger letters
// 0 = space
// 1 = base colour
// 2 = accent colour
var alphabet=new Array(44);
alphabet[0]=new Array("00111111100","01111111100","11000100000","11000100000","01111111100","00111111100");//A
alphabet[1]=new Array("11111111100","11111111100","10001000100","10001000100","11111111100","01110111000");//B
alphabet[2]=new Array("01111111000","11111111100","10000000100","10000000100","11100011100","01100011000");//C
alphabet[3]=new Array("11111111100","11111111100","10000000100","11000001100","01111111000","00111110000");//D
alphabet[4]=new Array("11111111100","11111111100","10001000100","10001000100","10001000100","10000000100");//E
alphabet[5]=new Array("11111111100","11111111100","10001000000","10001000000","10001000000","10000000000");//F
alphabet[6]=new Array("01111111000","11111111100","10000000100","10000100100","11100111100","01100111100");//G
alphabet[7]=new Array("11111111100","11111111100","00001000000","00001000000","11111111100","11111111100");//H
alphabet[8]=new Array("10000000100","11111111100","11111111100","10000000100");//I
alphabet[9]=new Array("00000011000","00000011100","00000000100","00000000100","11111111100","11111111000");//J
alphabet[10]=new Array("11111111100","11111111100","00001000000","00111110000","11110111100","11000001100");//K
alphabet[11]=new Array("11111111100","11111111100","00000000100","00000000100","00000000100");//L
alphabet[12]=new Array("11111111100","01111111100","00100000000","00011000000","00100000000","01111111100","11111111100");//M
alphabet[13]=new Array("11111111100","11111111100","00110000000","00011000000","00001100000","11111111100","11111111100");//N
alphabet[14]=new Array("01111111000","11111111100","10000000100","10000000100","11111111100","01111111000");//O
alphabet[15]=new Array("11111111100","11111111100","10001000000","10001000000","11111000000","01110000000");//P
alphabet[16]=new Array("01111111000","11111111100","10000000100","10000000110","11111111111","01111111001");//Q
alphabet[17]=new Array("11111111100","11111111100","10001000000","10001100000","11111111100","01110011100");//R
alphabet[18]=new Array("01100001000","11110001100","10011000100","10001100100","11000111100","01000011000");//S
alphabet[19]=new Array("10000000000","10000000000","11111111100","11111111100","10000000000","10000000000");//T
alphabet[20]=new Array("11111111000","11111111100","00000000100","00000000100","11111111100","11111111000");//U
alphabet[21]=new Array("11111110000","11111111000","00000001100","00000001100","11111111000","11111110000");//V
alphabet[22]=new Array("11111100000","11111111100","00000011100","00011100000","00000011100","11111111100","11111100000");//W
alphabet[23]=new Array("11000011100","11100111100","00111000000","00011100000","11100111100","11000011100");//X
alphabet[24]=new Array("11110000000","11111000000","00001111100","00001111100","11111000000","11110000000");//Y
alphabet[25]=new Array("10000011100","10000111100","10001100100","10011000100","11110000100","11100000100");//Z
alphabet[26]=new Array("00000000000","00000000000","00000000000","00000000000");//space
alphabet[27]=new Array("00000001100","00000001100");//full stop
alphabet[28]=new Array("11111110100","11111110100");//!
alphabet[29]=new Array("00100000000","01100000000","11111111100","11111111100");//1
alphabet[30]=new Array("01100001100","11100011100","10000110100","10001100100","11111000100","01110000100");//2
alphabet[31]=new Array("01100011000","11100011100","10001000100","10001000100","11111111100","01110111000");//3
alphabet[32]=new Array("11111110000","11111110000","00000010000","00111111100","00111111100","00000010000");//4
alphabet[33]=new Array("11111001000","11111000100","10001000100","10001001100","10001111000","10000110000");//5
alphabet[34]=new Array("00011111000","00111111100","11110000100","11010000100","10011111100","00001111000");//6
alphabet[35]=new Array("10000011100","10001111100","10111100000","11110000000","11000000000");//7
alphabet[36]=new Array("01110111000","11111111100","10001000100","10001000100","11111111100","01110111000");//8
alphabet[37]=new Array("01111000000","11111100100","10000101100","10000111000","11111110000","01111100000");//9
alphabet[38]=new Array("00000001101","00000001111","00000001110");//,
alphabet[39]=new Array("XXXXXXXXXXX");//PAUSE ( @ )
alphabet[40]=new Array("YYYYYYYYYYY");//FLASH ( # ) 
alphabet[41]=new Array("DDDDDDDDDDD");//SCROLL UP EFFECT ( ^ )
alphabet[42]=new Array("SSSSSSSSSSS");//SUN EFFECT ( _ )
alphabet[43]=new Array("01100000000","11100000000","10001101100","10011101100","11110000000","01100000000");//?
alphabet[44]=new Array("QQQQQQQQQQQ");//SPLIT EFFECT ( $ )

message=message.toUpperCase();					//make message uppercase
var messageArray=new Array();					//make messageArray-an array of the letters in the message
var columnCount=0; 								//variable to count columns in messageArray.length
for (i=0; i<message.length; i++){				//iterate through the characters in the message
	letterNum=message.charCodeAt(i);			//assign proper letter code (alphabet array)
	if ((letterNum>=65) && (letterNum<=90)) temp=letterNum-65; //letters
	else if (letterNum==46) temp=27;			//.
	else if (letterNum==32)	temp=26;			//space
	else if (letterNum==33)	temp=28;			//!
	else if ((letterNum>=49) && (letterNum<=57)) temp=letterNum-20;	//[1-9]
	else if (letterNum==48)	temp=14;			//zero
	else if (letterNum==63) temp=43;			//?
	else if (letterNum==44) temp=38;			//,
	else if (letterNum==64) temp=39;			//pause
	else if (letterNum==35) temp=40;			//flash effect
	else if (letterNum==94) temp=41;			//scroll up effect
	else if (letterNum==95) temp=42;			//sunrise effect
	else if (letterNum==36) temp=44;			//split effect
	else continue;
// stuff the array shapes into a new array
	for (ii=0; ii<alphabet[temp].length;ii++){ messageArray[columnCount]=alphabet[temp][ii];columnCount++;}
// put in blank for letters, effects, but not sunrise or split...
	if ((temp!=39) && (temp!=40) && (temp!=41)) {messageArray[columnCount]="00000000000";columnCount++;}
}

var b='';

for (var i=0; i<704; i++){//columns 64 x 11 (50 columns x 7 rows)
	rowPos=0+7*(i>63)+7*(i>127)+7*(i>191)+7*(i>255)+7*(i>319)+7*(i>383)+7*(i>447)+7*(i>511)+7*(i>575)+7*(i>639);
	colPos=0+448*(i>63)+448*(i>127)+448*(i>191)+448*(i>255)+448*(i>319)+448*(i>383)+448*(i>447)+448*(i>511)+448*(i>575)+448*(i>639);
	b+= (NS) ? 	'<LAYER NAME="block' + i + '" LEFT="' + (startXPos+i*7-colPos) + '" TOP="' + (startYPos+rowPos) + '" VISIBILITY="show" WIDTH="2" HEIGHT="2" BGCOLOR="' + LEDoffColor + '"></LAYER>' : '<div id="block' + i + '" style="position:absolute; z-index:1; left:' + (startYPos+rowPos) + 'px; top:' + (startXPos-i*7+colPos) + 'px; background-image:' + LEDoffColor +'; height: 7px; width: 7px;font-size:7px;"></div>';
}

document.write(b);

var columnCounter=0; 	//keep track of postion of messageArray
var bb=new Array();		//store particular LED's dom element here
	if (NS) { for (var i=0; i<704; i++) { bb[i]=getCSS("block"+i)}}
	else {for (var i=0; i<704; i++){ bb[i]=getCSS("block"+i).style;}}
var isOn=new Array();for (var i=0; i<704; i++){ isOn[i]=0;}	//keep track on on/off status of particular LED
onArray=new Array(); var onCount=0; //array size counter

function scroll(){
	onCount=0;

// loop through the entire array, avoiding the last row?
		for (var i=1; i<704; i++) {
// move the value down one
				isOn[i-1] = isOn[i];
				temp=bb[i].backgroundImage;
				temp1=bb[i-1].backgroundImage;
				if (temp1!=temp) {
				bb[i-1].backgroundImage = temp;}
		}	
	 
	temp=messageArray[columnCounter]; flag=temp.charAt(0);//GET NEW COLUMN
// rowPos=0+7*(i>63)+7*(i>127)+7*(i>191)+7*(i>255)+7*(i>319)+7*(i>383)+7*(i>447)+7*(i>511)+7*(i>575)+7*(i>639);
	var v=0
	for (i=0; i<11; i++){
	if (temp.charAt(i)=="1") 
	   {
	   v=i*64+63;
	   isOn[v]=1;
	   bb[v].backgroundImage=LEDonColor;} 
	else if (temp.charAt(i)=="2")
	   {
	   v=i*64+63;
	   isOn[v]=1;
	   bb[v].backgroundImage=LEDonColor;}
	}    
	if (flag=="X") 
	  {pauseScroll();} 
	else if (flag=="Y") 
	  {flashScroll();} 
	else if (flag=="D") 
	  {dropEffect();} 
	else if (flag=="S") 
	  {sunRiseEffect();} 
	else if (flag=="Q") 
	  {splitEffect();}
	columnCounter++; if(columnCounter==columnCount) columnCounter=0; 
}

//______________pause effect________________

function pauseScroll()
{ 
clearInterval(loop); 
//setTimeout("init()",3000);
}
//______________onArray Section_____________
onArray=new Array(); var onCount=0; //array size counter

function makeOnArray(){ clearInterval(loop); onCount=0;	for (var i=0; i<700; i++){if (isOn[i]==1) {onArray[onCount]=i; onCount++;};}//make onArray of 'on' LEDS

}//_________________________________

//_______________flash effect_______________

var flashCount=0;

function flashScroll(){	makeOnArray(); flashCount=0; if (NS) {setTimeout("flashItNS()",250);} else {setTimeout("flashIt()",250);}}
function flashItNS(){ flashCount++;
	if (flashCount<14) {
		if (flashCount % 2 == 0){ for (var i=0; i<onCount; i++){ isOn[onArray[i]]=0;bb[onArray[i]].bgColor=LEDoffColor;}}
		else {for (var i=0; ionCount; i++){isOn[onArray[i]]=1;bb[onArray[i]].bgColor=LEDonColor;}}
		setTimeout("flashItNS()",250);
	}	
	else {flashCount=0; setTimeout("init()",250);}
}

function flashIt(){ flashCount++;
	if (flashCount<14) {
		if (flashCount % 2 == 0){ for (var i=0; i<onCount; i++){ isOn[onArray[i]]=0;bb[onArray[i]].backgroundImage=LEDoffColor;}}
		else {for (var i=0; ionCount; i++){isOn[onArray[i]]=1;bb[onArray[i]].backgroundImage=LEDonColor;}}
		setTimeout("flashIt()",250);
	}	
	else {flashCount=0; setTimeout("init()",250);}
}//_________________________________

//____________scroll up effect______________

dropArray=new Array();

function dropEffect(){makeOnArray(); for (var i=0; i<onCount; i++){ dropArray[i]=onArray[i]; } if (NS) {dropItNS();} else {dropIt();}}
var dropCount=0;

function dropItNS(){
	if (dropCount11){for (var i=0; i<onCount; i++){	bb[dropArray[i]].bgColor=LEDoffColor; }
		for (var i=0; ionCount; i++){ temp=dropArray[i]; temp-=63;if (temp<0) temp+=350;bb[temp].bgColor=LEDonColor; dropArray[i]=temp;}
		dropCount++; setTimeout("dropItNS()",100);
	} else {dropCount=0;setTimeout("init()",100);}
}//_________________________________

function dropIt(){
	if (dropCount<11){ for (var i=0; i<onCount; i++){ bb[dropArray[i]].backgroundColor=LEDoffColor; }
		for (var i=0; ionCount; i++){ temp=dropArray[i]; temp-=63; if (temp<0) temp+=350; bb[temp].backgroundColor=LEDonColor; dropArray[i]=temp;}
		dropCount++; setTimeout("dropIt()",100);
	} else {dropCount=0;setTimeout("init()",100);}
}//_________________________________

//____________sunrise effect________________

sunRiseCounter=0;sunRiseArray=new Array();
sunRiseArray[0]=new Array(50,101,102,103,154,155,156,207,208,259,260,261,212,163,164,115,116,117,168,169,170,221,222,223,274,275,276,227,228,179,180,131,132,83,134,135,186,187,238,239,240,241,292,293,344,295,296,247,198);//Hills
sunRiseArray[1]=new Array(224,225,226); sunRiseArray[2]=new Array(174,175,176,177); sunRiseArray[3]=new Array(173,124,125,126,127,128,178); sunRiseArray[4]=new Array(172,123,74,75,76,77,129); sunRiseArray[5]=new Array(171,122,73,24,25,26,27,78,79,130);

function sunRiseEffect() { makeOnArray(); for (var i=0; i<onCount; i++){ isOn[onArray[i]]=0; if (!NS) {bb[onArray[i]].backgroundColor=LEDoffColor;}	else {bb[onArray[i]].bgColor=LEDoffColor;}}
	setTimeout("riseEffectUp()",1000);}

function riseEffectUp() {
	if (!NS) { for (var ii=0; iisunRiseArray[sunRiseCounter].length; ii++) {isOn[sunRiseArray[sunRiseCounter][ii]]=1;bb[sunRiseArray[sunRiseCounter][ii]].backgroundColor=LEDonColor;}}
	else {for (var ii=0; ii<sunRiseArray[sunRiseCounter].length; ii++) {isOn[sunRiseArray[sunRiseCounter][ii]]=1;bb[sunRiseArray[sunRiseCounter][ii]].bgColor=LEDonColor;}}
	sunRiseCounter++; if (sunRiseCounter>5) {sunRiseCounter=5;setTimeout("riseEffectDown()",2000);}	else {setTimeout("riseEffectUp()",250);}}

function riseEffectDown() {
	if (!NS) {for (var ii=0; ii<sunRiseArray[sunRiseCounter].length; ii++) {isOn[sunRiseArray[sunRiseCounter][ii]]=0;bb[sunRiseArray[sunRiseCounter][ii]].backgroundColor=LEDoffColor;}}
	else {for (var ii=0; iisunRiseArray[sunRiseCounter].length; ii++) {isOn[sunRiseArray[sunRiseCounter][ii]]=0;bb[sunRiseArray[sunRiseCounter][ii]].bgColor=LEDoffColor;}}
	sunRiseCounter--; if (sunRiseCounter<1) {sunRiseCounter=0;setTimeout("init()",1500);}
	else {setTimeout("riseEffectDown()",250);}
}//____________________________________

//____________split scroll effect___________

var splitCount=0;

function splitEffect() { makeOnArray(); for (var i=0; i<onCount; i++) { dropArray[i]=onArray[i]; }
	if (NS) {setTimeout("splitNS()",55);} else if (IE) {setTimeout("splitIt()",55);} else {setTimeout("splitIt()",100);}
}

function splitIt(){ for (i=0;ionCount;i++){ temp=dropArray[i];
	if (temp<150) { if (temp==100) {bb[temp].backgroundColor=LEDoffColor; temp=149; bb[temp-1].backgroundColor=LEDonColor;}
			else if (temp==50) {bb[temp].backgroundColor=LEDoffColor; temp=99; bb[temp-1].backgroundColor=LEDonColor;}
			else if (temp==0) {bb[temp].backgroundColor=LEDoffColor; temp=49; bb[temp-1].backgroundColor=LEDonColor;}
			else {bb[temp].backgroundColor=LEDoffColor; bb[temp-1].backgroundColor=LEDonColor;}
			dropArray[i]=temp-1; }
		else { if (temp==199) {bb[temp].backgroundColor=LEDoffColor; temp=200; bb[temp+1].backgroundColor=LEDonColor;}
			else if (temp==349) {bb[temp].backgroundColor=LEDoffColor; temp=300; bb[temp+1].backgroundColor=LEDonColor;}
			else if (temp==299) {bb[temp].backgroundColor=LEDoffColor; temp=250; bb[temp+1].backgroundColor=LEDonColor;}
			else if (temp==249) {bb[temp].backgroundColor=LEDoffColor; temp=200; bb[temp+1].backgroundColor=LEDonColor;}
			else {bb[temp].backgroundColor=LEDoffColor; bb[temp+1].backgroundColor=LEDonColor;}
			dropArray[i]=temp+1; }
	} splitCount++; if (splitCount<49) {if (IE) {setTimeout("splitIt()",55);} else {setTimeout("splitIt()",100);} } else {splitCount=0; init();}
}

function splitNS(){
	for (i=0;i<onCount;i++){ temp=dropArray[i];
		if (temp150) { if (temp==100) {bb[temp].bgColor=LEDoffColor; temp=149; bb[temp-1].bgColor=LEDonColor;}
			else if (temp==50) {bb[temp].bgColor=LEDoffColor; temp=99; bb[temp-1].bgColor=LEDonColor;}
			else if (temp==0) {bb[temp].bgColor=LEDoffColor; temp=49; bb[temp-1].bgColor=LEDonColor;}
			else {bb[temp].bgColor=LEDoffColor; bb[temp-1].bgColor=LEDonColor;}
			dropArray[i]=temp-1; }
		else { if (temp==199) {bb[temp].bgColor=LEDoffColor; temp=200; bb[temp+1].bgColor=LEDonColor;}
			else if (temp==349) {bb[temp].bgColor=LEDoffColor; temp=300; bb[temp+1].bgColor=LEDonColor;}
			else if (temp==299) {bb[temp].bgColor=LEDoffColor; temp=250; bb[temp+1].bgColor=LEDonColor;}
			else if (temp==249) {bb[temp].bgColor=LEDoffColor; temp=200; bb[temp+1].bgColor=LEDonColor;}
			else {bb[temp].bgColor=LEDoffColor; bb[temp+1].bgColor=LEDonColor;}
			dropArray[i]=temp+1; }
	} splitCount++; if (splitCount<49) {setTimeout("splitNS()",55);} else {splitCount=0; init();} 

}//___________________________________

function init(){ if (NS) {loop=setInterval("scroll()",110);} else if (IE){loop=setInterval("scroll()",110);} else {loop=setInterval("scroll()",100);}}


