var Light = {
	status: 'on',
	cookie: {
		name: 'light',
		value: {
			on:  'on',
			off: 'off'
		},
		expires: 3600
	},
	skin: {
		id: 'lightOFF',	
		url: '/v/css/play_dark.css?version=1.0.0505'
	},
	init: function(){
		var status = this.getStatus();
		if(status == 'off'){
			this.off();	
		}
	},
	turn: function(){
		if(this.status == 'on'){
			this.off();
		}else{
			this.on();
		}	
	},
	controlBox: function(turn){
		if(turn == 'off'){
			if(CollapseBox){
				var len = CollapseBox.getLength();
				var boxs = CollapseBox.collection;
				for(var i=0; i<len; i++){
					if(!CollapseBox.getGroup(boxs[i]) && boxs[i].id!="commentAreaBox"){//排除视频列表区
						CollapseBox.changeStatus(boxs[i], CollapseBox.config.status.collapse);	
					}
				}
			}
		}else if(turn == 'on'){
			if(CollapseBox){
				var len = CollapseBox.getLength();
				var boxs = CollapseBox.collection;
				for(var i=0; i<len; i++){
					if(!CollapseBox.getGroup(boxs[i]) && boxs[i].id!="commentAreaBox"){
						CollapseBox.changeStatus(boxs[i], CollapseBox.config.status.expand);	
					}
				}
			}
		}
	},
	on: function(){
		this.status = 'on';
		this._setCookie(this.cookie.name, 
							this.cookie.value.on,  
							{expires: this.cookie.expires});
		var stylesheet = document.getElementById(this.skin.id);
		if(stylesheet){stylesheet.disabled = true;}
		this.controlBox('on');
	},
	off: function(){
		this.status = 'off';
		this._setCookie(this.cookie.name, 
						this.cookie.value.off, 
						{expires: this.cookie.expires});
		var stylesheet = document.getElementById(this.skin.id);
		if(stylesheet){stylesheet.disabled = false;}
		else{
			var csslink = document.createElement('LINK');
			csslink.type = 'text/css';
			csslink.rel  = 'stylesheet';
			csslink.id = this.skin.id;
			csslink.href = this.skin.url;
			document.getElementsByTagName('HEAD')[0].appendChild(csslink);
		}
		this.controlBox('off');
	},
	getStatus: function(){
		var status = this._getCookie(this.cookie.name);
		if(status){this.status = status;}
		return this.status;
	},
	_setCookie: function(name, value, option){
		var str = name + '=' + escape(value);  
		if(option){
			if(option.expires){
				var date = new Date();
				var ms = option.expires*24*3600*1000;
				date.setTime(date.getTime() + ms);
				str += '; expires=' + date.toGMTString();
			} 
			if(option.path)   str += '; path='  + path;
			if(option.domain) str += '; domain' + domain;
			if(option.secure) str += '; true';
		}
		document.cookie = str;
	},
	_getCookie: function(name){
		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
		if(arr != null) return unescape(arr[2]); return null;
	}
}

window.nova_init_hook_turnlight=function(){Light.init();}
