function strpos( haystack, needle, offset){
// Finds position of first occurrence of a string within another  
// 
// version: 810.1317
// discuss at: http://phpjs.org/functions/strpos
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Onno Marsman    
// *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
// *     returns 1: 14
var i = (haystack+'').indexOf( needle, offset ); 
return i===-1 ? false : i;
}


function process_width()
{
	var w = 0;
	var h = 0;
	var content;
	var building;
	var half_difference = 300;
	var full_difference = 600;
	var margin_corrector = 280;
	

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	
	buildingdiv = document.getElementById('building');
	buildingInner = document.getElementById('building_inner');

	content = document.getElementById('content').offsetWidth;
	building = document.getElementById('building').offsetWidth;
	neighborhood = document.getElementById('building_neighborhood');

	/*
	
	calculation has to be different now that there's overlap.  Overlap is always 280.
	
	available space to the left is of course half the difference between content and the window width. 
	
	*/
	
	difference = Math.round((w - content)/2);
	newwidth = difference + half_difference;
	newoffset = -1 * (full_difference - newwidth);
	
	if (newwidth < half_difference) { //we've reached our minimum.
		newwidth = half_difference;
		newoffset = -half_difference;
	} else if (newwidth > full_difference) {
		newoffset = newwidth - full_difference;		
	}
	

	buildingdiv.style.width = newwidth + 'px';
	buildingInner.style.marginLeft =  newoffset + 'px';
	
	
	document.getElementById('navbar_inner').style.marginLeft =  (newwidth - margin_corrector) + 'px';

	if (strpos(navigator.userAgent, 'MSIE') > 0) {
	
		var wobj = document.getElementById('content').getBoundingClientRect();
		var wrapper_x = wobj.left;
		var iobj = document.getElementById('content_inner').getBoundingClientRect();
		var inner_x = iobj.left;
		
	} else {
	
		wrapper_x = document.getElementById('content').offsetLeft;
		inner_x = document.getElementById('content_inner').offsetLeft;
	
	}

	
	//update now_open.
	try {document.getElementById(now_open).style.left = inner_x + 'px';} catch (p_err) {}

	//move neighborhood
	if (strpos(navigator.userAgent, 'MSIE') > 0)
		neighborhood.style.marginLeft = half_difference + 'px';
	else 
		neighborhood.style.marginLeft = newwidth + 'px';

	//document.getElementById('debug').innerHTML = w + '<br>inner content' + inner_x + '<br>diff ' + difference + '<br>width ' + newwidth + '<br>offset ' + newoffset + '<br>wx ' + wrapper_x + '<br>n ' + neighborhood.style.marginLeft;

	if (strpos(navigator.userAgent, 'Firefox/2') > 0 || strpos(navigator.userAgent, 'Firefox/3') > 0 || strpos(navigator.userAgent, 'MSIE 6') > 0)
		setTimeout("process_width();",200);
	
}

//FF fires the onresize only after mouseup.  So do this for FF: 
/* FireFox resize workaround start*/

if (strpos(navigator.userAgent, 'Firefox/2') > 0 || strpos(navigator.userAgent, 'Firefox/3') > 0 || strpos(navigator.userAgent, 'MSIE 6') > 0) {
	setTimeout("process_width();",200);
} else {
	window.onresize = process_width;
}
var scrollOffsetValue = document.documentElement.scrollTop;

function process_navbar(last_y) {
	if (last_y == undefined || last_y != document.documentElement.scrollTop) {//then we're just starting, or still going
		last_y = document.documentElement.scrollTop;
		try {clearTimeout(NBtimeout);} catch (e) {} //might not have a timeout to clear
		NBtimeout = setTimeout("process_navbar("+last_y+");",200);
	} else {
		 //then we're done, so put the navbar in the right place
		clearTimeout(NBtimeout);
		nbTarget = (document.documentElement.scrollTop + document.documentElement.clientHeight) - 45;
		document.getElementById('navbar').style.top = nbTarget + 'px';
	} 
}


if (strpos(navigator.userAgent, 'MSIE 6') > 0 || strpos(navigator.userAgent, 'iPhone') > 0 || strpos(navigator.userAgent, 'iPad') > 0) { /* for positioning nav. */
	window.onscroll = process_navbar;
	window.onresize = process_navbar;
}


/*
if (strpos(navigator.userAgent, 'MSIE 6') > 0) {
		alert('is Zis');
		neighborhood.style.marginLeft = '300px';
		neighborhood.style.position = 'absolute';
	} else 
*/