var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;
if (ie5 || ns6) {
var anzahl = 6;
var batmax = 30;
var bat_pic = '/_pic/oh_bat.gif';
var bat_pic2 = '/_pic/oh_bat2.gif';
var w = 200;
var h = 99;
var batback = 0;
var running = true;
var starting = true;
var clearing = false;
var canmess = (document.getElementById('hint1')) ? true : false;
dt = new Array();
dl = new Array();
var dw = new Array();
var dh = new Array();
dirl = new Array();
dirt = new Array();
dirs = new Array();
var dir = 0;
var s=2;
var cansize = 0;
var x = -1;
init();
window.setTimeout('startf2()',600);
window.setTimeout('startf1(0,1)',500);
}
function init() {
docw = (ns6) ? self.innerWidth : document.body.clientWidth;
doch = (ns6) ? self.innerHeight : document.body.clientHeight;
lmax = docw - w;
tmax = doch - h;
for (i = 0; i < batmax; ++ i) {
dt[i] = parseInt(Math.random()*tmax);
dl[i] = parseInt(Math.random()*lmax);
x = parseInt(Math.random()*90);
dw[i] = w - x;
dh[i] = h - parseInt(x/2);
dir ++;
if (dir==1) {dirt[i] = true; dirl[i] = true; dirs[i] = true;}
else if (dir==2) {dirt[i] = true; dirl[i] = false; dirs[i] = false;}
else if (dir==3) {dirt[i] = false; dirl[i] = true; dirs[i] = true;}
else if (dir==4) {dirt[i] = false; dirl[i] = false; dirs[i] = false;}
else {dirt[i] = false; dirl[i] = true; dirs[i] = true;}
if (i/2 == parseInt(i/2)) pic = bat_pic;
else pic = bat_pic2;
if (i>anzahl)
document.writeln('<DIV ID=\"bat'+ i +'\" STYLE=\"position: absolute; visibility: hidden; left: '+dl[i]+'px; top: '+dt[i]+'px;\">');
else {
document.writeln('<DIV ID=\"bat'+ i +'\" STYLE=\"position: absolute; left: '+dl[i]+'px; top: '+dt[i]+'px; z-index: '+i+';\">');
}
document.writeln('<img src=\"'+pic+ '\" width=0 border=0 id=\"batp'+i+'\"></DIV>');
}
}
function addBat() {
if (running  && !starting && anzahl<batmax) {
docw = (ns6) ? self.innerWidth : document.body.clientWidth;
doch = (ns6) ? self.innerHeight : document.body.clientHeight;
lmax = docw - w;
tmax = doch - h;
dt[anzahl] = parseInt(Math.random()*tmax);
dl[anzahl] = parseInt(Math.random()*lmax);
x = parseInt(Math.random()*20) + 1;
dw[anzahl] = x;
dh[anzahl] = parseInt(x/2);
dir ++;
if (dir==5) dir = 1;
if (dir==1) { dirt[anzahl] = true; dirl[anzahl] = true; dirs[anzahl] = true; }
else if (dir==2) { dirt[anzahl] = true; dirl[anzahl] = false; dirs[anzahl] = false; }
else if (dir==3) { dirt[anzahl] = false; dirl[anzahl] = true; dirs[anzahl] = true; }
else { dirt[anzahl] = false; dirl[anzahl] = false; dirs[anzahl] = false; }
document.getElementById('batp'+anzahl).style.visibility = 'visible';
anzahl ++;
cansize++;
if (canmess) document.getElementById('hint1').innerHTML = 'Total bats: <B>' + anzahl + '</B>';
}
else {
if (running) if (canmess) document.getElementById('hint1').innerHTML = 'Total bats: <B>' + anzahl + ' is the maximum, sorry!</B>';
}
if(!running && !clearing && !starting) stopp(0);
}
function delBat() {
if (running && !starting && anzahl>0) {
anzahl --;
document.getElementById('batp'+anzahl).style.visibility = 'hidden';
document.getElementById('batp'+anzahl).style.width = "2px";
document.getElementById('batp'+anzahl).style.height = "1px";
cansize --;
if (canmess) document.getElementById('hint1').innerHTML = 'Total bats: <B>' + anzahl + '</B>';
}
else if(!running && !clearing && !starting) stopp(0);
}
function startf1(n,y) {
if (n < anzahl) {
if (canmess) {
document.getElementById('hint1').innerHTML = 'Bats counter: ' + (n+1);
if (n != x) {
x = n;
document.getElementById('bt3').src='/_pic/a13.gif';
window.setTimeout("document.getElementById('bt3').src='/_pic/a03.gif'",200);
}
}
if (y < dw[n]) {
document.getElementById('batp'+n).style.width = y + "px";
document.getElementById('batp'+n).style.height = parseInt(y/2) + "px";
y += 5;
window.setTimeout('startf1('+n+','+y+')',8);
}
else {
cansize++;
n++;
window.setTimeout('startf1('+n+',1)',50);
}
}
else {
if (canmess) {
document.getElementById('hint1').innerHTML = 'Total bats: ' + anzahl + '</B>';
}
starting = false;
}
}
function startf2() {
docw = (ns6) ? self.innerWidth : document.body.clientWidth;
doch = (ns6) ? self.innerHeight : document.body.clientHeight;
lmax = docw - w;
tmax = (ns6) ? doch - h : doch - h + document.body.scrollTop;
tmin = (ns6) ? 1 : document.body.scrollTop + 1;
for (i = 0; i < anzahl; i ++) {
s = (Math.random()*3) + 1;
if (dirt[i]) {dt[i] += s; dirt[i] = (dt[i] >= tmax) ? false : true; }
else { dt[i] -= s; dirt[i] = (dt[i] < tmin) ? true : false; }
s = (Math.random()*3) + 1;
if (dirl[i]) {dl[i] += s; if (dl[i] >= lmax) dirl[i] = false; }
else { dl[i] -= s; dirl[i] = (dl[i] < 4) ? true : false; }
if (i < cansize) {
if (dirs[i]) { dw[i] -= 2; dh[i] -= 1; if (dw[i]<20) dirs[i] = false; }
else { dw[i] += 2; dh[i] += 1; if (dw[i]>=w) dirs[i] = true; }
document.getElementById('batp'+i).style.width = dw[i] + "px";
document.getElementById('batp'+i).style.height = dh[i] + "px";
document.getElementById('bat'+i).style.zIndex = dh[i];
}
document.getElementById('bat'+i).style.top = dt[i]+'px';
document.getElementById('bat'+i).style.left = dl[i]+'px';
}
if (running) window.setTimeout('startf2()',50);
else {
clearing = true;
stopp1(99);
}
}
function stopp(n) {
if (!clearing) {
if (running) {
running = false;
batback = n;
if (canmess) document.getElementById('hint1').innerHTML = 'Clearing screen from bats...';
}
else {
running = true;
for (i = 0; i < anzahl; i ++) {
s = parseInt((Math.random()*70) + 6);
dw[i] = s;
dh[i] = parseInt(s/2);
document.getElementById('batp'+i).style.visibility = 'visible';
}
if (canmess) document.getElementById('hint1').innerHTML = 'Total bats: <B>' + anzahl + '</B>';
for (i = 1; i < 4; i++) document.getElementById('bt'+i).src='/_pic/a0'+i+'.gif';
startf2();
}
}
else if (canmess) document.getElementById('hint1').innerHTML = 'Clearing is in progess!<BR>Please be patient...';
}
function stopp1(n) {
if (n>0) {
a = 0;
for (i = 0; i < anzahl; i ++) {
if (dw[i]>4) {
a++;
dw[i] -= 4;
dh[i] -= 2;
document.getElementById('batp'+i).style.width = dw[i] + "px";
document.getElementById('batp'+i).style.height = dh[i] + "px";
}
}
n --;
if (a>0) window.setTimeout('stopp1('+n+')',30);
else stopp1(0);
}
else {
for (i = 0; i < anzahl; i ++) document.getElementById('batp'+i).style.visibility = 'hidden';
if (batback==1) bat_go();
else {
if (canmess) document.getElementById('hint1').innerHTML = 'Bats are at home.';
clearing = false;
hlpWait(2,0);
}
}
}
function hlpOn(n) {
if (running && !clearing && !starting) {
document.getElementById('bt'+n).src='/_pic/a1'+n+'.gif';
if (n==1) document.getElementById('hint1').innerHTML = 'Click here to remove a bat.';
if (n==2) document.getElementById('hint1').innerHTML = 'Click here to clear all bats from the screen.';
if (n==3) document.getElementById('hint1').innerHTML = 'Click here to add a bat.';
}
}
function hlpOff(n) {
if (running && !clearing && !starting) {
document.getElementById('bt'+n).src='/_pic/a0'+n+'.gif';
document.getElementById('hint1').innerHTML = 'Total bats: <B>' + anzahl + '</B>';
}
}
function hlpWait(n,z) {
if (!running) {
m = n - 1;
if (m == 0) m = 3;
document.getElementById('bt'+m).src='/_pic/a0'+m+'.gif';
document.getElementById('bt'+n).src='/_pic/a1'+n+'.gif';
n++;
if (n==4) n = 1;
z ++;
if (z==8) {
if (document.getElementById('hint1').innerHTML == 'Click any control to restart.') document.getElementById('hint1').innerHTML = 'Bats are at home.';
else document.getElementById('hint1').innerHTML = 'Click any control to restart.';
z = 0;
}
if (!running) window.setTimeout('hlpWait('+n+','+z+')',300);
}
}

