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

using System;
using System.Web;
using System.IO;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Configuration;

namespace CommunityServer.Controls {

    public class ThemeDropDownList : DropDownList {

        public ThemeDropDownList() {

            HttpContext context = CSContext.Current.Context;

            string[] dirs = Directory.GetDirectories( context.Request.PhysicalApplicationPath + CSConfiguration.GetConfig().FilesPath + "\\themes" );

            foreach (string s in dirs) {

                DirectoryInfo dirInfo = new DirectoryInfo(s);

				// check to ensure we skip any directories that start
				// with an underscore.
				//
				if (dirInfo.Name.Length > 0) {
					if (!dirInfo.Name.StartsWith("_" ) && string.Compare(dirInfo.Name, "blogs", true) != 0 && string.Compare(dirInfo.Name,"galleries",true) != 0) {

						// Add directories
						//
						Items.Add(new ListItem(dirInfo.Name.ToLower(), dirInfo.Name.ToLower()));
					}
				}
            }
        }

        public override string SelectedValue {
            get {
                return base.SelectedValue;
            }
            set {
                if (Items.FindByValue(value.ToLower()) == null)
                    Items.FindByValue("default").Selected = true;
                else
                    base.SelectedValue = value.ToLower();
            }
        }


    }
}
