var PerSettings = {
	sDefaults:{
		backcolor:"#333344",
		topcolor:"#FFFFFF",
		middlecolor:"#FFFFFF",
		bottomcolor:"#FFFFFF",
		topfont:"Segoe UI",
		middlefont:"Segoe UI",
		bottomfont:"Segoe UI",
		topfontsize:13,
		middlefontsize:75,
		bottomfontsize:13,	
		texture:4,
		topformat:"%F %Y",
		bottomformat:"%l",
		customtexture:""
	},
	sCurrent:new Array(),
	Init:function(){
		if (this.oFile.FileExists(this.sPath)){
			var tmpFile = this.oFile.OpenTextFile(this.sPath, 1);
			var fullText = tmpFile.ReadAll();
			tmpFile.Close();
			var fullArr = fullText.split("\n");
			var tmpArr;
			for (var i in fullArr){
				tmpArr=fullArr[i].split("=");
				if (tmpArr.length==2){
					this.sCurrent[tmpArr[0]]=this.StrToObj(tmpArr[1]);
				}
			}
		}
		var loadedDefault=false;
		for (var i in this.sDefaults){
			if (this.sCurrent[i]===undefined){
				loadedDefault=true;
				this.sCurrent[i]=this.sDefaults[i];
			}
		}
		if (loadedDefault){
			this.SaveCurrent();
		}
	},
	Get:function(strName){
		return this.sCurrent[strName];
	},
	Set:function(strName,strValue,dontSave){
		this.sCurrent[strName]=strValue;
		if (!dontSave){
			this.SaveCurrent();
		}
	},
	Reset:function(){
		this.sCurrent=this.ArrCopy(this.sDefaults);
		this.SaveCurrent();
	},
	ArrCopy:function(srcArr){
		var ret=[];
		for (var i in srcArr){
			if (typeof obj == "object"){
				ret[i]=this.ArrCopy(srcArr[i]);
			}else{
				ret[i]=srcArr[i];
			}
		}
		return ret;
	},
	SaveCurrent:function(){
		var fullText="";
		for (var i in this.sCurrent){
			fullText+=i+"="+this.ObjToStr(this.sCurrent[i])+"\n";
		}
		var tmpFile = this.oFile.CreateTextFile(this.sPath, true);
		tmpFile.Write(fullText);
		tmpFile.Close();
	},
	ObjToStr:function(obj){
		if (typeof obj == "object"){
			var tmpStr="a";
			var hasCount=false;
			for (var i in obj){
				tmpStr+=i+":"+this.ObjToStr(obj[i])+",";
				hasCount=true;
			}
			if (hasCount){
				tmpStr=tmpStr.substr(0,tmpStr.length-1);
			}
			return escape(tmpStr);
		}else{
			return "s"+escape(obj);
		}
	},
	StrToObj:function(str){
		var tmpType=str.substr(0,1)
		var tmpStr=unescape(str.substr(1));
		if (tmpType=="s"){
			return tmpStr.replace("\r","");
		}else{
			var tmpArr=tmpStr.split(",");
			var tmpArr2;
			var newArr=[];
			for (var i in tmpArr){
				tmpArr2=tmpArr[i].split(":");
				newArr[unescape(tmpArr2[0])]=this.StrToObj(tmpArr2[1]);
			}
			return newArr;
		}
	},
	oFile:new ActiveXObject("Scripting.FileSystemObject"),
	sPath:System.Gadget.path+"/PerSettings.ini"
}
PerSettings.Init();
