//____________________CONFIGURATION AREA_____________________
// THIS LED SCRIPT TAKES UP 200 pixels HORIZONTAL and 28 pixels VERTICAL -Have Fun :-)
// YOUR MESSAGE GOES ON NEXT 4 LINES DOWN.
// ALLOWABLE CHARACTERS ARE: A-Z, Period, space, comma, numerals, question mark and 'message codes'.
// THE 4 MESSAGE CODES:
// @=PAUSE FOR 3 SECONDS,  #=FLASH FOR 3 SECONDS, ^=SCROLL UP EFFECT, _=SUN EFFECT, $=SPLIT EFFECT

var message="Putting home back into home cooking       ";

var LEDonColor='Red';        //color of the LEDs when they are on
var LEDoffColor='#7D0605';   //color of the LEDs when they are off - #7D0605
startXPos=370;                //start of horizontal position eg. startXPos=20; places the leds 20 pixels from left
startYPos=89;
						//start of vertical position
//____________________END CONFIGURATION AREA__________________

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
}
var alphabet=new Array(44);
	alphabet[0]=new Array("0111111","1001000","1001000","1001000","0111111");	alphabet[1]=new Array("1111111","1001001","1001001","1001001","0110110");//B
	alphabet[2]=new Array("0111110","1000001","1000001","1000001","0100010");	alphabet[3]=new Array("1111111","1000001","1000001","1000001","0111110");//D
	alphabet[4]=new Array("1111111","1001001","1001001","1001001");				alphabet[5]=new Array("1111111","1001000","1001000","1001000");//F
	alphabet[6]=new Array("0111110","1000001","1000001","1001001","0101110");	alphabet[7]=new Array("1111111","0001000","0001000","0001000","1111111");//H
	alphabet[8]=new Array("1000001","1111111","1000001");						alphabet[9]=new Array("0000110","0000001","0000001","0000001","1111110");//J
	alphabet[10]=new Array("1111111","0001000","0010100","0100010","1000001");	alphabet[11]=new Array("1111111","0000001","0000001","0000001");//L
	alphabet[12]=new Array("1111111","0010000","0001000","0010000","1111111");	alphabet[13]=new Array("1111111","0010000","0001000","0000100","1111111");//N
	alphabet[14]=new Array("0111110","1000001","1000001","1000001","0111110");	alphabet[15]=new Array("1111111","1001000","1001000","1001000","0110000");//P
	alphabet[16]=new Array("0111110","1000001","1000001","1000011","0111111");	alphabet[17]=new Array("1111111","1001000","1001100","1001010","0110001");//R
	alphabet[18]=new Array("0110010","1001001","1001001","1001001","0100110");	alphabet[19]=new Array("1000000","1000000","1111111","1000000","1000000");//T
	alphabet[20]=new Array("1111110","0000001","0000001","0000001","1111110");	alphabet[21]=new Array("1110000","0001100","0000011","0001100","1110000");//V
	alphabet[22]=new Array("1111110","0000001","0000010","0001100","0000010","0000001","1111110"); alphabet[23]=new Array("1100011","0010100","0001000","0010100","1100011");//X
	alphabet[24]=new Array("1100000","0010000","0001111","0010000","1100000");	alphabet[25]=new Array("1000011","1000101","1001001","1010001","1100001");//Z
	alphabet[26]=new Array("0000000","0000000","0000000","0000000");			alphabet[27]=new Array("0000000","0000001","0000000","0000000","0000000");//PERIOD
	alphabet[28]=new Array("0000000","0000000","1111101","0000000","0000000");//!
	alphabet[29]=new Array("0100001","1111111","0000001");						alphabet[30]=new Array("0100011","1000101","1001001","1001001","0110001");//2
	alphabet[31]=new Array("0100010","1001001","1001001","1001001","0110110");	alphabet[32]=new Array("0001000","0011000","0101000","1111111","0001000");//4
	alphabet[33]=new Array("1111001","1001001","1001001","1001001","1000110");	alphabet[34]=new Array("0111110","1001001","1001001","1001001","0100110");//6
	alphabet[35]=new Array("1000011","1000100","1001000","1110000");			alphabet[36]=new Array("0110110","1001001","1001001","1001001","0110110");//8
	alphabet[37]=new Array("0110010","1001001","1001001","1001001","0111110");	alphabet[38]=new Array("0000001","0000010","0000000");//COMMA
	alphabet[39]=new Array("XXXXXXX");//PAUSE ( @ )
	alphabet[40]=new Array("YYYYYYY");//FLASH ( # )
	alphabet[41]=new Array("DDDDDDD");//SCROLL UP EFFECT ( ^ )
	alphabet[42]=new Array("SSSSSSS");//SUN EFFECT ( _ )
	alphabet[43]=new Array("0100000","1000000","1001101","1001000","0110000");//?
	alphabet[44]=new Array("QQQQQQQ");//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;
	for (ii=0; ii<alphabet[temp].length;ii++){ messageArray[columnCount]=alphabet[temp][ii];columnCount++;}
	if ((temp!=39) && (temp!=40) && (temp!=41)) {messageArray[columnCount]="0000000";columnCount++;}
}
//make 'led screen' with block 0-49 on row 1, block 50-99 on row 2, block 100-149 on row 3, etc..
var b='';
for (var i=0; i<1400; i++){//columns 50 columns x 7 rows
	rowPos=0+3*(i>199)+3*(i>399)+3*(i>599)+3*(i>799)+3*(i>999)+3*(i>1199);
	colPos=0+600*(i>199)+600*(i>399)+600*(i>599)+600*(i>799)+600*(i>999)+600*(i>1199);
	b+= (NS) ? '<LAYER NAME="block' + i + '" LEFT="' + (startXPos+i*3-colPos) + '" TOP="' + (startYPos+rowPos) + '" VISIBILITY="show" WIDTH="20" HEIGHT="20" BGCOLOR="' + LEDoffColor + '"></LAYER>' : '<div id="block' + i + '" style="position:absolute; left:' + (startXPos+i*3-colPos) + 'px; top:' + (startYPos+rowPos) + 'px; background-color:' + LEDoffColor +'; height: 2px; width: 2px;font-size:2px;"></div>';
}
document.write(b);
var columnCounter=0; 	//keep track of position of messageArray
var bb=new Array();		//store particular LED's dom element here
	if (NS) { for (var i=0; i<1400; i++) { bb[i]=getCSS("block"+i)}}
	else {for (var i=0; i<1400; i++){ bb[i]=getCSS("block"+i).style;}}
var isOn=new Array();for (var i=0; i<1400; 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;
	if (NS) { for (var i=0; i<1201; i+=200){ if (isOn[i]==1) { bb[i].bgColor=LEDoffColor; isOn[i]=0;} for (var ii=1; ii<200; ii+=7){
				temp=i+ii;temp1=temp+1;temp2=temp+2;temp3=temp+3;temp4=temp+4;temp5=temp+5;temp6=temp+6;
				if (isOn[temp]==1) {bb[temp].bgColor=LEDoffColor;  isOn[temp]=0; bb[temp-1].bgColor=LEDonColor; isOn[temp-1]=1;}
				if (isOn[temp1]==1) {bb[temp1].bgColor=LEDoffColor;  isOn[temp1]=0; bb[temp].bgColor=LEDonColor; isOn[temp]=1;}
				if (isOn[temp2]==1) {bb[temp2].bgColor=LEDoffColor;  isOn[temp2]=0; bb[temp+1].bgColor=LEDonColor; isOn[temp+1]=1;}
				if (isOn[temp3]==1) {bb[temp3].bgColor=LEDoffColor;  isOn[temp3]=0; bb[temp2].bgColor=LEDonColor; isOn[temp2]=1;}
				if (isOn[temp4]==1) {bb[temp4].bgColor=LEDoffColor;  isOn[temp4]=0; bb[temp3].bgColor=LEDonColor; isOn[temp3]=1;}
				if (isOn[temp5]==1) {bb[temp5].bgColor=LEDoffColor;  isOn[temp5]=0; bb[temp4].bgColor=LEDonColor; isOn[temp4]=1;}
				if (isOn[temp6]==1) {bb[temp6].bgColor=LEDoffColor;  isOn[temp6]=0; bb[temp5].bgColor=LEDonColor; isOn[temp5]=1;}
	}}}
	else { for (var i=0; i<1201; i+=200){ if (isOn[i]==1) { bb[i].backgroundColor=LEDoffColor; isOn[i]=0;} for (var ii=1; ii<200; ii+=7){
				temp=i+ii;temp1=temp+1;temp2=temp+2;temp3=temp+3;temp4=temp+4;temp5=temp+5;temp6=temp+6;
				if (isOn[temp]==1) {bb[temp].backgroundColor=LEDoffColor;  isOn[temp]=0; bb[temp-1].backgroundColor=LEDonColor; isOn[temp-1]=1;}
				if (isOn[temp1]==1) {bb[temp1].backgroundColor=LEDoffColor;  isOn[temp1]=0; bb[temp].backgroundColor=LEDonColor; isOn[temp]=1;}
				if (isOn[temp2]==1) {bb[temp2].backgroundColor=LEDoffColor;  isOn[temp2]=0; bb[temp+1].backgroundColor=LEDonColor; isOn[temp+1]=1;}
				if (isOn[temp3]==1) {bb[temp3].backgroundColor=LEDoffColor;  isOn[temp3]=0; bb[temp2].backgroundColor=LEDonColor; isOn[temp2]=1;}
				if (isOn[temp4]==1) {bb[temp4].backgroundColor=LEDoffColor;  isOn[temp4]=0; bb[temp3].backgroundColor=LEDonColor; isOn[temp3]=1;}
				if (isOn[temp5]==1) {bb[temp5].backgroundColor=LEDoffColor;  isOn[temp5]=0; bb[temp4].backgroundColor=LEDonColor; isOn[temp4]=1;}
				if (isOn[temp6]==1) {bb[temp6].backgroundColor=LEDoffColor;  isOn[temp6]=0; bb[temp5].backgroundColor=LEDonColor; isOn[temp5]=1;}
	}}}
	temp=messageArray[columnCounter]; flag=temp.charAt(0);//GET NEW COLUMN
	if (temp.charAt(1)=="1") {isOn[399]=1;} if (temp.charAt(2)=="1") {isOn[599]=1} if (temp.charAt(3)=="1") {isOn[799]=1}
	if (temp.charAt(4)=="1") {isOn[999]=1} if (temp.charAt(5)=="1") {isOn[1199]=1} if (temp.charAt(6)=="1") {isOn[1399]=1}
	if (flag=="0") {} else if (flag=="1") {isOn[199]=1;} else 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;
}
function LEDinit(){if (NS) {loop=setInterval("scroll()",55);} else if (IE){loop=setInterval("scroll()",55);} else {loop=setInterval("scroll()",55);}}
