<!--  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 tempTimeout;
var tempState	= true;
var _queue		= [];
var cssQueue	= ['body','listtitle','listcontent','listcontentmedium','a','a_hover','columntitle','columncontent','content','hottitle','hotcontent','navlight','navlink','navdark','logobackground','pageseparator','border','pagelight','pageicon','pagesubject','docparameter','docparameter_text','pagelighter'];

function initializeUI() {
	if(GetCookie('blueidea_colorSetting')!=null && /^#/.test(GetCookie('blueidea_colorSetting'))) {
		document.styleSheets[0].disabled=true;
		updateColor(GetCookie('blueidea_colorSetting'),true);
		document.styleSheets[0].disabled=false;
		}
	}
initializeUI();

function settingColor() {
	var reValue=window.showModelessDialog('color/colorSetting.htm',window,'dialogWidth:460px;dialogHeight:415px;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对象是干净的
			var tempScroll	= [oldBody.scrollLeft,oldBody.scrollTop];
			oldBody.style.filter='blendTrans(duration=1)';
			oldBody.filters[0].apply();
			}
		}

	var colors=new Object();

	for(var i=0;i<cssQueue.length;i++) {
		colors[cssQueue[i]]=settings.split(';')[i];
		}

	for(i=0;i<document.styleSheets[0].rules.length;i++) {

		with(document.styleSheets[0].rules[i]) {
			var tempText=selectorText.toLowerCase().replace(/[^\.]*\./i,'').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.body!=null && bt_colorSetting!=null) {
							bt_colorSetting.style.backgroundColor=colors[tempText];
							}
						else if(tempText=='body' && (document.body==null || bt_colorSetting==null)) {
							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.className='';
					if(oldBody!=null) {
						oldBody.applyElement(newBody, "inside")
						oldBody.swapNode(newBody);
						oldBody.removeNode(true);
					}
					document.body.scrollLeft	= tempScroll[0];
					document.body.scrollTop		= tempScroll[1];
					}
				tempState	= true;
				for(var i=0;i<_queue.length;i++) {
					eval(_queue[i].split(',')[0]+'('+_queue[i].split(',').slice(1)+')');
					}
				_queue		= [];
				},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=/";
}