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

using System;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for SidePortal.
	/// </summary>
	public class HighlightPicture : RandomPicture //: GalleryImage
	{

		#region Public Properties

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

            // Use a different prefix for the img id attribute than the default "SmallThumb" so there won't
            //  be duplicate id's if a PictureListing control containing the random image is on the same page.
            imageIDprefix = "HighlightPicture";
		}

		protected override void LoadPicture()
		{
			if((SectionID == -1) && (ApplicationKey != ""))
				SectionID = Galleries.GetGalleryID( ApplicationKey );
			else if(SectionID == -1)
			{
				Gallery gallery = Galleries.GetRandomGallery();
				if(gallery == null)
					return;
				SectionID = gallery.SectionID;
			}

			GalleryPostCategory category = GalleryPostCategory.Parse(PostCategories.GetCategory(CategoryID, SectionID)); 

			if(category.HasFeaturedPhoto)
				GalleryPost = (GalleryPost)category.FeaturedPost;
			else 
				GalleryPost = GalleryPosts.GetFirstPicture(SectionID, CategoryID);


			if(this.UseLink && this.LinkToPicture && ApplicationKey != "" && GalleryPost != null)
				base.NavigateUrl = GalleryUrls.Instance().ViewPicture(ApplicationKey,CategoryID, GalleryPost); 
			if(this.UseLink && this.LinkToCategory && ApplicationKey != "")
				base.NavigateUrl = GalleryUrls.Instance().ViewCategory(ApplicationKey, CategoryID) ; 
		}

	}
}
