var ua=navigator.userAgent
var current,h,speech,begin
var timesThrough=0

//win box model fix
if (ua.indexOf("MSIE 5.")>0 && ua.indexOf("Win")>0) {
document.write("<link rel='stylesheet' href='/css/winIE5_fix.css' type='text/css'>")
}

//writes any extras
function writeThem(){
document.writeln("<img id='housemate4sit' src='images/4_sit.gif' width='16' height='35'>");
document.writeln("<img id='housemate5turn' src='images/05_left.gif' width='16' height='36'>");
document.writeln("<img id='housemate11sit' src='images/11_sit.gif' width='16' height='35'>");
document.writeln("<img id='housemate12turn' src='images/12.gif' width='16' height='35'>");
}


//speech bubbles
function saySomething(me){
clearTimeout(speech)
x=document.getElementById('speech'+current)
x1=document.getElementById('bubble'+current)
y=document.getElementById('speech'+me)
y1=document.getElementById('bubble'+me)
if (x!=null&&begin=="OK"){
	x.style.visibility ='hidden';
	x1.style.visibility ='hidden';}
if (y!=null&&begin=="OK"){
	y.style.visibility ='visible';
	y1.style.visibility ='visible';
	current=me;}
}

function thatsAll(){
if (h!=true&&begin=="OK"&&current!=null){
	document.getElementById('speech'+current).style.visibility ='hidden';
	document.getElementById('bubble'+current).style.visibility ='hidden';}
else {setTimeout('thatsAll()',100)}
}

var whichScenario
var counter=0
var scenarios=[['4',''],['5',''],['11',''],['nah','']]
var person4=[['147px','21px'],['146px','24px'],['146px','28px'],['146px','32px'],['147px','35px']]
var person5=[['106px','6px'], ['104px','7px'], ['102px','8px'], ['100px','9px'], ['98px','10px'], ['96px','11px'], ['94px','9px'],['90px','10px'],['86px','11px'],['82px','15px'],['80px','20px'],['78px','26px']]
var person11=[['64px','64px'],['62px','65px'],['60px','66px'],['58px','67px']]

function sweet(stay){
//displays the permant bubble (if any)
x=document.getElementById('speech'+stay);
x1=document.getElementById('bubble'+stay);
if (x!=null){
	x.style.visibility ='visible';
	x1.style.visibility ='visible';
	x.style.zIndex ='5';
	x1.style.zIndex ='4';
	}
//allows other speech bubbles to appear
begin="OK";
//set an event
doSomethingBaby();
}

function doSomethingBaby(){
if (timesThrough<2){
	do {whichScenario=Math.floor(4*Math.random());}
	while (!(scenarios[whichScenario][1]!="done"))

	if (whichScenario=="0"||whichScenario=="2"){setTimeout("animateTheLittleGuys(scenarios[whichScenario][0])",2000);}
	else if (whichScenario=="1"){setTimeout("turn(scenarios[whichScenario][0])",2000);}
	else {scenarios[whichScenario][1]="done";timesThrough++;setTimeout("doSomethingBaby()",100);}
	}

}

function animateTheLittleGuys(who){
//checks if person exists AND doesn't have a bubble
if (document.getElementById('housemate'+who)!=null&&!(document.getElementById('bubble'+who)!=null)){
	var thisArray=eval("person"+who)
	if (counter<thisArray.length){
		document.getElementById('housemate'+who).style.left=thisArray[counter][0];
		document.getElementById('housemate'+who).style.top=thisArray[counter][1];
		counter++;
		setTimeout("animateTheLittleGuys("+who+")",100);
		}
	else if (counter==thisArray.length){
		document.getElementById('housemate'+who).style.visibility='hidden';
		document.getElementById('housemate'+who+'sit').style.visibility='visible';
		scenarios[whichScenario][1]="done";
		counter=0;
		timesThrough++;
		setTimeout("doSomethingBaby()",100);
		}
	}
}

function turn(who){
if (document.getElementById('housemate'+who)!=null&&!(document.getElementById('bubble'+who)!=null)){
	var thisArray=eval("person"+who)
if (counter==0){
	document.getElementById('housemate'+who).style.visibility='hidden';
	document.getElementById('housemate'+who+'turn').style.visibility='visible';
	counter++;
	setTimeout("turn("+who+")",100);
	}
else if (counter<thisArray.length){
	document.getElementById('housemate'+who+'turn').style.left=thisArray[counter][0];
	document.getElementById('housemate'+who+'turn').style.top=thisArray[counter][1];
	counter++;
	setTimeout("turn("+who+")",100);
	}
else if (counter==thisArray.length){setTimeout("turnfinal()",700);}

	}

}

function turnfinal(who){
if (document.getElementById('housemate12')!=null){
	document.getElementById('housemate12').style.visibility='hidden';
	document.getElementById('housemate12turn').style.visibility='visible';
	scenarios[whichScenario][1]="done";
	counter=0;
	timesThrough++;
	setTimeout("doSomethingBaby()",100);
	}
}
