Event.observe(window, 'load', function()
{
	var loggedInUser = readCookie('aflogin');
	if (loggedInUser)
	{
		$('logininfo').show();
		$('loggedinuser').update(loggedInUser.replace(/\+/g, ' '));

	}
	$('html').onclick = function()
	{
		$$('a.popNav').invoke("closeNav");
	}

	if ($('content'))
	{

		$('content').resize = function()
		{
			this.setStyle(
			{
			        width : document.viewport.getWidth() - 250 + 'px',
			        height : '100%'

			});
			if ($('bigPusher'))
			{

				$('bigPusher').setStyle(
				{

					height : document.viewport.getHeight() - 266 + 'px'
				});
			}
			

		}

		this.onresize = function()
		{
			$('content').setStyle(
			{
			        height : '0px',
			        width : '0px'

			});

			$('content').resize();
			if(document.flashLoaded)
				getFlashMovie("content").initImgView();
		}

		setTimeout("this.onresize()", 200);
	}
	else
	{
		this.onresize = function()
		{
			if ($('flashFrame')) setTimeout("flashResize()", 200);
		}
	}
	$$('div.popNav').each( function(el)
	{
		el.clip = clip;
		el.clipWidth = 0;
	});

	$$('a.popNav').each( function(el)
	{
		el.onclick = function(event)
		{
			if (!event) var event = window.event;
			event.cancelBubble = true;

			if ($(el).hasClassName('root')) $$('a.popNav').invoke("closeNav");

			var siblings = el.siblings();

			for ( var i = 0; i < siblings.length; i++)
			{
				if (siblings[i].closeNav) siblings[i].closeNav();
			}

			var menu = $(el.getAttribute('rel'));
			if (!menu) return false;
			if (menu.clipWidth > 0)
			{
				el.closeNav();
				return false;
			}

			var mOffsetY = el.cumulativeOffset()[1];
			var viewPortY = document.viewport.getHeight();
			var menuY = menu.scrollHeight;

			if (mOffsetY + menuY > viewPortY) mOffsetY = viewPortY - menuY - 20;
			else mOffsetY = el.cumulativeOffset()[1];

			var bullet = menu.select('div.bullet')[0];

			bullet.setStyle(
			{
				top : el.cumulativeOffset()[1] - mOffsetY + 'px'
			});

			menu.setStyle(
			{
			        width : menu.select('div.popMenu')[0].scrollWidth + 2 + 'px',
			        left : el.cumulativeOffset()[0] + 145 + 'px',
			        top : mOffsetY + 'px'

			});
			menu.select('div.tm')[0].setStyle(
			{
				width : menu.select('div.popMenu')[0].scrollWidth - 12 + 'px'
			});

			menu.select('div.bm')[0].setStyle(
			{
				width : menu.select('div.popMenu')[0].scrollWidth - 12 + 'px'
			});

			menu.setStyle(
			{
				clip : 'rect(0px,2000px,2000px,0px)'
			});

			/*
			 * menu.interval = setInterval( function() {
			 * menu.clip(25) }, 10);
			 */
			el.addClassName("active");
			return false;
		}

		el.closeNav = closeNav;
	});

});

function clip(width)
{

	if (this.scrollWidth > this.clipWidth)
	{
		this.setStyle(
		{
			clip : 'rect(0px ' + (this.clipWidth + width) + 'px 1000px 0px)'
		});
		this.clipWidth = this.clipWidth + width;
	}
	else
	{
		clearInterval(this.interval);
		this.setStyle(
		{
			clip : 'rect(0px,2000px,2000px,0px)'
		});

	}

}

function closeNav()
{
	var menu = $(this.getAttribute('rel'));
	if (!menu) return false;
	menu.setStyle(
	{
		clip : 'rect(0px 0px 2000px 0px)'
	});
	menu.clipWidth = 0;
	this.removeClassName("active");
	menu.select('div.popMenu a.popNav').invoke('closeNav');
}

function readCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

