<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<title><?php echo $this->_var['book']['title']; ?></title>
		<script src="/plugin/jquery/jquery-2.1.3.min.js"></script>
		<link href="/plugin/dt-ui/dt-ui-pc.css" rel="stylesheet" />
		<link href="<?php echo $this->_var['skins']; ?>book/view.css" rel="stylesheet" /> 
	</head>
	 
 
	<body>
		<div class="resbox" >
			<div class="resbox-hd">搜索结果
			<a class="close" id="resbox-close" href="javascript:;">关闭</a>
			</div>
			<div id="reslist" class="reslist"></div>
		</div>
		<div id="top" class="topbox">
			<?php $this->assign("site",M("site")->get()); ?> 
			<img class="w60 mgr-10"  src="<?php echo $this->_var['site']['logo']; ?>" />
			<a href="/" class="cl-primary">返回首页</a>
			<div class="title"><?php echo $this->_var['book']['title']; ?></div>
			<div class="search-box">
				<input type="text" id="searchWord" class="text" /><div id="searchSubmit" class="bt">搜索</div>
				
			</div>
			 
			 
		</div>
		<div id="leftbox" class="menulist">
				 
				<?php $_from = $this->_var['artlist']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'a');if (count($_from)):
    foreach ($_from AS $this->_var['a']):
?>
					<div class="aitem close <?php if (! $this->_var['a']['child']): ?>nochild<?php endif; ?>" id="aitem<?php echo $this->_var['a']['id']; ?>" >
						<?php if (! $this->_var['a']['child']): ?>
						<a href="/module.php?m=book_article&a=show&bookid=<?php echo $this->_var['book']['bookid']; ?>&id=<?php echo $this->_var['a']['id']; ?>" class="atitle js-go" vid="<?php echo $this->_var['a']['id']; ?>" ><?php echo $this->_var['a']['title']; ?></a>
						<div class="fold-right"></div>
						<?php else: ?>
						
						<a href="javascript:;" class="atitle fold-toggle-a" vid="<?php echo $this->_var['a']['id']; ?>" ><?php echo $this->_var['a']['title']; ?><div class="fold-toggle"></div></a>
						<?php endif; ?>
						
						<?php if ($this->_var['a']['child']): ?>
							<?php $_from = $this->_var['a']['child']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'b');if (count($_from)):
    foreach ($_from AS $this->_var['b']):
?>
							<div class="bitem" id="bitem<?php echo $this->_var['b']['id']; ?>" >
								<?php if (! $this->_var['b']['child']): ?>
								<div class="fold-right"></div>
								<a href="/module.php?m=book_article&a=show&bookid=<?php echo $this->_var['book']['bookid']; ?>&id=<?php echo $this->_var['b']['id']; ?>" class="btitle js-go" vid="<?php echo $this->_var['b']['id']; ?>" ><?php echo $this->_var['b']['title']; ?></a>
								<?php else: ?>
								<a href="javascript:;" class="btitle fold-toggle-b" vid="<?php echo $this->_var['b']['id']; ?>" ><?php echo $this->_var['b']['title']; ?><div class="fold-toggle active"></div></a>
								
								<?php endif; ?>
								
								<?php if ($this->_var['b']['child']): ?>
									<?php $_from = $this->_var['b']['child']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'c');if (count($_from)):
    foreach ($_from AS $this->_var['c']):
?>
									<a href="/module.php?m=book_article&a=show&bookid=<?php echo $this->_var['book']['bookid']; ?>&id=<?php echo $this->_var['c']['id']; ?>" id="citem<?php echo $this->_var['c']['id']; ?>" class="citem js-go" vid="<?php echo $this->_var['c']['id']; ?>"  ><?php echo $this->_var['c']['title']; ?>
									<div class="fold-right"></div>
									</a>
									<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
								<?php endif; ?>
								</div>
							<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
						<?php endif; ?>
					</div>
				<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
			</div>
		<div id="rightbox" >
				<iframe  id="iframe" src="/module.php?m=book&a=viewContent&bookid=<?php echo $this->_var['book']['bookid']; ?>"></iframe>
			</div>
		 	
		<script>
			function goArticle(id){
				var url="/module.php?m=book_article&a=view&id="+id;
				var iframe='<iframe id="iframe" src="'+url+'"></iframe>';
				$("#rightbox").html(iframe);
				window.history.pushState(null, null, "<?php echo HTTP_HOST; ?>/module.php?m=book&a=view&bookid=<?php echo $this->_var['book']['bookid']; ?>&vid="+id);
			}
			$(document).on("click",".js-go",function(event){
				event.preventDefault();
				var id=$(this).attr("vid");
				$(".js-go").removeClass("active");
				$(this).addClass("active");
				goArticle(id);
			})
			
			$(document).on("click","#searchSubmit",function(){
				var word=$("#searchWord").val();
				var bookid="<?php echo $this->_var['book']['bookid']; ?>";
				$.get("/module.php?m=book_article&a=search&ajax=1",{
					bookid:bookid,
					word:word
				},function(data){
					if(data.error){
						skyToast(data.message);
					}else{
						var html='';
						var sdata=data.data.data;
						for(var i=0;i<sdata.length;i++){
							html+='<div class="reslist-item" vid="'+sdata[i].id+'">'+sdata[i].title+'</div>';
						}
						$(".resbox").show();
						$(".reslist").html(html);
					}
				},"json")
			})
			
			$(document).on("click",".reslist-item",function(){
				var id=$(this).attr("vid");
				$(".resbox").hide();
				$(".js-go").removeClass("active");
				$(".js-go[vid='"+id+"']").addClass("active");
				goArticle(id);
			})
			$(document).on("click","#resbox-close",function(){
				$(".resbox").hide();
			});
			$(document).on("click",".fold-toggle-a",function(){
				$(this).find(".fold-toggle").toggleClass("active");
				$(this).parents(".aitem").toggleClass("close");
			})
			$(document).on("click",".fold-toggle-b",function(){
				$(this).find(".fold-toggle").toggleClass("active");
				$(this).parents(".bitem").toggleClass("close");
			})
		</script>
		<?php if (get ( 'vid' )): ?>
		<script>
			
				var id="<?php echo intval($_GET['vid']); ?>";
				$(".js-go").removeClass("active");
				$(".js-go[vid='"+id+"']").addClass("active");
				goArticle(id);
			
		</script>
		<?php endif; ?>
	</body>
</html>
