var chapterRead = new Object();
chapterRead.ncn = '<span style="margin-left:20px;font-weight:bold;color:#A51257;">已经没有页面了，您可以做以下选择</span>：<br /><div style="margin-top:15px;text-align:center;"><a href="index.html">回本书首页</a>&nbsp;&nbsp;<a href="/index.php?do=book/comment/get&bookId=' + bookId + '">去本书书评</a><br /><a href="/index.php">回书酷首页</a>&nbsp;&nbsp;<a href="/index.php?do=user/favorite/add&bookId=' + bookId + '">加入收藏夹</a></div>';
chapterRead.ids = chapterIds;
chapterRead.next = function()
{	
	if(!this.hasNext()){	
		flyDiv.show(chapterRead.ncn, 300, 150);
		return;
	}
	//var href = window.location.href;
	//var regs = href.match(/\/chapter(\d+)\.html#*$/);
	for(var i = 0; i < chapterIds.length; i++){
		if(chapterIds[i] == chapterId){
			var nChapterId = chapterIds[i + 1];
			break;
		}
	}
	window.location.href = nChapterId + '.html';
}

chapterRead.prev = function()
{
	if(!this.hasPrev()){
		flyDiv.show(chapterRead.ncn, 300, 150);
		return;
	}
	for(var i = 0; i < chapterIds.length; i++){
		if(chapterIds[i] == chapterId){
			var pChapterId = chapterIds[i - 1];
			break;
		}
	}
	window.location.href = pChapterId + '.html';
};

chapterRead.home = function()
{
	var padId = this.getPadBookId();
	window.location.href = '/' + padId + '.html';
}

chapterRead.hasNext = function()
{
	if(this.ids[this.ids.length - 1] != this.getChapterId()){
		return true;
	}
	return false;
}

chapterRead.hasPrev = function()
{
	if(this.ids[0] != this.getChapterId()){
		return true;
	}
	return false;
}

chapterRead.getBookId = function()
{
	return bookId;
}

chapterRead.getChapterId = function()
{
	return chapterId;
}

chapterRead.getPadBookId = function()
{
	var href = window.location.href;
	var regs = href.match(/(\d+)\/\d+.html#*$/);
	return regs[1];
};
chapterRead.moveAddBookmark = function()
{
	var o = document.getElementById('addfav');
	o.style.top = document.documentElement.scrollTop + 200 + 'px';
}

chapterRead.favorite = function()
{
	var cid = this.getChapterId();
	var bid = this.getBookId();
	window.location.href = '/index.php?do=user/favorite/add&bookId=' + bid + "&chapterId=" + cid;
}

flyDiv = new Object();

flyDiv.show = function(content, width, height)
{
	var bg = document.getElementById('flyDivBg');
	if(bg != null){
		return;
	}
	this.selectSwitch(0);
	window.scrollTo(0,0);
	var h = document.body.clientHeight > screen.height - 300 ? document.body.clientHeight : screen.height - 300;
	var w = document.body.clientWidth;	
	var shell = "<div id='flyDivBg' style='z-index:10000;text-align:center;vertical-align:middle;left:0px;top:0px;background-color:#cccccc;filter:alpha(opacity=80);opacity:0.8;padding-top:170px;position:absolute;height:" + h + "px;width:" + w +"px;'></div>";
	
	document.body.innerHTML += shell;
	
	var l = (screen.width / 2) - (width / 2);
	var d = "<div id='flyDivContent' style='padding:10px;left:" + l + "px;background-color:#ffffff;z-index:10001;position:absolute;width:" + width + "px;height:" + height + "px;top:170px;px;border:2px solid #A690A8;'>";
		d += "	<div style='text-align:right;'><a href='#' onclick='flyDiv.hidden();'>关闭</a></div>";
		d += "	<div style='float:none;'>"+content+"</div>";
		d += "	<div style='margin-top:15px;text-align:center;'><a href='#' onclick='flyDiv.hidden();'><b>确&nbsp;定</b></a></div>";
		d += "</div>";
	document.body.innerHTML += d;
}

flyDiv.hidden = function()
{
	this.selectSwitch(1);
	var c = document.getElementById('flyDivContent');
	c.style.display = 'none';
	c.parentNode.removeChild(c);
	var bg = document.getElementById('flyDivBg');
	bg.style.display = 'none';
	bg.parentNode.removeChild(bg);
	return true;
}

flyDiv.selectSwitch = function(display)
{
	var s = document.getElementsByTagName('select');
	for(var i = 0; i < s.length; i++){
		if(display == 0){
			s[i].style.visibility = 'hidden';
		}else{
			s[i].style.visibility = 'visible';
		}
	}
}

var se = new Object();
se.cs = document.getElementById('content-shell');
se.bg = '#ffffff';
se.fc = '#333333';
se.fs = '14px';
se.setbg = function (value) 
{	
	cookie.set('bg', value, 1000000);
	this.bg = value;
	se.setStyle();
}

se.setfc = function(value)
{
	cookie.set('fc', value, 1000000);
	this.fc = value;
	this.setStyle();
}
se.setfs = function(size)  //修改字体大小
{	
	cookie.set('fs', size, 1000000);
	this.fs = size;
	this.setStyle();
}

se.ini = function()
{
	var bg = cookie.get('bg');
	if(bg != null){
		this.bg = bg;
	}	
	
	var fc = cookie.get('fc');
	if(fc != null){
		this.fc = fc;
	}
	
	var fs = cookie.get('fs');
	if(fs != null){
		this.fs = fs;
	}
	se.setStyle();
}

se.setStyle = function()
{
	this.cs.style.backgroundColor = this.bg;
	this.cs.style.color = this.fc;
	this.cs.style.fontSize = this.fs;
}
se.ini();

window.onscroll = function()
{
	chapterRead.moveAddBookmark();
}

document.onkeydown = function(e)
{
	if(document.all){
		var k = event.keyCode;
	}else{
		var k = e.keyCode;
	}

	switch(k){
		case 37 :
			chapterRead.prev();
			break;
		case 39 : 
			chapterRead.next();
			break;
		case 36 :
			chapterRead.home();
	}
}




