// define bulletin namespace
if ( !AARP.Bulletin ) AARP.Bulletin = {};

AARP.Bulletin.bulletinHeader = function ()
{
	// for some reason, AARP.page.pathc is empty when this function runs, but not before or after
	// it's defined. so...rebuild it, since AARP.page.path is untouched
	var tmp = AARP.page.path.split( '/' );
	tmp.shift();
	AARP.page.pathc = tmp;
	
	if ( AARP.User.isLoggedIn )
	{
		var firstName = AARP.User.firstName;
		var newMessageCount = AARP.User.messages;
		var membername = AARP.User.name;
		
		$('welcomeAnon').hide();
		$('welcomeLoggedIn').show();
		$('firstName').update(firstName);
		if (newMessageCount > 0) {
			$('newMessageCount').update(' (' + newMessageCount + ' New)');
		}
	}
	
	// grab the channel name
	var channel = AARP.page.pathc[0];
	var subchannel = AARP.page.pathc[1];
	
	// correct for authoring instance (remove first two levels )
	if ( channel == 'author' )
	{
		channel = AARP.page.pathc[2];
		if ( !channel )
		{
			channel = AARP.page.file.split( '.' )[0];
			if ( channel == 'bulletin' ) channel = 'frontpage';
		}
		else
			subchannel = AARP.page.pathc[3];
	}
	// Defines channel for the front page at /
	else if ( window.location.pathname == '/' ) channel = 'frontpage';
	
	// set the navigation & subnav elements
	var channel_obj = $( channel + 'Nav' );
	var schannel_obj = $( channel + 'SubNav' );
	
	// if main nav exists, set to active state
	if ( channel_obj )
	{
		channel_obj.addClassName( 'active' );
	}
	
	// same for subnav
	if ( schannel_obj )
	{
		schannel_obj.style.display='';
		if ( $( subchannel ) )
		{
			subchannel = $( subchannel );
			subchannel.childNodes[0].className = 'active';
		}
	}
	
	Event.observe( 'searchTerms', 'blur', searchTerm.toggle, false );
	Event.observe( 'searchTerms', 'focus', searchTerm.toggle, false );
}
