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

using System;
using System.IO;
using CommunityServer.Components;
using CommunityServer.Configuration;

namespace CommunityServer.Galleries.Components
{
	/// <summary>
	/// Summary description for GalleryUrls.
	/// </summary>
	public class GalleryUrls : ApplicationUrls
	{

		public static readonly string GalleryUrlsProviderName = "GalleryUrlsProvider";

		public GalleryUrls() { }

		#region Instance

		private static GalleryUrls _defaultInstance = null;

		static GalleryUrls()
		{
			CreateDefaultCommonProvider();
		}

		/// <summary>
		/// Returns an instance of the user-specified data provider class.
		/// </summary>
		/// <returns>An instance of the user-specified data provider class.  This class must inherit the
		/// CommonDataProvider interface.</returns>
		public static GalleryUrls Instance() 
		{
			return _defaultInstance;
		}

		public static GalleryUrls Instance (Provider dataProvider) 
		{
			GalleryUrls fdp = CSCache.Get(dataProvider.Name) as GalleryUrls;
			if(fdp == null)
			{
				fdp = DataProviders.Invoke(dataProvider) as GalleryUrls;
				CSCache.Max(dataProvider.Name,fdp);
			}
			return fdp;
		}

		/// <summary>
		/// Creates the Default CommonDataProvider
		/// </summary>
		private static void CreateDefaultCommonProvider()
		{
			// Read the configuration specific information
			// for this provider
			//
			Provider urlProvider = (Provider) CSConfiguration.GetConfig().Providers[GalleryUrlsProviderName];

			// Create the instance for the provider, or fall back on the builtin one
			//
			if(urlProvider != null)
				_defaultInstance = CreateInstance(urlProvider) as GalleryUrls;
			else
				_defaultInstance = new GalleryUrls();
		}
        
		#endregion

		#region Gallery Urls

		#region Public Urls

		public virtual string Home
		{
			get { return FormatUrl("galleryhome"); }
		}

		public virtual string GalleryListing
		{
			get { return FormatUrl("gallerylisting"); }
		}

		public virtual string Rss(RssType type, string applicationKey)
		{
			return Rss(type, applicationKey, -1);
		}

		public virtual string Rss(RssType type, string applicationKey, int categoryID)
		{
			switch(type)
			{
				case RssType.Categories:
					return FormatUrl("gallery_RssCategory", applicationKey);
				case RssType.Pictures:
					if(categoryID == -1)
						return FormatUrl("gallery_RssGalleryPictures", applicationKey);
					else
						return FormatUrl("gallery_RssCategoryPictures", applicationKey, categoryID);
				default:
					return "";
			}
		}

		public virtual string Rss(string applicationKey, string[] tagNames)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			foreach (string tag in tagNames)
			{
				if (sb.Length > 0)
					sb.Append("/");

				sb.Append(Globals.UrlEncodePathComponent(tag));
			}
			return FormatUrl("gallery_TagsRss", applicationKey, sb.ToString() );
		}
		
		public virtual string Rss(string applicationKey, string[] tagNames, bool andTags)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			foreach (string tag in tagNames)
			{
				if (sb.Length > 0)
					sb.Append("/");

				sb.Append(Globals.UrlEncodePathComponent(tag));
			}
			return FormatUrl("gallery_TagsRssAnd", applicationKey, sb.ToString(), Convert.ToInt32(andTags) );
		}


		public virtual string ViewGallery(string applicationKey)
		{
			return FormatUrl("gallery_ViewGallery", applicationKey);
		}

		public virtual string ViewCategory(string applicationKey, int categoryID)
		{
			return FormatUrl("gallery_ViewCategory", applicationKey, categoryID);
		}

		public virtual string TagsHome(string applicationKey)
		{
			return FormatUrl("gallery_AllTags", applicationKey);
		}

		public virtual string TagsBrowser(string applicationKey, string[] tagNames)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			foreach (string tag in tagNames)
			{
				if (sb.Length > 0)
					sb.Append("/");

				sb.Append(Globals.UrlEncodePathComponent(tag));
			}

			return FormatUrl("gallery_ViewTags", applicationKey, sb.ToString());
		}

		public virtual string ViewWatermark(string applicationKey)
		{
			return FormatUrl("gallery_Watermark", applicationKey);
		}

		public virtual string ViewTempAttachment(string applicationKey, Guid guid)
		{
			return FormatUrl("gallery_Picture_TempAttachement", applicationKey, guid);
		}


		public virtual string ViewPicture(string applicationKey, GalleryPost galleryPost)
		{
			if(galleryPost.HasName)
				return FormatUrl("gallery_ViewPicture_Gallery_FriendlyName", applicationKey, Globals.UrlEncodeFileComponent(galleryPost.Name));
			else
				return FormatUrl("gallery_ViewPicture_Gallery", applicationKey, galleryPost.PostID);
		}

		public virtual string ViewPicture(string applicationKey, int categoryID, GalleryPost galleryPost)
		{
			if(categoryID == -1)
				return ViewPicture(applicationKey, galleryPost);
			else if(galleryPost.HasName)
				return FormatUrl("gallery_ViewPicture_Category_FriendlyName", applicationKey, categoryID, Globals.UrlEncodeFileComponent(galleryPost.Name));
			else
				return FormatUrl("gallery_ViewPicture_Category", applicationKey, categoryID, galleryPost.PostID);
		}

		#region Picture URLS

		public virtual string ThumbnailURL(GalleryPost post)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetThumbnailFileName(post)));

			if(post.HasName)
				return ThumbnailURL(post.Section.ApplicationKey, post.Name);
			else
				return ThumbnailURL(post.Section.ApplicationKey, post.PostID);
			
		}
		public virtual string SecondaryThumbnailURL(GalleryPost post)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetSecondaryThumbnailFileName(post) ) );

			if(post.HasName)
				return SecondaryThumbnailURL(post.Section.ApplicationKey, post.Name);
			else
				return SecondaryThumbnailURL(post.Section.ApplicationKey, post.PostID);
		}
		public virtual string ThumbnailURL(string applicationKey, int PostID)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(PostID);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetThumbnailFileName(post) ) );
			}

			return FormatUrl("gallery_PictureUrlType", applicationKey, PostID, "thumb");
		}

		public virtual string SecondaryThumbnailURL(string applicationKey, int PostID)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(PostID);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetSecondaryThumbnailFileName(post) ) );
			}

			return FormatUrl("gallery_PictureUrlType", applicationKey, PostID, "secondarythumb");
		}
		
		public virtual string ThumbnailURL(string applicationKey, string postName)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(postName);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetThumbnailFileName(post) ) );
			}

			return FormatUrl("gallery_PictureUrlType_FriendlyName", applicationKey, "thumb", Globals.UrlEncodeFileComponent(postName));
		}

		public virtual string SecondaryThumbnailURL(string applicationKey, string postName)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(postName);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetSecondaryThumbnailFileName(post) ) );
			}

			return FormatUrl("gallery_PictureUrlType_FriendlyName", applicationKey, "secondarythumb", Globals.UrlEncodeFileComponent(postName));
		}

		/// <summary>
		/// Gets the URL for the original version of the picture
		/// </summary>
		public virtual string PictureUrl(GalleryPost galleryPost)
		{
			GalleryAttachmentSettings fs = GalleryConfiguration.Instance().AttachmentSettings;
			if(fs.EnableDirectLinks)
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetFileName(galleryPost)) );

			return PictureUrl(galleryPost, GalleryImageType.Original, galleryPost.Attachment.Width, galleryPost.Attachment.Height);
		}

		public virtual string PictureUrl(GalleryPost galleryPost, GalleryImageType imageType, int Width, int Height)
		{
			if(!galleryPost.HasName)
				return PictureUrl(galleryPost.Section.ApplicationKey, galleryPost.PostID, imageType, Width, Height);
			else
			{
				switch(imageType)
				{
					case GalleryImageType.Micro:
					case GalleryImageType.Thumbnail:
						return ThumbnailURL(galleryPost.Section.ApplicationKey, galleryPost.Name);
					case GalleryImageType.Gallery:
					case GalleryImageType.SecondaryThumbnail:
						return SecondaryThumbnailURL(galleryPost.Section.ApplicationKey, galleryPost.Name);
					case GalleryImageType.Slideshow:
					case GalleryImageType.Details:
					case GalleryImageType.Other:
						return PictureUrl(galleryPost.Section.ApplicationKey, galleryPost.PostID, Width, Height);

					case GalleryImageType.Original:
					default:
						return PictureUrl(galleryPost.Section.ApplicationKey, galleryPost.Name);
				}
			}
		}

		/// <summary>
		/// Gets the URL for the original version of the picture based on a named image
		/// </summary>
		public virtual string PictureUrl(string applicationKey, string name)
		{
			GalleryAttachmentSettings fs = GalleryConfiguration.Instance().AttachmentSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(name);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetFileName(post)) );
			}

			return  FormatUrl("gallery_PictureUrlType_FriendlyName", applicationKey, "original", Globals.UrlEncodeFileComponent(name) );
		}
		
		public virtual string PictureUrl(string applicationKey, int pictureID, GalleryImageType imageType, int Width, int Height)
		{
			switch(imageType)
			{
				case GalleryImageType.Micro:
				case GalleryImageType.Thumbnail:
					return ThumbnailURL(applicationKey,pictureID);
				case GalleryImageType.Gallery:
				case GalleryImageType.SecondaryThumbnail:
					return SecondaryThumbnailURL(applicationKey,pictureID);
				case GalleryImageType.Slideshow:
				case GalleryImageType.Details:
				case GalleryImageType.Other:
					return PictureUrl(applicationKey, pictureID, Width , Height);
				case GalleryImageType.Original:
				default:
					return PictureUrl(applicationKey, pictureID);
			}
		}

		/// <summary>
		/// Gets the URL for the original version of the picture based on a PostID
		/// </summary>
		public virtual string PictureUrl(string applicationKey, int pictureID)
		{
			GalleryAttachmentSettings fs = GalleryConfiguration.Instance().AttachmentSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(pictureID);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetFileName(post)) );
			}

			return FormatUrl("gallery_PictureUrlType", applicationKey, pictureID, "original");
		}

		/// <summary>
		/// Gets the URL for the scaled version of the picture based on a PostID, Width and Height
		/// </summary>
		public virtual string PictureUrl(string applicationKey, int pictureID, int width, int height)
		{
			GalleryCacheSettings fs = GalleryConfiguration.Instance().CacheSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(pictureID);
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath, fs.GetFileName(post, width, height)) );
			}
			return FormatUrl("gallery_PictureUrlScale", applicationKey, pictureID, width, height);
		}

		#endregion

		public virtual string DefaultHighlightImage
		{
			get
			{
				string path = GalleryUrls.Instance().Home;
				path = path.Substring(0, path.LastIndexOf("/"));
				return path + "/default_highlight_image.gif";
			}
		}

		#region POST For RSS Writer
		public virtual string ViewPicture(string applicationKey, int categoryID, int postID)
		{
			return FormatUrl("gallery_ViewPicture_Category", applicationKey, categoryID, postID);
		}
		public virtual string ViewPicture(string applicationKey, int postID)
		{
				return FormatUrl("gallery_ViewPicture_Gallery", applicationKey, postID);
		}
		#endregion		

		public virtual string ViewExif(string applicationKey, GalleryPost galleryPost)
		{
				return FormatUrl("gallery_ViewExif_Gallery", applicationKey, galleryPost.PostID);
		}

		public virtual string ViewExif(string applicationKey, int categoryID, GalleryPost galleryPost)
		{
			if(categoryID == -1)
				return ViewExif(applicationKey, galleryPost);
			else 
				return FormatUrl("gallery_ViewExif_Category", applicationKey, categoryID, galleryPost.PostID);
		}

		public virtual string ViewOrderPrints(string applicationKey, int pictureID, int width, int height, int thumbWidth, int thumbHeight)
		{
			return FormatUrl("gallery_ViewOrderPrints", applicationKey, pictureID) + "?Width=" + width + "&Height=" + height + "&TWidth=" + thumbWidth + "&THeight=" + thumbHeight;
		}

		#region Slideshow

		public virtual string ViewSlideshow(string applicationKey)
		{
			return FormatUrl("gallery_ViewSlideshow_Gallery", applicationKey);
		}

		public virtual string ViewSlideshow(string applicationKey, int categoryID)
		{
			if(categoryID == -1)
				return ViewSlideshow(applicationKey);
			else
				return FormatUrl("gallery_ViewSlideshow_Category", applicationKey, categoryID);
		}

		public virtual string ViewSlideshowPro()
		{
			return FormatUrl("gallery_ViewSlideshowPro").Replace("{0}/","") ;
		}

		public virtual string ViewSlideshowPro(string applicationKey)
		{
			return FormatUrl("gallery_ViewSlideshowPro_Gallery", applicationKey);
		}

		public virtual string ViewSlideshowPro(string applicationKey, int categoryID)
		{
			if(categoryID == -1)
				return ViewSlideshowPro(applicationKey);
			else
				return FormatUrl("gallery_ViewSlideshowPro_Category", applicationKey, categoryID);
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the standard slideshow image size for main images
		/// </summary>
		public virtual string SlideshowPictures()
		{
			return FormatUrl("gallery_SlideShowPictures");
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the standard slideshow image size for main images
		/// </summary>
		public virtual string SlideshowPictures(string applicationKey)
		{
			return FormatUrl("gallery_SlideShowGalleryPictures", applicationKey);
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the standard slideshow image size for main images
		/// </summary>
		public virtual string SlideshowPictures(string applicationKey, int categoryID)
		{
			if(categoryID == -1)
				return SlideshowPictures(applicationKey);
			else
				return FormatUrl("gallery_SlideShowCategoryPictures", applicationKey, categoryID);
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the specified image size for main images
		/// </summary>
		public virtual string SlideshowPictures(int width, int height)
		{
			return FormatUrl("gallery_SlideShowPicturesScale", width, height);
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the specified image size for main images
		/// </summary>
		public virtual string SlideshowPictures(string applicationKey, int width, int height)
		{
			return FormatUrl("gallery_SlideShowGalleryPicturesScale", applicationKey, width, height);
		}

		/// <summary>
		/// The XML feed for the slideshow
		/// Uses the specified image size for main images
		/// </summary>
		public virtual string SlideshowPictures(string applicationKey, int categoryID, int width, int height)
		{
			if(categoryID == -1)
				return SlideshowPictures(applicationKey, width, height);
			else
				return FormatUrl("gallery_SlideShowCategoryPicturesScale", applicationKey, categoryID, width, height);
		}

		#endregion

		public virtual string Search(string query)
		{
			return FormatUrl("gallery_Search", query);
		}

		public virtual string CustomCSS(string applicationkey)
		{
			return FormatUrl("gallery_CustomCSS", applicationkey);
		}

		public virtual string CommentRss(string applicationKey, int PostID)
		{
			return FormatUrl("gallery_CommentRss", applicationKey,PostID);
		}

		public virtual string RssComments(string applicationKey, int PostID)
		{
			return FormatUrl("gallery_RssComments", applicationKey, PostID);
		}

		public virtual string ContactForm(string applicationKey)
		{
			throw new NotImplementedException("This option is not yet available in the gallery!"); 
		}
		
		public virtual string About(string applicationKey)
		{
			return FormatUrl("gallery_ViewAbout", applicationKey);
		}

		public virtual string EmailSubscriptions(string applicationkey)
		{
			return FormatUrl("gallery_ViewEmailSubscription",applicationkey);
		}
		
		#endregion

		#region Admin Urls

		public virtual string Admin_MyGalleries
		{
			get { return FormatUrl("gallery_Admin_MyGalleries"); }
		}

		public virtual string Admin_AdminGallery(string applicationKey)
		{
			return FormatUrl("gallery_Admin_AdminGallery", applicationKey);
		}

		public virtual string Admin_AdminGallery_ReturnUrl(string applicationKey, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminGallery_ReturnUrl", applicationKey, url, args);
		}

		public virtual string Admin_AdminGallery(int sectionID)
		{
			return FormatUrl("gallery_Admin_AdminGallery2", sectionID);
		}

		public virtual string Admin_AdminGallery_ReturnUrl(int sectionID, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminGallery2_ReturnUrl", sectionID, url, args);
		}

		public virtual string Admin_ManageCategories(string applicationKey)
		{
			return FormatUrl("gallery_Admin_ManageCategories", applicationKey);
		}

		public virtual string Admin_AdminCategory(string applicationKey, int categoryID)
		{
			return FormatUrl("gallery_Admin_AdminCategory", applicationKey, categoryID);
		}

		public virtual string Admin_AdminCategory_ReturnUrl(string applicationKey, int categoryID, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminCategory_ReturnUrl", applicationKey, categoryID, url, args);
		}

		public virtual string Admin_ManagePictures(string applicationKey, int categoryID)
		{
			return FormatUrl("gallery_Admin_ManagePictures", applicationKey, categoryID);
		}

		public virtual string Admin_ManagePictures(string applicationKey, int categoryID, int highlightID)
		{
			return FormatUrl("gallery_Admin_ManagePicturesSuccess", applicationKey, categoryID, highlightID);
		}

		public virtual string Admin_AdminPicture(string applicationKey, int categoryID, int pictureID)
		{
			return FormatUrl("gallery_Admin_AdminPicture", applicationKey, categoryID, pictureID);
		}

		public virtual string Admin_AdminPicture_ReturnUrl(string applicationKey, int categoryID, int pictureID, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminPicture_ReturnUrl", applicationKey, categoryID, pictureID, url, args);
		}

		#endregion

		#region ConrolPanel Urls

		public virtual string ControlPanel_Photos
		{
			get { return FormatUrl("gallery_ControlPanel_Photos"); }
		}
		
		public virtual string ControlPanel_Photos_Gallery(int sectionID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_Gallery", sectionID); 
		}

		public virtual string ControlPanel_Photos_Category(int sectionID, int categoryID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_Category", sectionID, categoryID); 
		}
	
		public virtual string ControlPanel_Photos_NewPost()
		{
			return FormatUrl("gallery_ControlPanel_Photos_NewPost"); 
		}

		public virtual string ControlPanel_Photos_NewPost(int sectionID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_NewPost_Gallery", sectionID); 
		}

		public virtual string ControlPanel_Photos_NewPost(int sectionID, int categoryID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_NewPost_Category", sectionID, categoryID); 
		}

		public virtual string ControlPanel_Photos_NewPost(string returnUrl)
		{
			return FormatUrl("gallery_ControlPanel_Photos_NewPost_ReturnURL", returnUrl);
		}

        public virtual string ControlPanel_Photos_NewPost(int sectionID, string returnUrl)
        {
            return FormatUrl("gallery_ControlPanel_Photos_NewPost_Gallery_ReturnURL", sectionID, returnUrl);
        }
        public virtual string ControlPanel_Photos_NewPostModal(int sectionID, string returnUrl)
        {
            return FormatUrl("gallery_ControlPanel_Photos_NewPostModal_Gallery_ReturnURL", sectionID, returnUrl);
        }

		public virtual string ControlPanel_Photos_NewPost(int sectionID, int categoryID, string returnUrl)
		{
			return FormatUrl("gallery_ControlPanel_Photos_NewPost_Category_ReturnURL", sectionID, categoryID, returnUrl); 
		}

		public virtual string ControlPanel_Photos_EditPost(int postID, string returnUrl)
		{
			return FormatUrl("gallery_ControlPanel_Photos_EditPost_ReturnURL", postID, returnUrl);
		}

		public virtual string ControlPanel_Photos_EditPost(int sectionID, int postID, string returnUrl)
		{
			return FormatUrl("gallery_ControlPanel_Photos_EditPost_Gallery_ReturnURL", sectionID, postID, returnUrl); 
		}

		public virtual string ControlPanel_Photos_EditPost(int sectionID, int categoryID, int postID, string returnUrl)
		{
			return FormatUrl("gallery_ControlPanel_Photos_EditPost_Category_ReturnURL", sectionID, categoryID, postID, returnUrl); 
		}

		public virtual string ControlPanel_Photos_PostList
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_PostList"); }
		}

		public virtual string ControlPanel_Photos_CategoryList
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_CategoryList"); }
		}

		public virtual string ControlPanel_Photos_CategoryList_Gallery(int sectionID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryList_Gallery", sectionID); 
		}

		public virtual string ControlPanel_Photos_CategoryList_Category(int sectionID, int categoryID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryList_Category", sectionID, categoryID); 
		}
		
		public virtual string ControlPanel_Photos_CategoryManager
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_CategoryManager"); }
		}
		public virtual string ControlPanel_Photos_CategoryManager_Gallery(int sectionID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryManager_Gallery", sectionID); 
		}
		public virtual string ControlPanel_Photos_CategoryManager_Category(int sectionID, int categoryID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryManager_Category", sectionID, categoryID);
		}

		public virtual string ControlPanel_Photos_CategoryForm(int sectionID, int categoryID, int parentID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryForm", sectionID, categoryID);
		}
		public virtual string ControlPanel_Photos_CategoryForm_New(int sectionID, int categoryID, int parentID)
		{
			return FormatUrl("gallery_ControlPanel_Photos_CategoryForm_New", sectionID, categoryID, parentID);
		}
		public virtual string ControlPanel_Photos_CommentList
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_CommentList"); }
		}
		
		public virtual string ControlPanel_Photos_Options
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_Options"); }
		}
		
		public virtual string ControlPanel_Photos_Switch
		{
			get { return FormatUrl("gallery_ControlPanel_Photos_Switch"); }
		}
		
		public virtual string ControlPanel_Photos_Switch_ReturnUrl(string url)
		{
			return FormatUrl("gallery_ControlPanel_Photos_Switch", url);
		}
	
		public virtual string ControlPanel_PhotosAdmin
		{
			get { return FormatUrl("gallery_ControlPanel_PhotosAdmin"); }
		}
		
		public virtual string ControlPanel_PhotosAdmin_GroupList
		{
			get { return FormatUrl("gallery_ControlPanel_PhotosAdmin_GroupList"); }
		}
		
		public virtual string ControlPanel_PhotosAdmin_GalleryList
		{
			get { return FormatUrl("gallery_ControlPanel_PhotosAdmin_GalleryList"); }
		}
		
		public virtual string ControlPanel_PhotosAdmin_DefatulPermissionList
		{
			get { return FormatUrl("gallery_ControlPanel_PhotosAdmin_DefatulPermissionList"); }
		}

		public virtual string ControlPanel_PhotosAdmin_Options
		{
			get { return FormatUrl("gallery_ControlPanel_PhotosAdmin_Options"); }
		}

		#endregion

		#region System Admin Urls

		public virtual string Admin_ManageGalleries
		{
			get { return FormatUrl("gallery_Admin_ManageGalleries"); }
		}

		public virtual string Admin_GroupAdmin(int groupID)
		{
			return FormatUrl("gallery_Admin_GroupAdmin", groupID);
		}

		public virtual string Admin_ManagePermissions
		{
			get {  return FormatUrl("gallery_Admin_ManagePermissions"); }
		}

		public virtual string Admin_AdminPermission(int galleryID, Guid roleID)
		{
			return FormatUrl("gallery_Admin_AdminPermission", galleryID, roleID);
		}

		public virtual string Admin_AdminPermission_ReturnUrl(int galleryID, Guid roleID, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminPermission_ReturnUrl", galleryID, roleID, url, args);
		}

		public virtual string Admin_ManageDefaultPermissions
		{
			get {  return FormatUrl("gallery_Admin_ManageDefaultPermissions"); }
		}

		public virtual string Admin_AdminDefaultPermission(Guid roleID)
		{
			return FormatUrl("gallery_Admin_AdminDefaultPermission", roleID);
		}

		public virtual string Admin_AdminDefaultPermission_ReturnUrl(Guid roleID, string url, string args)
		{
			return FormatUrl("gallery_Admin_AdminDefaultPermission_ReturnUrl", roleID, url, args);
		}

		#endregion

		#endregion

		public virtual string TrackbackPingUrl(int postID)
		{
			return FormatUrl("gallery_TrackBack_Ping",postID);
		}
        
		public string AttachmentUrl(Gallery gallery, PostAttachmentMetaData metaData)
		{
			if(metaData.IsRemote)
				return metaData.FileName;

			GalleryAttachmentSettings fs = GalleryConfiguration.Instance().AttachmentSettings;
			if(fs.EnableDirectLinks)
			{
				GalleryPost post = GalleryPosts.GetPicture(metaData.PostID); 
				return CSContext.Current.Context.Response.ApplyAppPathModifier(Path.Combine(fs.VirtualPath,fs.GetLocalFileName(post)));
			}
			return this.PictureUrl(gallery.ApplicationKey,metaData.PostID);
            
		}


	}
}
