//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for SidePortal.
	/// </summary>
	public class RandomGallery : GalleryBaseTemplatedWebControl
	{

		#region Child Controls

		private HyperLink nameLink;

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			nameLink = (HyperLink)FindControl( "NameLink" );
		}

		#endregion

		#region Event Overrides

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			if(!Page.IsPostBack)
				DataBind();
		}

		public override void DataBind()
		{
			base.DataBind();
			BindData();
		}

		#endregion

		private void BindData()
		{
			Gallery gallery = Galleries.GetRandomGallery();
			if(gallery != null)
			{
				nameLink.NavigateUrl = GalleryUrls.Instance().ViewGallery( gallery.ApplicationKey );
				nameLink.Text = gallery.Name;
			}
		}


	}
}
