function Is ()
{   // convert all characters to lowercase to simplify testing
    // We'll only test some, as index.html tests all.
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
    this.nav4up = (this.nav && (this.major >= 4));
    this.nav4b = (this.nav4up && (this.minor<= 4.03));
    this.nav5 = (this.nav && (this.major == 5));
    this.moz = this.nav5;
    this.nav5up = (this.nav && (this.major >= 5));

    this.ie   = (agt.indexOf("msie") != -1);
    this.ie4up  = (this.ie  && (this.major >= 4));


    // *** PLATFORM ***
    this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );

    this.mac    = (agt.indexOf("mac")!=-1);

    this.sun   = (agt.indexOf("sunos")!=-1);
    this.irix  = (agt.indexOf("irix") !=-1);    // SGI
    this.hpux  = (agt.indexOf("hp-ux")!=-1);
    this.aix   = (agt.indexOf("aix") !=-1);      // IBM
    this.linux = (agt.indexOf("inux")!=-1);
    this.sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    this.unixware = (agt.indexOf("unix_system_v")!=-1);
    this.mpras    = (agt.indexOf("ncr")!=-1);
    this.reliant  = (agt.indexOf("reliantunix")!=-1);
    this.dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
         (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
         (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    this.sinix = (agt.indexOf("sinix")!=-1);
    this.freebsd = (agt.indexOf("freebsd")!=-1);
    this.bsd = (agt.indexOf("bsd")!=-1);
    this.unix  = ((agt.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux ||
                 this.sco ||this.unixware || this.mpras || this.reliant ||
                 this.dec || this.sinix || this.aix || this.linux || this.bsd || this.freebsd);

    this.vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
    this.mozilla = (document.getElementById && document.getElementById(0)) ? 1:0;
}

var is = new Is(); 
if (is.unix || is.mac) 
	document.write('<LINK rel=STYLESHEET TYPE="text/css" HREF="unix.css">');
else 	document.write('<LINK rel=STYLESHEET TYPE="text/css" HREF="pc.css">');
timeout_speed = 1;
// Besides the pictures, the height we need includes 20 down from the top, the height of the title, and the height of the revealed footer.
boxH = imageheight+70; // 70 is the height of the title
boxW = 400;
needH = (is.unix||is.mac) ? (20+70+imageheight+30+20) : (is.nav4up) ? (20+70+imageheight+35+20) : (20+70+imageheight+40+20);									
needW = 20 + 5 + 135 + 5 + 20 + boxW; // just pictures and margins, and 400 for text.

if (is.nav4up) {
	var maxW = window.innerWidth;
	var maxH = window.innerHeight;
	}
else if (is.ie4up) {
	var maxW = document.body.clientWidth;
	var maxH = document.body.clientHeight;
	}
if (maxH<needH) { 
	maxH=needH;
	//alert("maxH<needH");
	document.writeln("<img src='pixel.gif' width=1 height="+maxH+" border=0>");
	}

if (maxW<needW) {
	//alert("maxW<needW "+maxW+" "+needW);
	if (maxH>needH) {
	   needW = maxW;
	   needH = maxH;
	   }
	else maxW=780;
	//alert("writing gif for width");
	document.writeln("<img src='pixel.gif' width="+maxW+" height=1 border=0>");
	}

if (needW < maxW) boxW = (is.ie4up) ?  (maxW - 210) : (maxW - 190);

document.writeln("<style TYPE='text/css'>");
document.writeln("#titlepix	 {visibility:show;position:absolute;left:20px;		  top:70px; width:"+boxW+";height:"+boxH+";z-index:10;}");  
document.writeln("#main 	 {visibility:show;position:absolute;left:20px; 		  top:70px; width:"+boxW+";height:"+boxH+";z-index:15;margin:0;border:0;}");  
document.writeln("#foot		 {visibility:show;position:absolute;left:20; 		  top:70px; width:"+boxW+";height:80;z-index:5;}");  
document.writeln("#pix		 {visibility:show;position:absolute;left:"+(boxW-150)+";top:50;width:150;}");
document.writeln("#footwidth {visibility:show;position:absolute;left:"+(boxW-1)+";    top:0; width:1;height:1;}");  
document.writeln("#mainwidth {visibility:show;position:absolute;left:"+(boxW-1)+";    top:0; width:1;height:1;}");  
document.writeln("</style>");

function placement(footcolor,pixcolor,maincolor) {
var startrgb=0;
if (document.layers) {
	document.layers.main.bgColor = maincolor;
	document.layers.titlepix.bgColor = pixcolor;
	document.layers.foot.bgColor =  footcolor;
	startrgb = document.layers.titlepix.bgColor;
	if (is.unix||is.mac)  boxH += 20;
	if (boxH<document.layers.main.document.height) boxH=document.layers.main.document.height;
	document.layers.foot.top = document.layers.main.top + boxH - document.layers.foot.document.height;
	//alert("foot top is now "+document.layers.foot.top+"="+document.layers.main.top+"+"+boxH+"-"+document.layers.foot.document.height);
	}
else if (document.all) {
	document.all['titlepix'].style.posLeft = 20;
	document.all['titlepix'].style.posTop = 70;
	document.all['foot'].style.posLeft = 20;
	document.all.main.style.backgroundColor = maincolor;
	document.all.titlepix.style.backgroundColor = pixcolor;
	document.all.foot.style.backgroundColor = footcolor;
	if (document.all.titlepix.style.backgroundColor.charAt(0)=="#") {
	   eval("startrgb = hexToDec(0x"+document.all.titlepix.style.backgroundColor.substr(1)+")");
	   }
	document.all.foot.style.posTop = (document.all.main.offsetTop + document.all.main.clientHeight) - document.all.foot.clientHeight;
	}
download_images();

var args = (is.unix||is.mac) ? "moveit('titlepix',160,-50,'foot',70,30)" : (is.nav4up) ? "moveit('titlepix',155,-50,'foot',70,35)" : "moveit('titlepix',155,-50,'foot',85,30)";									
	setTimeout(args,timeout_speed);
if (startrgb) {
	// following three lines courtesy http://tech.irt.org/articles/js162/
	r = startrgb >> 16;		  		  		 startr = r; //DecToHex(r);
	g = (startrgb & 0x00FF00) >> 8; startg = g; //DecToHex(g);
	b = startrgb & 0x0000FF;  	 		 startb = b; //DecToHex(b);
	setTimeout("fadeit(1)",(timeout_speed));
	}
}
//Convert one hex number into decimal form
function hexToDec(number){return number};

var hexbase="0123456789ABCDEF";
function DecToHex(number) {
   // take a decimal integer, return 2-digit hex string
   return hexbase.charAt((number>> 4)& 0xf)+ hexbase.charAt(number& 0xf);
 }
function getHex(r,g,b) {
   // convert 3 dec integers to hex strings and use as a colour value
   return '#'+DecToHex(r)+DecToHex(g)+DecToHex(b);
 }
 
function fadeit(loop){
var doit = 0;
var rvis = (document.layers) ? document.layers.titlepix.layers.redlogo : document.all['redlogo'].style;
var bvis = (document.layers) ? document.layers.titlepix.layers.blacklogo : document.all['blacklogo'].style;

if (loop==1) { //background goes from blueish to red
	if (r<250)	{doit=1; r+=5;}
	if (g>5)	{doit=1; g-=5;}
	if (b>5)	{doit=1; b-=5;}
	if (!doit) {
		rvis.visibility = 'visible';
		loop++;
		doit=1;
		}
	}
else if (loop==2) { //background goes from red to darkred
	if (r<=128) {
		bvis.visibility='visible';
		loop++;
		}
	else 	r-=5; 
	doit=1;
	}
else if (loop==3) { //background goes from darkred to whatever it started as
	if (r<startr)   {doit=1; r+=1}; 
	if (g<startg)	{doit=1; g+=1};
	if (b<startb)	{doit=1; b+=1};
	}
	
if (doit) {
	if (document.layers) document.layers.titlepix.bgColor = getHex(r,g,b);
	else if (document.all) document.all.titlepix.style.backgroundColor = getHex(r,g,b);
	setTimeout("fadeit(" + loop + ")",timeout_speed);
	}
//else alert("no more fadeit");
}

var websiteUrl = document.URL;
websiteDir = document.URL.lastIndexOf("/");
websiteUrl = document.URL.substring(0,websiteDir);

function setImage(name) {
doc = (document.layers) ? "document.titlepix.document" : (document.all) ? "document.all" : "";
var target = eval(doc + '["pix"]' + '.document.I'+name);
target.src = eval(name+'.src');
}

function moveit() { // shift a layer from one place to another - expecting what,toX,toY
var currentX, currentY, doit=0, left, top, what,toX, toY;
var i=0; var newargs = ""; var comma="";
for (i=0; i<moveit.arguments.length; i+=3){
	what = moveit.arguments[i];
	stepsX  = moveit.arguments[i+1];
	stepsY  = moveit.arguments[i+2];
	left = (document.all) ? "document.all(what).style.posLeft" : "document.layers[what].left";
	top  = (document.all) ? "document.all(what).style.posTop" : "document.layers[what].top";

	if (stepsX > 0) {
		eval(left + "++");
		stepsX--;
		doit = 1;
		}
	else if (stepsX < 0) {
		eval(left + "--");
		stepsX++;
		doit = 1;
		}
	if (stepsY > 0) {
		eval(top + "++");
		stepsY--;
		doit = 1;
		}
	else if (stepsY < 0) {
		eval(top + "--");
		stepsY++;
		doit = 1;
		}
	newargs+=comma+"'"+what+"',"+stepsX+","+stepsY,
	comma=",";
	}
if (doit)	setTimeout("moveit(" + newargs + ")",timeout_speed);
//else alert("no more movement");
}

