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

using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Web;
using System.Web.Caching;
using CommunityServer.Components;
using CommunityServer.Configuration;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for ThemeManager.
	/// </summary>
	public class ThemeManager : BaseThemeManager
	{
		private NameValueCollection SkinList = new NameValueCollection();
		private Hashtable ThemeList = new Hashtable();
        public static string CacheKey = "GalleryThemeManager";
        private ThemeManager()
		{
			
		}

		public static ThemeManager Instance()
		{
            ThemeManager tm = CSCache.Get(CacheKey) as ThemeManager;
			if(tm == null)
			{
				tm = new ThemeManager();
				CacheDependency dep = new CacheDependency(null, new string[]{CSConfiguration.CacheKey});
                CSCache.Insert(CacheKey, tm, dep);
			}

			return tm;
		}

        protected override ThemedApplicationKeyApplicationConfiguration Config
        {
            get { return GalleryConfiguration.Instance(); }
        }

        public static string SkinPath()
        {
            CSContext cntx = CSContext.Current;	
            if(cntx.IsWebRequest)
            {
                Gallery g = Galleries.GetGallery(cntx.ApplicationKey);
                string path = GalleryConfiguration.Instance().ThemeLocation + g.Theme + "/";
                if(path.EndsWith("/"))
                    path = path.Substring(0, path.Length - 1);
                return path.Replace("~", Globals.ApplicationPath);
            }
            else
                return string.Empty;
        }
       
	}
}