var _reader = {
	toggleAside: function() {
		if($("#J_AsideTrigger").hasClass("open")){
			$("#J_Theme").is(":hidden") || _reader.toggleTheme(), $("#J_Aside").animate({ left: -$("#J_Aside").width() }, 200), $("#J_AsideTrigger").removeClass("open").addClass("close"), _reader.setCookie("aside", "close")
		}else{
			$("#J_Aside").animate({ left: 0 }, 200), $("#J_AsideTrigger").removeClass("close").addClass("open"), _reader.setCookie("aside", "open")
		}
	},
	toggleRecommand: function() {
		if($("#J_RecommandTrigger").hasClass("open")){
			$("#J_Recommand").animate({ right: -$("#J_Recommand").width() }, 200), $("#J_RecommandTrigger").removeClass("open").addClass("close"), _reader.setCookie("recommand", "close")
		}else{
			$("#J_Recommand").animate({ right: 0 }, 200), $("#J_RecommandTrigger").removeClass("close").addClass("open"), _reader.setCookie("recommand", "open")
		}
	},
	handleTheme: function(e) {
		e && e.preventDefault(), _reader.toggleTheme(), $("#J_Theme").find("a").removeClass("on"), $(this).addClass('on');
		var theme = parseInt($(this).attr('data-theme')) || 1000;
		_reader.channgeTheme(theme), _reader.setCookie("theme", theme)
	},
	channgeTheme: function(theme) {
		switch (theme) {
			case 1e3:
				$("#J_Reader").attr('class', '').addClass('skin-normal');
				break;
			case 1001:
				$("#J_Reader").attr('class', '').addClass('skin-green')
				break;
			case 1002:
				$("#J_Reader").attr('class', '').addClass('skin-pink')
				break;
			case 1003:
				$("#J_Reader").attr('class', '').addClass('skin-light')
				break;
			case 1004:
				$("#J_Reader").attr('class', '').addClass('skin-dark'), $("#J_AsideTrigger").hasClass("open") && _reader.toggleAside(), $("#J_RecommandTrigger").hasClass("open") && _reader.toggleRecommand();
				break;
		}
	},
	handleFont: function() {
		$("#J_Font").toggle(), $("#J_Font").find("a").removeClass("on"), $(this).addClass('on');
		var size = parseInt($(this).attr('data-size')) || 12;
		$("#J-content").css("font-size",size), _reader.setCookie("fontsize", size)
	},
	toggleTheme: function(e) {
		e && e.preventDefault(), $("#J_Theme").toggle()
	},
	toggleFont: function(e) {
		e && e.preventDefault(), $("#J_Help").is(":hidden") || _reader.toggleHelp(), $("#J_Font").toggle()
	},
	toggleHelp: function(e) {
		e && e.preventDefault(), $("#J_Font").is(":hidden") || _reader.toggleFont(), $("#J_Help").toggle()
	},
	jumpPage: function() {
		var event = document.all ? window.event : arguments[0];
		if (event.keyCode == 37) document.location = pre_page;
		if (event.keyCode == 39) document.location = next_page;
		if (event.keyCode == 13) document.location = index_page;
		var w = $(document).scrollTop(), h = $(window).height();
		if (event.keyCode == 38) {
			w = w - h;
		}
		if (event.keyCode == 40) {
			w = w + h;
		}
		$("html, body").animate({
			scrollTop: w
		}, 300)
	},
	setCookie: function(cookieName,cookieValue) {
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000 * 356 * 24);
		document.cookie = cookieName+'='+escape(cookieValue)+ ';expires='+expire.toGMTString()+'; path=/';
	},
	readCookie: function(cookieName) {
		var theCookie=''+document.cookie;
		var ind=theCookie.indexOf(cookieName);
		if (ind==-1 || cookieName=='') return ''; 
		var ind1=theCookie.indexOf(';',ind);
		if (ind1==-1) ind1=theCookie.length;
		return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	},
	loadSet: function() {
		var tmpstr;
		tmpstr = _reader.readCookie("theme");
		if (tmpstr != "") {
			_reader.channgeTheme(parseInt(tmpstr)), $("#J_Theme").find("a").removeClass("on"), $("[data-theme='"+tmpstr+"']").addClass('on')
		}
		tmpstr = _reader.readCookie("fontsize");
		if (tmpstr != "") {
			$("#J-content").css("font-size",parseInt(tmpstr)), $("#J_Font").find("a").removeClass("on"), $("[data-size='"+tmpstr+"']").addClass('on')
		}
		tmpstr = _reader.readCookie("aside");
		tmpstr == "close" && _reader.toggleAside();
		tmpstr = _reader.readCookie("recommand");
		tmpstr == "close" && _reader.toggleRecommand()
	},
	doBookMark : function(e) {
		e && e.preventDefault();
		SAXUE.doFav(e,aid,chapterid)
	},
	init: function() {
		_reader.loadSet(), $("#J_AsideTrigger").bind('click', this.toggleAside), $("#J_RecommandTrigger").bind('click', this.toggleRecommand), $("#J-ThemeTrigger").bind('click', this.toggleTheme), $("#J_Theme a").bind('click', this.handleTheme), $("#J_HelpClose").bind('click', this.toggleHelp), $("#J_HelpTrigger").bind('click', this.toggleHelp), $("#J_FontTrigger").bind('click', this.toggleFont), $("#J_Font a").bind('click', this.handleFont), $('#J_PrevTurn').bind('click', function() { document.location = pre_page }), $('#J_NextTurn').bind('click', function() { document.location = next_page }), $('#J_Fav').bind('click', SAXUE.doFav), $('#J_BookMark').bind('click', this.doBookMark), $('#J_Top').bind('click', SAXUE.doTop), $('#J_Down').bind('click', SAXUE.doDown), document.onkeydown = _reader.jumpPage;
	}
};
$(function(){
	_reader.init();
	// °Ù¶È·ÖÏí
	if (s_thumb.indexOf("http://")!=0){
		s_thumb = saxue_url + s_thumb
	}
	window._bd_share_config={"common":{"bdSnsKey":{},"bdText":s_intro,"bdUrl":s_url,"bdPic":s_thumb,"bdMini":"2","bdMiniList":false,"bdStyle":"1","bdSize":"16"},"share":{"bdSize":16}};
	with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
});