var aLetters = new Array();

if (window.innerWidth)
{
	theWidth = window.innerWidth
	theHeight = window.innerHeight
}
else if (document.documentElement && document.documentElement.clientWidth)
{
	theWidth = document.documentElement.clientWidth
	theHeight = document.documentElement.clientHeight
}
else if (document.body)
{
	theWidth = document.body.clientWidth
	theHeight = document.body.clientHeight
}
var docWidth = theWidth;
var docHeight = theHeight;

function random_letter(){
	return(String.fromCharCode(65 + Math.round(Math.random()*23)));
}

function random_letters(){
  result = '';
	for(i=0; i<1; i++){
	  result = result + random_letter() + "<br>";
	}
	return(result);
}

function random_length(){
	return(1 + Math.round(Math.random() * 20));
}

function makeLetter(id, aLeft, aTop, aSpeed){
	document.write('<div id="' + id + '" class="matrix_letter">');

	aLength = 1;//random_length();
	document.write('</div>');

	document.getElementById(id).style.left = aLeft;
	document.getElementById(id).style.top = aTop;
}

function random_speed(){
	return(1 + Math.round(Math.random() * 100));
}

function random_left(){
	return(Math.round(Math.random() * (docWidth-50)));
}

function random_top(){
	return(Math.round(Math.random() * (docHeight)));
}

function move(id){
	aLetter = document.getElementById(id);
	aLetter.innerHTML = random_letter();

	newTop = parseInt(aLetter.style.top) + 10;

  if((newTop + 110) > docHeight){
    aLetter.style.top = 0;
    aLetter.style.left = random_left();
	}
	else{
	  aLetter.style.top = newTop;
	}
}

function move_all(){
	for(i=0; i<aLetters.length; i++){
	  move(aLetters[i]);
	}
}

function build_letters(letter_count){
	document.write("<style>");
	document.write(".matrix_letter{");
  document.write("filter:");
//	document.write("progid:DXImageTransform.Microsoft.Glow(Color=#00FF55,Strength=1)");
//  document.write("progid:DXImageTransform.Microsoft.MotionBlur(Strength=400,Direction=0);");
  document.write("height: 100px;");
  document.write("color: #00FF55;");
	document.write("position: absolute;");
  document.write("font-family: Tahoma, monospace;");
  document.write("font-size: 16pt;");
  document.write("font-weight: bold;");
  document.write("left: 0; top: 0;");
	document.write("}");
	document.write("</style>");

  for(x=0; x<letter_count; x++){
  	makeLetter("letter"+x, random_left(), random_top(), random_speed());
  	aLetters.push("letter"+x);
  }

	setInterval("move_all()", 20);


}
