var curr;
function show(name){
	var onDiv = document.getElementById( name + "OnDiv" );
	if( curr && curr != onDiv ){
		hide(onDiv);
	}
	fade(onDiv.id,10);
	curr = onDiv;
	
	hideQuestion();
}
function hide(who){
	curr = null;
	fade(who+"OnDiv",-10);
	showQuestion();
}
function fade( id, delta ){
	var div = document.getElementById(id)
	
	if( div ){
		clearTimeout( div.fadeTimeout );
		if( ! div.opacity ){
			div.opacity = (delta>0) ? 0 : 100;
			div.style.visibility = "visible";
		}
		
		div.opacity += delta;
		div.style["filter"] = "alpha(opacity=" + div.opacity + ")";
		div.style["-moz-opacity"] = (div.opacity-1) / 100;
		div.style["opacity"] = (div.opacity-1) / 100;
		if( div.opacity == 0 ){
			div.style.visibility = "hidden";
		}
		else if( div.opacity < 100 ){
			div.fadeTimeout = setTimeout("fade('" + id + "'," + delta + ")", 7);
		}
		else if ( div.opacity == 100 ){
			div.style["filter"] = "";
			div.style["-moz-opacity"] = ".9";
			div.style["opacity"] = ".9";
		}
	}
}

for( var maxQuestionID=0; document.getElementById( "homeQuestion" + maxQuestionID + "Div" ); maxQuestionID++ );
var currQuestion = null;
var currQuestionID = null;
function showQuestion(){
	hideQuestion();
	if( currQuestionID != null ){
		currQuestionID = (currQuestionID+1) % maxQuestionID
	}
	else{
		currQuestionID = Math.floor(Math.random() * maxQuestionID);
	}
	
	currQuestion = document.getElementById( "homeQuestion" + currQuestionID + "Div" );
	fade( currQuestion.id, 10 );
}
function hideQuestion(){
	if( currQuestion ){
		fade( currQuestion.id, -10 );
		currQuestion = null;
	}
}
showQuestion();


function recentOver(img){
	mouseover(img.name);
	showDesc(img,true);
	
}
function recentOut(img){
	mouseout(img.name);
	showDesc(img,false);
}
function showDesc( img, on_off ){
	var div = document.getElementById( img.name.replace('Img','DescDiv') );
	div.style.visibility = (on_off) ? 'visible' : 'hidden';
	
	div.style.top = img.offsetTop + img.offsetParent.offsetTop - 2
}

if( is.ie5 && is.mac ){
	var allDivs = document.getElementsByTagName("DIV");
	document.all.pageCenterer.align = 'left';	
}
init("showOnImages()");
function showOnImages(){
	var imgs = ["door", "room", "wall", "window", "hallway"];
	for( var i in imgs ){
		var name = imgs[i] + "_on";
		document.images[name].src = document.images[imgs[i]].src.replace("off","on");
	}
}