/**
 * @namespace com.thesis.control.ThemeControl
 * @imports com.thesis.base.String
 * @imports com.thesis.util.StringBuffer
 * @imports com.thesis.util.Cookies
 * @author 钟军锐 August.R@263.net
 */

/** @id ThemeControl */
function ThemeControl(aryID){
	this.CSS;
	this.URL = "css/";
	this.Param = "?clr=";
	this.Links = aryID;
	
	if(typeof ThemeControl._initialized == "undefined"){
		ThemeControl._initialized = true;
		
		/** @id refreshTheme */
		ThemeControl.prototype.refreshTheme = function(sID){
			if(!sID){
				this.CSS.href = this.URL;
				Cookies.del("ThemeStyle","/");
				return;
			}
			this.CSS.href = this.URL + sID + ".css";
			for(var i in this.Links){
				if(i && this.Links[i]){
					var t = $(this.Links[i]);
					if(t && this.Links[i] == sID)
						t.parentNode.className = "on";
					else if(t)
						t.parentNode.className ="";
				}
			}
			Cookies.set("ThemeStyle",sID,30*24*60*60,"/");
		};
		
		/** @id initialize */
		ThemeControl.prototype.initialize = function(Root){
			this.CSS = C$("link");
			this.CSS.rel = "stylesheet";
			this.CSS.type = "text/css";
			document.getElementsByTagName("Head")[0].appendChild(this.CSS);
			var sID = Cookies.get("ThemeStyle");
			this.refreshTheme(sID);
			
			for(var i in aryID){
				if(i && aryID[i]){
					var t = $(aryID[i]);
					if(t){
						uEvent.addBrowserHandler(t,"click",function(){
							var oE = uEvent.getBrowserEvent();
							Root.refreshTheme(oE.target.id);
						});
					}
				}
			}
		};
	}
	
	this.initialize(this);
}
