<!--  color script written entirely in JavaScript  -->
<!--  Written by myhyli & 色眯眯的小疯狗, 2003/05/12. -->
<!--  Member Of Blueidea Web Team. -->
<!--  Welcome to www.blueidea.com. -->

var temp_bt_colorSetting;
var tempState=true;
var tempTimeout;

function initializeUI() {
	if(GetCookie('blueidea_colorSetting')!=null) {
		document.styleSheets[0].disabled=true;
		updateColor(GetCookie('blueidea_colorSetting').split(';'),true);
		document.styleSheets[0].disabled=false;
		}
	}
initializeUI();

function settingColor() {
	var reValue=window.showModelessDialog('js/color/colorSetting.htm',window,'dialogWidth:450px;dialogHeight:405px;status:no;scroll:no;help:no;');
	}

function updateColor(settings,grade) {
	if(tempState==false) return false;
	clearTimeout(tempTimeout);
////为了增加颜色转换的效果和消除切换的生硬感，使用了滤镜
	if(grade!=true) {
		tempState=false;
		var oldBody=document.body;
		if(oldBody!=null) {
			var newBody=oldBody.cloneNode();//必须在应用滤镜前进行，以确保body对象是干净的
			oldBody.style.filter='blendTrans(duration=1)';
			oldBody.filters[0].apply();
			}
		}
////////////////////////////////////////////////////////

	var colors=new Object();
	for(var i=0;i<settings.length;i++) {
		colors[settings[i].split(':')[0].replace(/^(d_)|(c_)/i,'').toLowerCase()]=settings[i].split(':')[1];
		}

	for(i=0;i<document.styleSheets[0].rules.length;i++) {

		with(document.styleSheets[0].rules[i]) {
			var tempText=selectorText.toLowerCase().replace(/[^\.]*\./i,'');
			tempText=tempText.replace(/:\w*/i,'');
			switch(tempText) {
				case 'a':
					if(selectorText.match(/:hover/)!=null)style.color=colors['a_hover'];
					else style.color=colors[tempText];
					break;
				case 'navlink':
					style.color=colors[tempText];
					break;
				case 'content':
					style.color=colors[tempText];
					break;
				case 'td':
					style.color=colors['content'];
					break;
				case 'docparameter td':
					style.color=colors['docparameter_text'];
					break;
				default:
					if(colors[tempText]) {
						if(tempText=='body' && document.readyState=='complete') {
							bt_colorSetting.style.backgroundColor=colors[tempText];
							}
						else if(tempText=='body' && document.readyState!='complete') {
							temp_bt_colorSetting=colors[tempText];
							}
						style.backgroundColor=colors[tempText];
						}
					break;
				}
			}
		}

////播放滤镜，并且在播放完毕后更新body，以消除应用滤镜后的滞后感，该部分代码作者：色眯眯的小疯狗
	if(grade!=true) {
		document.body.filters[0].play();
		tempTimeout=setTimeout(function() {
				if(oldBody!=null) {
					oldBody.applyElement(newBody, "inside")
					oldBody.swapNode(newBody);
					oldBody.removeNode(true);
					}
				tempState=true;
				},1500);
		}
/////////////////////////////////////////////////////////////////
	}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = window.document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (window.document.cookie.substring(i, j) == arg)	return getCookieVal (j);    
		i = window.document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function getCookieVal (offset) {  
	var endstr = window.document.cookie.indexOf (";", offset);  
	if (endstr == -1) endstr = window.document.cookie.length;  
	return unescape(window.document.cookie.substring(offset, endstr));
}
function SetCookie (name, value) {  
	var exp = new Date();  
	exp.setTime(exp.getTime() + (30*24*60*60*1000));
	window.document.cookie = name + "=" + escape (value) + "; expires=" + exp.toGMTString()+";path=/";
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	window.document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()+";path=/";
}