/**
 * Main Site UI core
 * 
 * VERSION: 1.0.16384
 */
 
// Menubar UI
var AAOA_URL_REQUEST_GENERAL_URL				= 0;
var AAOA_URL_REQUEST_BENEFETS_PAGE				= 1;

var AAOA_URL_RESPONSE_ERROR						= 0;
var AAOA_URL_RESPONSE_INVALID_REQUEST			= 1;
var AAOA_URL_RESPONSE_REQUIRES_PIN_LOGIN		= 2;
var AAOA_URL_RESPONSE_REQUIRES_ACCOUNT_LOGIN	= 3;
var AAOA_URL_RESPONSE_NO_ACCESS					= 4;

/* ================================================================================
 * UI_MainMenu_HideAllSlideMenus()
 *
 * Hides all the slideable menu items in the main menu pane.
 */
function UI_MainMenu_HideAllSlideMenus()
{
	var menuItems;
	
	menuItems = $$('.subMenuContainer');
	
	menuItems.each(function(s) 
						   {
						   		if( s.style.display != 'none' )
						   		{
							   		Effect.SlideUp( s.id, { duration: 0.5 } );
						   		}
							});
	return true;
}

/* ================================================================================
 * UI_MainMenu_OpenSlideMenuItem()
 *
 * Slides open a slideable menu item
 */
function UI_MainMenu_OpenSlideMenuItem( menuItemId )
{	
	if( 'none' == $( menuItemId ).style.display )
	{
		Effect.SlideDown( menuItemId, { duration: 0.5 } );
	}
	return true;
}

/* ================================================================================
 * UI_MainMenu_SlideIntoMenu()
 *
 * Hides other menu items and opens the current slides open the current one.
 */
function UI_MainMenu_SlideIntoMenu( menuItemId )
{
	UI_MainMenu_OpenSlideMenuItem( menuItemId );
	//UI_MainMenu_HideAllSlideMenus();
}

/* ================================================================================
 * UI_MainMenu_ToggleSlideMenu()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */

function UI_MainMenu_ToggleSlideMenu( menuItemId )
{
	
	if( 'none' == $( menuItemId ).style.display )
	{
		Effect.SlideDown( menuItemId, { duration: 0.5 } );
	}
	else
	{
		Effect.SlideUp( menuItemId, { duration: 0.5 } );
	}
}

/* ================================================================================
 * UI_MainMenu_ToggleSubMenu()
 *
 * Toggles between sub menus for independant categories
 */

function UI_MainMenu_ToggleSubMenu( subMenuName )
{
	var menuId 		= 'menu' + subMenuName;
	var imageId		= 'imgArrow' + subMenuName;
	
	var allSubMenus	= [ 'Healthcare', 'Travel', 'BusinessServices', 'Publications' ];
	
	// Hide other sub menus
	allSubMenus.each ( function ( s ) {
								 var e 	= $( 'menu' + s );
								 var i 	= $( 'imgArrow' + s );
								 
								 if ( e )
								 {
									 if ( e.style.display != 'none' )
									 {
										 new Effect.BlindUp( e, { duration: 0.5 } );
									 }  
									 if ( i )
									 {
										 i.src = '/images/arrow-1-tiny-right.gif';
									 }
								 } 
							});
	
	// Scroll down the menu
	var e 	= $(menuId);
	var i 	= $(imageId);
	
	if ( e )
	{
		if ( e.style.display == 'none' )
		{
			new Effect.BlindDown( e, { duration: 0.5 } );
			if ( i )
			{
				i.src = '/images/arrow-1-tiny-down.gif';
			}
		}
		else
		{
			new Effect.BlindUp( e, { duration: 0.5 } );
			if ( i )
			{
				i.src = '/images/arrow-1-tiny-right.gif';
			}
		}
	}
	
	// Change arrow image
	
	
	
}

/* ================================================================================
 * UI_MainMenu_ShowFadeMenu()
 *
 * Shows a faded manu item
 */
function UI_MainMenu_ShowFadeMenu( menuItemId )
{
	if( 'none' == $( menuItemId ).style.display )
	{
		Effect.Appear( menuItemId, { duration: 0.8 } );
	}
}

/* ================================================================================
 * UI_MainMenu_HideFadeMenu()
 *
 * Hides a faded manu item
 */
function UI_MainMenu_HideFadeMenu( menuItemId )
{
	if( 'none' != $( menuItemId ).style.display )
	{
		Effect.Fade( menuItemId, { duration: 0.8 } );
	}
}

/* ================================================================================
 * UI_MainMenu_TogleFadeMenu()
 *
 * Togles a faded manu item, displays if invisible, hides if it is
 */
function UI_MainMenu_TogleFadeMenu( menuItemId )
{
	if( 'none' == $( menuItemId ).style.display )
	{
		Effect.Appear( menuItemId, { duration: 0.8 } );
	}
	else
	{
		Effect.Fade( menuItemId, { duration: 0.8 } );
	}
}

/* ================================================================================
 * UI_MainMenu_ToggleSlideMenu()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */
function UI_MainMenu_OpenPopoutMenu( menuItemId )
{
	var menuItem 	= $( menuItemId );
	var childMenu 	= $( menuItemId + 'Child' );
	
	childMenu.show();
	Effect.Move( childMenu.id, {x: 0, y: 130 } );
	
	if( 'none' == childMenu.style.display )
	{
		childMenu.style.position 	= 'absolute';
		childMenu.style.top 		= menuItem.style.top;
		childMenu.style.left 		= menuItem.style.left;
		
		// Move menu item into view while fading it into the screen
		Effect.Appear( childMenu.id, {duration: 0.5 } );
		Effect.Move( childMenu.id, {x: 0, y: 130 } );
	}
}


/* ================================================================================
 * UI_New_OpenSubMenuItem()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */

function UI_New_OpenSubMenuItem( menuId )
{
	em = $(menuId);
	
	if ( em )
	{
		if ( 'none' == em.style.display )
		{
			em.style.display = 'block';
			
			//em.style.left = '100px';
			/*
			new Effect.Parallel([
				new Effect.Appear( em, { sync: true } ),
				new Effect.Move(em, { sync: true, x: 74, y: 0 } ) ],
					{ duration: 0.2 } );
			*/
			
			
								
		}
	}
}

/* ================================================================================
 * UI_New_OpenSubMenuItem()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */

function UI_GoToUrl( url )
{
	window.location = url;
}

/* ================================================================================
 * UI_New_OpenSubMenuItem()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */

function UI_New_CloseSubMenuItem( menuId )
{
	em = $(menuId);
	
	if ( em )
	{
		if ( 'none' != em.style.display )
		{
			em.style.display = 'none';
			//new Effect.Fade ( em, { duration: 0.2 } );
		}
	}
}

/* ================================================================================
 * UI_RequestUrl()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */
function UI_RequestUrl( url )
{
	
	var getUrlService = '/geturl.php?url=' + url
	var loginUrl = $('loginUrl');
	
	loginUrl.value = url;
	new Ajax.Request( getUrlService, {
					 method: 'get',
					 onSuccess: function( t ) {
						 //r = new Object(t.responseText);
						 //eval ( 'r = ' + t.responseState );
						 
						 switch ( t.responseText )
						 {
							 case 'login':
							 case 'login.php':
							 case '/login.php':
							 	UI_ShowFloatingPinEntryWindow();
								break;
							
							default:
								window.location = t.responseText;
								break;
							 
						 }
						 
						 /*
						 switch (r.responseState)
						 {
							 
							 
							 
							 case 2:
							 	//$('mainPinEntryForm').show();
								UI_ShowFloatingPinEntryWindow();
								break;
							default:
						 		alert( 'Unknown response from the server.' );
						 }
						 */
					 } 
				});
}


/* ================================================================================
 * UI_ShowFloatingPinEntryWindow()
 *
 * Toggles a menu item. If it is open, it will close. If it is closed, it will open.
 */

function UI_ShowFloatingPinEntryWindow()
{
	var pinForm 		= $('mainPinEntryForm');
	var pageContainer	= $('pageContainer');
	
	//formLeft = window.scrt
	
	var scrollY = 0;
	if ( document.body )
	{
		scrollY = document.body.parentNode.scrollTop ;
	}
	else
	{
		scrollY = window.scrollY;
	}
	
	pageContainer.style.opacity = '0.4';
	pageContainer.style.filter = 'filter: alpha(opacity=40)';
	
	//filter: alpha(opacity=0);

	pinForm.style.top = (240 + scrollY) + 'px';
	pinForm.style.top = '240px';
	Effect.Appear( 'mainPinEntryForm', { duration: 0.5 } );
}


function UI_HideFloatingPinEntryWindow()
{
	
	var pinForm 		= $('mainPinEntryForm');
	var pageContainer	= $('pageContainer');
	
	pageContainer.style.opacity = '1.0';
	pageContainer.style.filter = 'filter: alpha(opacity=100)';
	Effect.Fade( pinForm, { duration: 0.5 } );
	
}

function UI_SubmitFloatingPinEntryWindow()
{
	var formContainer 	= $('mainPinEntryForm');
	var pageContainer 	= $('pageContainer');
	var pinNumber 		= $('mainPinEntryField').value;
	var submitPin		= $('loginPinNumber');
	var submitUrl		= $('loginUrl');
	var submitForm		= $('login');
	
	if ( 'none' != formContainer.style.display )
		formContainer.style.display = 'none';
	
	pageContainer.style.opacity = '1.0';
	
	submitPin.value = pinNumber;
	submitForm.submit();
}

function UI_SubmitHeaderPinEntry()
{
	var pinNumber 		= $('headerPinEntryField').value; 
	var submitPin		= $('loginPinNumber');
	var submitForm		= $('login');
	
	submitPin.value = pinNumber;
	submitForm.submit();
}


function UI_TriggerLogin()
{
	UI_ShowFloatingPinEntryWindow();
}



