
RFPB.switchAddr = {};
RFPB.curLoc = ''; // Track current location

/**
 * Checks if the # part of the address bar has changed.
 * If it has, it focuses the correct doc.
 */
RFPB.switchAddr.check = function () {
	// Only trigger if: location has changed and is set to something we manage
	if (RFPB.curLoc != window.location.hash &&
		window.location.hash.length > 2 &&
		window.location.hash[1] == '_')
	{
		var loc = window.location.hash.substr(2);
		if (RFPB.curLoc != loc && document.getElementById(loc))
		{
			// Make sure parent category is open; Don't re-click it if it is!
			var parentClass = $j('#'+loc).parent().parent().attr('class');
			if ((parentClass != 'selected') && (parentClass != 'expand'))
			{
				$j('#'+loc).parent().parent().prev().click();
				window.scrollTo(0, document.getElementById('rfp-container').offsetTop);
			}
			// Click the newly "selected" doc
			$j('#'+loc).click()
			// Keep in mind where we are
			RFPB.curLoc = loc;
		}
	}
}

/**
 * Sets the address bar hash (#) to the correct text if a link is clicked.
 */
RFPB.switchAddr.nowAt = function (link) {
	window.location.hash = '#_'+link.id;
	RFPB.curLoc = window.location.hash;
}

$j(function () {
	RFPB.switchAddr.check();
	setInterval(RFPB.switchAddr.check, 100);
});

