// Script property of Tiger of Doom Productions
// No use without explicit permission
//Declare some variables
//What do you want the text following the mouse to be?
//Blank = "No Text";
var origText ="ROFL:ROFL:LOL:ROFL:ROFL<br>       ____^____<br> L   _/      [] \\<br>LOL==_           \\<br> L   \\___________]<br>         I     I<br>       \\----------/";
//Use a text box? (overrides var text)
var useBox = true;

//Are we in debug (alert) mode?
var debug = false;


var textArray = new Array();
var divArray = new Array();

var pageLoaded = 0;

//Copy and Paste-able debug caller:
//  if (debug){toDebug("");}


  if (debug){toDebug("Script Tag Works, Script enabled.\nDebug is on.\nThe text is: " + text);}





// Add a sum function to arrays.
Array.prototype.sum = function()
{
 x = 0;
 for (i = 0; i < this.length; i++)
 {
  x += this[i];
 }
 return x;
}





function RESET()
{
textArray = '';
textArray = new Array();
divArray = '';
divArray = new Array();
document.getElementById('follower').innerHTML = '';
setMouseFollower();
}


function setMouseFollower(){
  if (debug){toDebug("In mouse follower function.");}

var text = origText;
if (useBox == true){
	if (document.getElementById('followText'))
	{
var fTB = document.getElementById('followText');
text = fTB.value;
	}
	   }
if (text == "" ){text="No Text";}


var brArray = new Array();

while (text.indexOf("<br>") > -1)
{
var pos = text.indexOf('<br>')
brArray[brArray.length] = pos;
text = text.substring(0,pos) + text.substring(pos+4,text.length);

}


if (debug){toDebug("Text = " + text);}

for (i=0;i<text.length;i++){

var thisChar = text.substring(i,i+1);
//if(debug){document.writeln(thisChar + " <br />");}
textArray[i] = thisChar;
if (pageLoaded == 0){
document.writeln("<div class='follower' id='fol" + i + "'>" + thisChar + "</div>\n");
}
else {
var folBox = document.getElementById('follower');
folBox.innerHTML += "<div class='follower' id='fol" + i + "'>" + thisChar + "</div>\n";

}
var folpi = "fol" + i;
var thisDiv = document.getElementById(folpi);
//document.writeln(thisDiv);
var x = 4*i;
divArray[x] = thisDiv; 

x++;
divArray[x] = i;
x++;
divArray[x] = i;



var nl=0;

for (l=0;l<brArray.length;l++)
{
if (i>=brArray[l]){nl++;}
}

for (q=0;q<divArray.length;q++)
{
 var somevar = q*4 + 3;
 if (divArray[somevar] == nl){nl = 0;}
}


x++;
divArray[x] = nl;
if(debug){toDebug("New Line: " + nl);}


//document.writeln(divArray.length);

			   }






  if (debug){toDebug("Exiting Mouse Follower Function<br>------<br><br>");}

pageLoaded = 1;
setTimeout("runMouseFollower();",100);
}

function runMouseFollower()
{
if (document.getElementById('follower'))
{

for (i=0;i<divArray.length/4;i++)
	{
        var x = 4*i;
	var nl = x+3;
	var myBox = divArray[x];
	nl = divArray[nl];
	//if (debug){toDebug(myBox + " x= " + x);}
	
var xca;
var yca;

if (x == 0){
	x++;
	var xc = divArray[x];
	xca = (xcoord-xc)/2;
	xc += xca;
	divArray[x] = xc;

	x++;
	var yc = divArray[x];
	yca = (ycoord-yc)/2 + 10;
	yc += yca+nl;
	divArray[x] = yc;

} 
else{
	if (nl == 0){
	x++;
	var z = x-4;
	var xc = divArray[x];
	var xco = divArray[z];
	xca = (xco-xc)/2;
	xc += xca+6;
	divArray[x] = xc;


	x++;
	var z = x-4;
	var yc = divArray[x];
	var yco = divArray[z];
	yca = (yco-yc)/2;
	yc += yca;
	divArray[x] = yc;
		     }


	else{
	x++;
	var xc = divArray[x];
	xca = (xcoord-xc)/2;
	xc += xca;
	divArray[x] = xc;

	x++;
	var yc = divArray[x];
	yca = (ycoord-yc)/2;
	yc += yca+(nl*10) + 10;
	divArray[x] = yc;

	
	    }


if (debug){toDebug("<b>x = " + x + "</b>");}
if (debug){toDebug("yc = " + yc);}
if (debug){toDebug("yco = " + yco);}
if (debug){toDebug("yca = " + yca);}


}


	myBox.style.top = yc;
	myBox.style.left = xc;
	}





 }
setTimeout("runMouseFollower();",50);
}



var bullets = new Array(0,0,0,0,0);

function fireBullet()
{
 for (k = 0; k < bullets.length; k++)
 {
  if (bullets[k] == 0)
  {
   bullets[k] = 1;
   var bulletName = "b" + (k+1);
   if (document.getElementById(bulletName))
   {
    var b = document.getElementById(bulletName);
    b.style.top = ycoord + 100;
    b.style.left = xcoord + 220;
    b.style.display = "block";
	
	
	if (bullets.sum() == 1)
	{
		setTimeout("runBullets();",50);
	}
	
    return;
   }
  }
  
 }

}

function runBullets()
{
 for (z = 0; z < bullets.length; z++)
 {
  if (bullets[z] == 1)
  {  
   var bulletName = "b" + (z+1);
   var b = document.getElementById(bulletName); 
   if (document.getElementById(bulletName))
   {
    var curTop = parseInt(b.style.top);
    var curLeft = parseInt(b.style.left);
	var newLeft = curLeft + 10;
	if (newLeft >= getWindowWidth()-10)
	{
	 bullets[z] = 0;
	 b.style.display = "none";
	 }
	 else
	 {
	  b.style.left = newLeft;
	 }
	}
   }
   else
   {
    //bullets.splice(z,1);
   }
 }
if (bullets.sum() >= 1)
 {
  setTimeout("runBullets();",50);
 }

}


function getWindowWidth()
{
var winW = 630;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
 }
}
return winW;

}


var ie = document.all?true:false;
if (!ie) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseCoords;
var xcoord = 0;
var ycoord = 0;

function getMouseCoords(e) {
if (ie) { // grab the x-y pos.s if browser is IE
xcoord = event.clientX + document.body.scrollLeft;
ycoord = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
xcoord = e.pageX;
ycoord = e.pageY;
}  
if (xcoord < 0){xcoord = 0;}
if (ycoord < 0){ycoord = 0;} 
//alert(xcoord + " " + ycoord);

return true;
}











function toDebug(theLine)
{

if (document.getElementById('debugBox')){
var debugBox = document.getElementById('debugBox');

//alert("debugBox is a/an " + debugBox);

debugBox.innerHTML += "\n<br />";
debugBox.innerHTML += theLine;
					}
else {alert(theLine);}

}
