		var currentPage;
		
		
		
		/**
		 * Fades out the current page and then fades up the page passed.
		 * @param {Object} page
		 */
		function showPage(page, pageVO)
		{
			if (!page || typeof(page) == "string" ) return;
			
			if (!currentPage)
			{
				page.fadeIn(menuToggleSpeed);
			}
			else if (page != currentPage)
			{
				var pdfInstruction = $("#pdfInstructions");
				
				if (currentPage.attr("id") == "pdfPage" )
					pdfInstruction.fadeOut(menuToggleSpeed);	
				
				currentPage.fadeOut(menuToggleSpeed, function()
				{
					page.delay(250).fadeIn(menuToggleSpeed);
					
					//If the page we are showing is the gallery, set the width once visible
					if (page.attr("id") == "galleryPage") 
					{
						setTimeout(function()
						{
							setScrollerWidth();
							scroll(0);
						} , 250);
						
					}
					
					else if (page.attr("id") == "gasPage" && pageVO) 
							populatePage(pageVO);
						
					else if (page.attr("id") == "gasPage") 
								populateNewsPage();
							
					else if (page.attr("id") == "pdfPage") 
					{
						pdfInstruction.fadeIn(menuToggleSpeed);
						populatePDFPage();
					}
						
					
				})
			
			}
			
			currentPage = page;
		}
	

		
		function showPageFromURL()
		
		{
			//TODO - add dynamic url conversion so we can have deep links into the site
			switch(window.location.hash)
			{
				default : showPage( $("#homePage") ); 
					
			}
			
		}
		

		/**
		* Load up a GAS page vo to be displayed in the pages section.
		* If no VO is set, then load up the home page
		*/
		function loadPage(page)
		{
			deselectPhotographer();
			
			showNav();
			
			if (page==null)
				showPage( $("#homePage") );
			else if (page=="pdf")
				showPage( $("#pdfPage") );
			else if (page=="news")
				showPage( $("#gasPage") );
			else
				showPage( $("#gasPage"), page );
			
			
		}


		/**
		 * Poplates the pdf with gas data (if it hasnt got any)
		 */
		function populatePDFPage()
		{
			var photog2 = $(this).attr("photographerVO");
			$("#mainpdf").children().remove();
			//document.write(photog2);
			if (!$("#pdfPage").attr("populated")) 
			{
				
			//document.write(GAS.data.photographers[2]);
			

					if (GAS.imageProxy.getImagesByPhotograpaher( photog2 ).length>0)
						$("#pdfPage").append( createPDFListDiv( photog2 ) );
				
				
				$("#pdfPage").attr("populated", true);
			}
		}

		
		/**
		* Creates the news page
		*/
		function populateNewsPage( )
		{
			//Remove old page...
			$("#gasPage").children().remove();
			
			for (var i=0; i<GAS.data.pages.length; i++)
			{
				//ignore id 1 and 2
				var pageVO = GAS.data.pages[i];
				if (pageVO.id>2)
					$("#gasPage").append( createPageDiv( pageVO ) );
				
			}
			
		}
		
		/**
		* Populate the gas template with gas data
		*/
		function populatePage( pageVO )
		{
			//Remove old page...
			$("#gasPage").children().remove();
			//Add new page...
			$("#gasPage").append( createPageDiv(pageVO,false) );
			
			
		}


		/**** Gallery ****/
		function loadPhotographer()
		{
			var photog = $(this).attr("photographerVO");
			var imgs = GAS.imageProxy.getImagesByPhotograpaher( photog );
		
			$("#items").children().remove();
			
			var aPDF = createPDF(photog);
			$(aPDF).click(populatePDFPage);
			$("#mainpdf").children().remove();
			$("#mainpdf").append(createLITag(aPDF));
			
			//Add photog images
			for (var i=0; i<imgs.length; i++)
				$("#items").append( createImageTag( imgs[i], photog, i ) );
			
			//Add the photog bio at the end
			if (photog.description)
				$("#items").append( createPhotogBio( photog ) );
			
			
			
			//Add tags links - a bit special for this site, we show a list of tags for this PHOTOG only
			var uniqueTags = new Array();
			var imageIndex = new Array();
			
			for (var i=0; i<imgs.length; i++)
			{
				var tags;
				
				tags = GAS.tagsProxy.getItemTags( imgs[i] );
					
				for (var j=0; j<tags.length; j++)
				{
					if (uniqueTags.indexOf(tags[j])==-1)	
					{
						uniqueTags.push(tags[j]);
						imageIndex.push(i);
					}
				}
			}
			
				
			
			//Fake a tag for the biography
			//Add the photog bio at the end
			if (photog.description && photog.description.length>0 && photog.description!="")
			{
				uniqueTags.push( new com.zero42.galleryAdmin.model.vo.TagVO(999, "Bio") );
				imageIndex.push(i);
			}
			
			$("#gallerySubNavList").children().remove();
			
			for (var k=0; k<uniqueTags.length; k++)
			{
				var a = createTagsTag( uniqueTags[k] );
				a.imgIndex=imageIndex[k];
				//Get the first item in the images list whoes tag is this
				
				
				a.onclick=function() {  scroll($(this).attr("imgIndex"))  }
				$("#gallerySubNavList").append( a );
			
			}
				
			setScrollerWidth();
			scroll(0);
			showPage($("#galleryPage"));
		}

		function deselectPhotographer()
		{
			if (selectedItem)
			{
				deselectItem(selectedItem);
				selectedItem.attr("toggled" ,false);
				selectedItem=null;
			}
		}
		
		
		
