/*
|---------------------------------------------------------------------------
| Lobby Nav 
|---------------------------------------------------------------------------
|
|	This script is used to highlight the active page(s) throughout the site.
|
|	The logic used in this script is created in 3 different areas.
|
|	1 - /application/libraries/PGS_Controller.php sends an array of URI segments 
|		to all views.
|	2 - /views/includes/header.php encodes URI segment array into JSON object 
|		for use in this script.
|	3 - /common/javascript/lobby-nav.js (this file) evaluates 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 <li>'s
	   that should be highlighted whenever a user is visiting that page. */
	var pages = {
		'home' 						: Array ( "home" ),
		'bingocarddetail'			: Array ( "listsession" ),
		'bingo' 					: Array ( "games", "bingo" ),
		'slots'						: Array ( "games", "slots" ),
		'poker'						: Array ( "games", "poker" ),
		'table_games'				: Array ( "games", "table-games" ),
		'keno_games'				: Array ( "games", "keno-games" ),
		'featured' 					: Array ( "promotions", "featured" ),
		'bingoschedule' 			: Array ( "promotions", "bingoschedule" ),
		'dailyevents' 				: Array ( "promotions", "dailyevents" ),
		'testimonials' 				: Array ( "community", "testimonials" ),
		'bigwinners' 				: Array ( "community", "bigwinners" ),
		'faq' 						: Array ( "help", "faq" ),
		'contactsupport'			: Array ( "help", "contactsupport" ),
		'viewtickets'				: Array ( "help", "viewtickets" ),
		'viewticketdetail'			: Array ( "help", "viewtickets" ),
		'createticketcomment'		: Array ( "help", "viewtickets" ),
		'openticket'				: Array ( "help", "openticket" ),
		
		//My Account Menu Items
		'my_profile'				: Array ( "myprofile" ),
		'deposit'					: Array ( "deposit" ),
		'withdraw'					: Array ( "withdraw" ),
		'list_session'				: Array ( "listsession" ),
		'transactions'				: Array ( "transactions" ),
		'bonus'						: Array ( "bonus" ),
		'reconcile'					: Array ( "reconcile" ),
		'deposit_history'			: Array ( "deposithistory" ),
		'withdrawal_history'		: Array ( "withdrawalhistory" ),
		'prepurchase_report' 		: Array ( "prepurchasereport" ),
		'deposit_rebate'			: Array ( "depositrebate" ),
		'close_account'				: Array ( "closeaccount" ),
		'egift'						: Array	( "egift" ),
		'bonus_exchange'			: Array ( "bonusexchange" ),
		'listactivity'				: Array ( "listsession" ),
		'loyalty_exchange'			: Array ( "loyaltyexchange" )
	};
	
	var valid_url ='';
	
	/* 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.  If the uri_array is empty, then we are on the homepage. */
	if(uri_array.length == 0)
	{
		$('li a#home').addClass("active");
	}
	else
	{
		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;
			}
		}
	}
});
