var s_cleared = false;

function MM_findObj(n, d) { //v4.01
//  alert("find("+n+")");
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
//    alert("done");
  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function clearSearch(){
 if(s_cleared) return;
 else {
 document.forms['searchFrm'].elements['s'].value = "";
 s_cleared = true;
 }
}

function runActiveContent(what) {
	document.write(what);
}

function doHighlight(what) {
	//var tbl = MM_findObj("cat"+what);
	var tbl = document.getElementById('cat'+what);
	var td = document.getElementById('td'+what);
	//alert(tbl.style.cssText);
	tbl.style.cssText = 'border: #c4bdbe 1px solid';
	td.style.cssText = 'padding: 0px';
	
}

function doBlur(what) {
	var tbl = document.getElementById('cat'+what);
	var td = document.getElementById('td'+what);
	tbl.style.cssText = 'border: none';
	td.style.cssText = 'padding: 1px';
}

var ColorTimer = null;
var CurrentColor = new Array();
var dr = 1;
var dg = -1;
var db = -1;
var r_done = false;
var g_done = false;
var b_done = false;

function dec2hex (dec)
{
	var hexChars = "0123456789ABCDEF";
	var a = dec % 16;
	var b = (dec - a) / 16;
	hex = '' + hexChars.charAt (b) + hexChars.charAt (a);
	return hex;
}

function setPhoneColor (r, g, b)
{
	var code = document.getElementById ('code');
	var phone = document.getElementById ('phone');
	var color = '#' + dec2hex(r)+dec2hex(g)+dec2hex(b);
	if (code) code.style.color = color;
	if (phone) phone.style.color = color;
	//window.status = CurrentColor.r.toString+" - "+CurrentColor.g.toString+" - "+CurrentColor.b.toString;
}

function initColors()
{
	CurrentColor.r = 0; // 207
	CurrentColor.g = 125; // 61
	CurrentColor.b = 125; // 36
	
	ColorTimer = setInterval (shiftColor, 50);
}

function shiftColor()
{
	var x = Math.floor (10 * Math.random());
	if (x < 4) CurrentColor.r = moveColorComponent(CurrentColor.r, 0, 207, "r");
	else if (x <7) CurrentColor.g = moveColorComponent(CurrentColor.g, 61, 125, "g");
	else CurrentColor.b = moveColorComponent(CurrentColor.b, 36, 125, "b");
	
	setPhoneColor (CurrentColor.r, CurrentColor.g, CurrentColor.b);

	if(r_done&&g_done&&b_done) {
		dr = -dr;
		db = -db;
		dg = -dg;
		r_done = false;
		g_done = false;
		b_done = false;
	}

	//alert("R="+CurrentColor.r.toString()+" ("+dr.toString()+"; "+r_done.toString()+"); G="+CurrentColor.g.toString()+" ("+dg.toString()+"; "+g_done.toString()+"); B="+CurrentColor.b.toString()+" ("+db.toString()+"; "+b_done.toString()+")");
	
	//clearInterval (ColorTimer);
	//ColorTimer = setInterval (SlightlyAlterColor, 150);	
}

function moveColorComponent (value, min, max, code)
{
	var step = Math.floor (5 * Math.random())+10;
	
	var d;
	
	if(code=="r") d = dr;
	if(code=="g") d = dg;
	if(code=="b") d = db;
	
	if (d<0) {
		if(value-step>min) value-=step;
		else {
			value = min;
			//alert(code+": "+value);
			if(code=="r") r_done = true;
			if(code=="g") g_done = true;
			if(code=="b") b_done = true;
		}
	} else {
		if(value+step<max) value+=step;
		else {
			value = max;
			//alert(code+": "+value);
			if(code=="r") r_done = true;
			if(code=="g") g_done = true;
			if(code=="b") b_done = true;
		}
	}

	if(code=="r") dr = d;
	if(code=="g") dg = d;
	if(code=="b") db = d;

	return value;
}

initColors(); 
