/*
|---------------------------------------------------------------------------
| Lobby Nav 
|---------------------------------------------------------------------------
|
|	This script is used to highlight the active page(s) throughout the site.
|
|	The logic used by $(document).ready() is created in 3 different areas.
|
|	1 - /core/PGS_Controller.php sends an array of URI segments 
|		to all views.
|	2 - /views/includes/header.php encodes the URI segment array into a JSON 
|		object for use in this script.
|	3 - /common/javascript/lobby-nav.js (this file) evaluates the segment array 
|		and highlights approriate navigation items.
*/

$(document).ready(function()
{
	/* Object containing a property for each page that a user can visit on the site.
	   Each property contains an array of id's. These id's correspond to the elements
	   that should be highlighted whenever a user is visiting that page. */
	var pages = 
	{
		'slots' 					: Array ( 'slots-btn' ),
		'poker'						: Array ( 'poker-btn' ),
		'table_games'				: Array ( 'table-btn' ),
		'keno_games'				: Array ( 'keno-btn' ),
		'sheriff'					: Array ( 'threed-btn' )
	};
	
	/* Search through the given uri_array for a URI segment that exists in the
	   pages object. The first valid entry that is found is stored and then we break
	   out of the loop.*/
	for( var i = 0; i < uri_array.length; i++ )
	{
		if (typeof pages[uri_array[i]] != 'undefined' )
		{
			/* Iterate over all array indexes stored under the selected pages property.
			   Each index in the array is given the 'active' class name to highlight it. */
			for( var j = 0; j < pages[uri_array[i]].length; j++ )
			{
				$('li a#' + pages[uri_array[i]][j]).addClass("active");
			}
			
			break;
		}
	}
});

/*
|---------------------------------------------------------------------------
| AJAX Nav 
|---------------------------------------------------------------------------
|
|	This function is used to highlight the active page(s) in AJAX popups.
|
|	The logic used by ajax_update() is created in 3 different areas.
|
|	1 - /controllers/ajax/page_name where page_name is any given ajax controller
|		will send the active page to the view it loads.
|	2 - /views/ajax/page_name where page_name is any given ajax view will call
|		ajax_update() and pass it the current page name.
|	3 - /common/javascript/lobby-nav.js (this file) highlights the active <li>'s
*/

function ajax_nav_update(url)
{
	//Un-highlight everything
	$('#my-account-menu li').removeClass('active');
	$('#my-account-menu li a').removeClass('active');
	
	$('#my-account-menu li').removeClass('hover');
	$('#my-account-menu li a').removeClass('hover');
	
	var segments = url.split('/');
	
	/* Object containing a property for each page that a user can visit on the site.
	   Each property contains an array of id's. These id's correspond to the elements
	   that should be highlighted whenever a user is visiting that page. */
	var pages = 
	{
		'deposit'					: Array ('deposit-btn', 'deposit'),
		'withdraw'					: Array ('deposit-btn', 'withdraw'),
		
		'my_profile'				: Array ( 'my-account-btn', 'my-profile' ),
		'update_my_profile'			: Array ( 'my-account-btn', 'my-profile' ),
		'egift'						: Array ( 'my-account-btn', 'egift' ),
		'bonus_exchange'			: Array ( 'my-account-btn', 'bonus-exchange' ),
		'deposit_rebate'			: Array ( 'my-account-btn', 'deposit-rebate' ),
		'close_account'				: Array ( 'my-account-btn', 'close-account' ),
		
		'list_session'				: Array ( 'reports-btn', 'list-session' ),
		'list_activity'				: Array ( 'reports-btn', 'list-session' ),
		'transactions'				: Array ( 'reports-btn', 'transactions' ),
		'bonus'						: Array ( 'reports-btn', 'bonus' ),
		'reconcile'					: Array ( 'reports-btn', 'reconcile' ),
		'deposit_history'			: Array ( 'reports-btn', 'deposit-history' ),
		'deposit_detail_report'		: Array ( 'reports-btn', 'deposit-history'),
		'withdrawal_history'		: Array ( 'reports-btn', 'withdrawal-history' ),
		'withdrawal_detail_report'	: Array ( 'reports-btn', 'withdrawal-history'),
		
		'faq' 						: Array ( 'help-btn', 'faq' ),
		'view_tickets'				: Array ( 'help-btn', 'view-tickets' ),
		'view_ticket_detail'		: Array ( 'help-btn', 'view-tickets' ),
		'create_ticket_comment'		: Array ( 'help-btn', 'view-tickets' ),
		'open_ticket'				: Array ( 'help-btn', 'open-ticket' )
	};

	/* Search through the given uri_array for a URI segment that exists in the
	   pages object. The first valid entry that is found is stored and then we break
	   out of the loop.*/
	for( var i = 0; i < segments.length; i++ )
	{
		if (typeof pages[segments[i]] != 'undefined' )
		{
			/* Iterate over all array indexes stored under the selected pages property.
			   Each index in the array is given the 'active' class name to highlight it. */
			for( var j = 0; j < pages[segments[i]].length; j++ )
			{
				$('li a.' + pages[segments[i]][j]).addClass("active");
			}
			
			break;
		}
	}
	
	//Hide all sub-menus
	$('#my-account-menu li ul').hide();
	
	//Highlight the active button's containing <li>
	$('#my-account-menu li a.active').parent().addClass('active');
	
	//Show only the active sub-menu
	$('#my-account-menu li.active ul').show();
}
