	/**

		 * When the GAS data has loaded, retrieve the first image from each photographer

		 * and add that to the home page, then show the home page

		 */

		function buildNavigation()

		{

			for (var i=0; i<GAS.data.photographers.length; i++)

			{

				var photog = GAS.data.photographers[i];

				

					//document.write(photog);

				var img = GAS.imageProxy.getImagesByPhotograpaher(photog);

					

					

				if (img.length>0) 

				{

				

					//Add photog to main menu.

					var aTag = createPhotogTag(photog);

					

					$(aTag).click(hideNav);

					$(aTag).click(loadPhotographer);

					

					

					//Set rollver states

					aTag.onmouseover = function(){

						//('div #homePage').fadeIn('slow');

						$('#homeGrid img.thumb').hide();

						//selectImage($("#homeGrid img[photogID=" + this.photographerVO.id + "]"));

						$('#homeGrid img[photogID='+ this.photographerVO.id + ']').fadeIn('slow');

					}

					aTag.onmouseout = function(){

						$('#homeGrid img[photogID='+ this.photographerVO.id + ']').fadeOut('slow');

						//$('div #homePage').fadeOut(100);

//						deselectImage($("#homeGrid img[photogID=" + this.photographerVO.id + "]"));

					}

					

					//Add LI tag with this a tag in it

					$("#mainnav").append(createLITag(aTag));

					

					//Add first image from photog to home page

					if (img[3]) {

						//var imgTag = createImageTag(img[0], true);

						var imgTag = createImageTag(img[0], true);

						var imgTag2 = createImageTag(img[1], true);

						var imgTag3 = createImageTag(img[2], true);

						var imgTag4 = createImageTag(img[3], true);

						

						//imgTag.onmouseover = function(){

//							selectImage($("img[photogID=" + this.imageVO.photographerID + "]"));

//							selectItem($(".nav[photogID=" + this.imageVO.photographerID + "]"));

//						};

						

					//	imgTag.onmouseout = function(){

//							deselectImage($("img[photogID=" + this.imageVO.photographerID + "]"));

//							

//							var item = $(".navSelected[photogID=" + this.imageVO.photographerID + "]");

//							

//							if (item.attr("toggled") != "true") 

//								deselectItem(item);

//						};

						

						$(imgTag).click(function(){

							$(".navSelected[photogID=" + this.imageVO.photographerID + "]").click();

						});

						

						var dave = "thumb";

						

						$(imgTag).addClass( dave );

						$(imgTag2).addClass( dave );

						$(imgTag3).addClass( dave );

						$(imgTag4).addClass( dave );

						

						//Add image tag with this tag in it

						$("#homeGrid").append(createLITag(imgTag));

						$("#homeGrid").append(createLITag(imgTag2));

						$("#homeGrid").append(createLITag(imgTag3));

						$("#homeGrid").append(createLITag(imgTag4));

						$('#homeGrid img.thumb').hide();

					}

				}

				

			}

			

			//Only add ID 1 and 2 to the menu, the rest are under news

			for (var j=GAS.data.pages.length-1; j>=0; j--)

			{

				if (GAS.data.pages[j].id < 3)

				{

					var navItem = createPageTag( GAS.data.pages[j] );

					navItem.onclick=function() { loadPage( this.pageVO ) };

					$("#mainNavListLarge").prepend(  createLITag( navItem ) );

				}

			}

			

			//set toggle state

			$(".toggle").click(navItemToggleHandler);

			

			

			//Show the header

			$("#header").fadeIn();

			

			//SHow the page

			setTimeout(showPageFromURL, 500 );

		}

		

		

	

	/**

	 * When a nav item is toggled, reset all the other iems in this list.

	 */

	function navItemToggleHandler()

	{

		//turn off selected state for items within this list and set the normal state

		$("li > a").addClass("nav");

		$("li > a").removeClass("navSelected");



		$("li > a").attr("toggled" ,false);

		

		//turn off the normal state for this item and turn on the selected state

	  	$(this).removeClass("nav");

		$(this).addClass("navSelected");

		$(this).attr("toggled" ,true);

	}

	

	/**

	 * Removes the selecte state from the A item passed in

	 * @param {Object} item The A html item to deselect

	 */

	function deselectItem(item)

	{

		if (item)

		{

			item.addClass("nav");

			item.removeClass("navSelected");

		}

	}

	

	

	/**

	 * Adds the selected state to the A itempassed in 

	 * @param {Object} item  The A html item to select

	 */

	function selectItem(item)

	{

		item.removeClass("nav");

		item.addClass("navSelected");

	}

	

	

	

	

	function selectImage(img)

	{

		$("#homeGrid img").not(img).stop(true).fadeTo('fast',0.2);

	}

	

	function deselectImage(img)

	{

		$("#homeGrid img").stop(true).fadeTo('fast',1);

	}

	

	/** 

	 * Slides the nav bar up and fades out certain elements

	 */

	function hideNav()

	{

		selectedItem = $(this);

		$("#homePage").hide();

		

		$('#headerContent').animate({height: 50}, menuToggleSpeed);

		

		$('#mainnav > li').fadeOut(menuToggleSpeed);

		

		$('#mainNavListLarge').fadeOut( menuToggleSpeed, function() 

		{  

			$("#mainNavListSmall, #gallerySubNavList ").fadeIn(menuToggleSpeed);

			selectedItem.parent().fadeIn(menuToggleSpeed);	

		} );

	}

	

	/** 

	 * Slides the nav bar down and fades up certain elements

	 */

	function showNav()

	{

		$('#headerContent').animate({height: 140}, menuToggleSpeed);

		

		if (selectedItem)

			selectedItem.parent().fadeOut(menuToggleSpeed);

		

		var count=0;

		$('#mainNavListSmall, #gallerySubNavList').fadeOut( menuToggleSpeed, function()

			{ 

				//This fires for each item we fade, so only run it once.

				if (count++ == 1)

					$("#mainNavListLarge, #mainnav > li").fadeIn(menuToggleSpeed); 

			} );

			

	}


