//	navpod.js

//	Init Function _____________________________________________________________

Event.observe(window, 'load', function()
{
	Event.observe($('nav_head'), 'mousedown', operateNavPod, false);
	
	Event.observe($('long_head'), 'mousedown', operateLongPodHook, false);
	
	var panels = $A(document.getElementsByClassName('link_panel', 
		$('link_container')));
	panels.each(function (panel)
	{
		var e = $(panel.firstChild.id);
		
		Event.observe(e, 'mouseover', 
			function () { e.style.fontWeight = 'bold'; }, false);
			
		Event.observe(e, 'mouseout', 
			function () { e.style.fontWeight = 'normal'; }, false);
			
		Event.observe(e, 'mousedown', showLongPodHook, false);
	});
}, false);

//	Members __________________________________________________________________

var navClosed = true;
var longClosed = true;
var longPodShown = false;
var currentLinkPanel;

//	Methods __________________________________________________________________

function operateNavPod(op)
{
	if (navClosed || (op && op == 'open'))
	{
		new Effect.BlindDown('link_container', {queue: 'front'});
		navClosed = false;
	}
	else if (!navClosed  || (op && op == 'close'))
	{
		if (longPodShown) showLongPod('close');
		new Effect.BlindUp('link_container', {queue: 'end'});
		navClosed = true;
		
		if (currentLinkPanel)
		{
			currentLinkPanel.style.textDecoration = 'none';
			currentLinkPanel = null;
		}
	}
}

function showLongPodHook(event)
{
	if (currentLinkPanel)
	{
		currentLinkPanel.style.textDecoration = 'none';
	}
	
	var trigger = Event.element(event || window.event);
	
	currentLinkPanel = $(trigger.id);
	currentLinkPanel.style.textDecoration = 'underline';
	reloadLongPod(trigger.id);
}

function reloadLongPod(key)
{
	if (!longClosed) 
	{
		operateLongPod('close');
		getLinksFromServer(key);
		operateLongPod('open');
	}
	else
	{
		getLinksFromServer(key);
		showLongPod('open');
	}
}

function showLongPod(op)
{
	if (!longPodShown || (op && op == 'open'))
	{
		new Effect.Grow('longpod', {direction: 'top-left', queue: 'front'});
		longPodShown = true;
		operateLongPod();
	}
	else if (op && op == 'close')
	{
		if (!longClosed) operateLongPod('close');
		new Effect.Shrink('longpod', {direction: 'top-left', queue: 'end'});
		longPodShown = false;
	}
}

function operateLongPodHook(event)
{
	operateLongPod('close');
	showLongPod('close');
}

function operateLongPod(op)
{
	if (longClosed || (op && op == 'open'))
	{
		new Effect.SlideDown('long_body', {duration: 1, queue: 'end'});
		longClosed = false;
	}
	else if (!longClosed || (op && op == 'close'))
	{
		new Effect.SlideUp('long_body', {duration: 0.25, queue: 'front'});
		longClosed = true;
	}
}

function getLinksFromServer(linksKey)
{
	var request = new Ajax.Updater(
		'long_body_content',
		'linkdispatch.php',
		{ method: 'get', parameters: 'links=' +  linksKey});
}

function showNavPod()
{
	new Effect.Appear('navpod_container', {duration: 0.5, queue: 'end'});
}

function hideNavPod()
{
	new Effect.Fade('navpod_container', {duration: 0.5, queue: 'end'});
}
