oldBackgroundColor = "";

objX = null;
iX = 0;
limit=30

function changeBg(obj) {
	oldBackgroundColor = obj.style.backgroundColor;
	obj.style.backgroundColor= randomColorLight();
}

function display2(obj, value) {display3(obj, value, 'scroll');}

function display3(obj, value, scr) {
	obj = document.getElementById(obj); 
	oldDisplay=obj.style.display;
	obj.style.display=value;
	scrollAmount= 200;
	if(scr=='scroll' && oldDisplay!='inline') scrollSlowly(); //window.scrollBy(0, amount);
}

function flip() {return randInt(2)==0;}

function floatObj(obj, replacement) {
	document.getElementById('interactiveMsg').title = "";
	replacementObj = document.getElementById(replacement);
	replacementObj.style.fontFamily="Cursive";
	if (obj.moving) {
	  stopMoving('#8899ff');
	  return;
	}
	upDown = leftRight = 0;
	while (upDown==0) upDown = randInt(3)-1;
	leftRight = randInt(3)-1;
	obj.style.oldPixelTop = obj.style.pixelTop;
	obj.style.oldPixelLeft = obj.style.pixelLeft;
	obj.style.oldBackgroundColor = obj.style.backgroundColor;
	obj.style.oldColor = obj.style.color;
	obj.style.oldFontWeight = obj.style.fontWeight;
	obj.style.oldFontSize = obj.style.fontSize;
	obj.moving=true;
	movingObj = obj;
	replacementObj.display="inline";
	replacementObj.style.backgroundColor="#ff99bb";
	moveIt();
	replacementObj.innerHTML=replacement;
	replacementObj.style.border="outset 2";
	replacementObj.style.color="#000000";
}

function hexDigit(d) {
    d = Math.max(0, Math.min(15, d));
	return String.fromCharCode(d + ((d<10) ? 48 : (97-10)));
}

var replacementObj;
var movingObj;
var upDown;
var leftRight;
var distance = 250

function moveIt() {
	  if (!movingObj.moving) return;
	  movingObj.style.pixelTop += upDown;
	  movingObj.style.pixelLeft += leftRight;
	  if (movingObj.style.pixelTop < -distance || movingObj.style.pixelTop > distance ||
		  movingObj.style.pixelLeft < -distance || movingObj.style.pixelLeft > distance) {
	  	stopMoving('#ff99bb');
		return;
	  }
	  movingObj.style.backgroundColor = "#000000";
	  movingObj.style.color = "#ffff00";
	  movingObj.style.fontWeight=900;
	  var dist = Math.floor(Math.max(Math.abs(movingObj.style.pixelTop), 
	                                 Math.abs(movingObj.style.pixelLeft)));
	  var pct = 1 - (distance-dist)/distance;
	  movingObj.style.fontSize = Math.floor(30*(1-pct));
	  var hexColorDigit = hexDigit(Math.floor(16*pct));
	  replacementObj.style.color= '#' + hexColorDigit + hexColorDigit+ hexColorDigit + hexColorDigit+ hexColorDigit + hexColorDigit;
	  setTimeout("moveIt()", 1);
}

function outIn(obj) {outIn(obj, 0);}
function outIn(obj, delay) {
	if(outInRunning) return;
	outInRunning=true;
        objX = obj;
	iX = 0;
	setTimeout("outI("+ iX + ")", delay);
}

outInRunning=false;

function outI(iX) {
	if (iX%(Math.floor(limit/3))==0) color = randomColor();
	objX.style.borderStyle = "outset";
	objX.style.borderWidth = iX<(limit/2)?iX:limit-iX;
	objX.style.borderColor = color;
	if (iX < limit) {
	  iX++;
	  setTimeout("outI("+ iX + ")", 45);
	} else outInRunning=false;
}

function popIn(obj) {obj.style.border="";}

function popOut(obj, size, color) {
//alert("border: outset " + size + " '" + color + "'");
	obj.style.borderStyle = "outset";
	obj.style.borderWidth = size;
	obj.style.borderColor = color;
	obj.style.padding = 3;
//  obj.style.border = "outset " + size + '#ff0000'; // + " '" + color + "'";
}

function randHex() {return hexDigit(randInt(16));}

function randHexHigh() {return String.fromCharCode(101+randInt(2));}

function randInt(high) {
	return Math.floor(Math.random()*high);
}

function randomColor() {
	return '#'+randHex()+randHex()+randHex()+randHex()+randHex()+randHex();
}

function randomColorLight() {
        return '#'+randHexHigh()+randHexHigh()+randHexHigh()+randHexHigh()+randHexHigh()+randHexHigh();
}

function restoreBg(obj) {
	obj.style.backgroundColor=oldBackgroundColor;
}

function scrollSlowly() {
	window.scrollBy(0, 2);
	if (scrollAmount-- <= 0) return;
	setTimeout("scrollSlowly()", 1);
}


function stopMoving(newBackground) {
	  movingObj.style.pixelTop = movingObj.style.oldPixelTop;
	  movingObj.style.pixelLeft = movingObj.style.oldPixelLeft;
	  movingObj.style.backgroundColor = newBackground; // movingObj.style.oldBackgroundColor;
	  movingObj.style.color = '#ffffff'; // movingObj.style.oldColor;
	  movingObj.style.fontSize = movingObj.style.oldFontSize;
	  movingObj.style.fontWeight = 400; // movingObj.style.oldFontWeight;
	  movingObj.moving=false;
	  replacementObj.style.border="0";
	  replacementObj.innerHTML="";
	  if (document.getElementById("bottom").style.display=="none") {
	  display3('p15', 'inline', "noscroll");
	  }
}
