/**
 * @author roger
 */

 $(function() {
 	// Menu Items
	 var menuCategories = [ ['Center for Economic Development Education', 'http://www.iea.ualr.edu/econdev/default.php' ],
							['Census State Data Center', 'http://www.iea.ualr.edu/census/default.php',null,'width:126px;'],
							['Workforce Issues', 'http://www.iea.ualr.edu/lep/default.php',null,'width:146px;'],
							['News &amp; Events', 'http://www.iea.ualr.edu/news'],
							['Research Group', 'http://www.iea.ualr.edu/research/default.php',null,'width:110px;'],
							['Research Library', 'http://www.iea.ualr.edu/library/default.php',null,'width:110px;'] ];

	var menuItems = [];
	// ['Center for Economic Development Education', 'http://www.iea.ualr.edu/econdev/default.html' ]
	menuItems[0] = null;
	
	// ['Census State Data Center', 'http://www.iea.ualr.edu/census/default.html']
	menuItems[1] = [ ['Census State Data Center', 'http://www.iea.ualr.edu/census/default.php'],
					  ['Children\'s Research', 'http://www.iea.ualr.edu/census/crc/default.php'],
					  ['GIS Applications Lab', 'http://argis.ualr.edu/frontpage.htm'] ];
					  
	// ['Labor Education Program', 'http://www.iea.ualr.edu/lep/default.html']
	menuItems[2] = [ ['Labor Education Program', 'http://www.iea.ualr.edu/lep/default.php'],
					  ['Workforce Group','http://www.iea.ualr.edu/lep/wsep/default.php'] ];
	
	// ['Management Education &amp; Development Program', 'http://www.iea.ualr.edu/medp/default.html']
	menuItems[3] = null;
	
	// ['Research Group', 'http://www.iea.ualr.edu/research/default.html']
	menuItems[4] = [ ['Economic Research &amp; Forcasting', 'http://www.iea.ualr.edu/research/economic/default.php'],
					  ['Survey Research', 'http://www.aiea.ualr.edu/research/survey/default.php', [	
					  						['Survey/Business Research Home', 'http://www.iea.ualr.edu/research/survey/default.php'],
											['Survey/Business Research Brochure (PDF)','http://www.iea.ualr.edu/research/pdf/surveyBusResearch.pdf'],
											['Decision Support Center Brochure (PDF)','http://www.iea.ualr.edu/research/pdf/decisionBrochure.pdf']] ],
					  ['Demographic Research', 'http://www.iea.ualr.edu/research/demographic/default.php'],
					  ['Development Information Network of Arkansas', 'http://www.dina.org/'],
					   ['We Know Arkansas', 'http://www.weknowarkansas.org/'],
					  ['EDA University Center', 'http://www.iea.ualr.edu/research/edauniversity.php'] ];
	
	// ['Research Library', 'http://www.iea.ualr.edu/library/default.html']
	menuItems[5] = [ ['Publications', 'http://www.iea.ualr.edu/library/publications.php'],
					  ['Periodicals', 'http://www.iea.ualr.edu/library/periodicals.php'] ];

	// Checks whether the given object is an Array or not
	function isArray(obj) {
		if (obj == null)
			return false;
		if (obj.constructor.toString().indexOf("Array") == -1)
			return false;
		else
			return true;
	}

	// Turns an array of items into a nested list
	function exportMenu(categories, items)
	{
		var html = "<ul class='sf-menu'>\r";
		
		// Go through the categories array and turn them into a list
		for (var x = 0; x < categories.length; x++)
		{
			// Create the next entry in the list and attach any custom styles there maybe
			html = html + "	<li " + (categories[x][3] != null ? "style='" + categories[x][3] + "'" : "")+ "><div><a href='" + categories[x][1] + "'>" + categories[x][0] + "</a></div>";

			// Check to see if there's any items attached to the menu
			if (isArray(items[x]) == true)
			{
				html = html + "<ul class='sf-menu sf-js-enabled sf-shadow'>\r";
				for (var y = 0 ; y < items[x].length ; y++)
				{
					html = html + "<li>\r";
					html = html + "<div><a href='" + items[x][y][1] + "'>" + items[x][y][0] + "</a></div>";
					
					// Check if there's any submenus, if so call itself
					if (items[x][y].length == 3) {
						if (isArray(items[x][y][2]))
							html = html + exportMenu(items[x][y][2], []);
					}
					
					html = html + "</li>\r";
				}
				html = html + "</ul>";
			}
			html = html + "</li>";
		}
		
		html = html + "</ul>";
		
		return html;
	}

	// Select the menu and put the html inside
	$("div#body_menu > div#body > div#left > *").html(exportMenu(menuCategories,menuItems));
	// Attach the javascript menu to the html
	$("ul.sf-menu").superfish({
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show'},  			  // fade-in
            speed:       'slow',                          // faster animation speed 
            dropShadows: false
	}); 
	
 });
