	<div class="container top">
		<div class="well">
			<div class="text-center">
			<?php if ($pres) { ?>
				<a id="Btnprse" type="button" class="btn btn-default btn-circle-lg" href="<?php echo base_url('view/' . $pres) ?>">上一页</a>
			<?php } ?>
				<a type="button" class="btn <?php if($is_love) { echo 'btn-success'; } else { echo 'btn-default'; } ?> btn-circle-lg" id="collectBtn" onClick="Love('<?php echo $uuid ?>')">收藏 <span id="collect"><?php echo $collect ?></span></a> 
				<a type="button" class="btn <?php if($is_like) { echo 'btn-success'; } else { echo 'btn-default'; } ?> btn-circle-lg" id="likeBtn" onClick="Like('<?php echo $uuid ?>')">喜欢 <span id="like"><?php echo $like ?></span></a>
				<a type="button" class="btn btn-default btn-circle-lg" href="<?php echo base_url('xixi/downImage/' . $uuid) ?>" onClick="Down()">下载 <span id="download"><?php echo $share ?></span></a>	
				<a type="button" class="btn btn-default btn-circle-lg" onClick="Random()">发现</a> 
			<?php if ($next <= $this->pic_model->max_id()) { ?>	
				<a id="Btnnext" type="button" class="btn btn-default btn-circle-lg" href="<?php echo base_url('view/' . $next) ?>">下一页</a>
			<?php } ?>
			</div>
			<h1 class="text-center"><strong><?php echo $name ?></strong></h1>
			<div class="text-center">
				<a style="cursor: pointer;" ondblclick="Like('<?php echo $uuid ?>')" onClick="Random()">
					<img style="max-width: 100%;" data-tag="xixi_picture" src="<?php echo $url ?>">
				</a>
			</div>
			<h5 class="text-left">
				<blockquote><?php echo $text ?></blockquote>
			</h5>
			<h5 class="text-left">
				<?php $tag  = explode(" ", $tags); ?>
				<?php if( $this->session->userdata('online') ): ?>
					<a style="cursor: pointer;" data-toggle="modal" data-target="#addtagModal"><i class="fa fa-tags fa-lg"></i></a>
				<?php else: ?>
					<?php if( !empty($tag[0]) ): ?>
						<i class="fa fa-tags fa-lg" style="color: #428BCA;"></i>
					<?php endif; ?>
				<?php endif; ?>
					<?php echo nbs(2) ?>
			<?php foreach ($tag as $value): ?> <!-- 输出所有标签 -->
				<a href="<?php echo base_url('tag/'.$value) ?>"><span class="label label-info"><?php echo $value ?></span></a>
			<?php endforeach; ?>
			</h5>
			<h5 class="text-right">
				<a href="<?php echo base_url('catalogue/'.$catanothername) ?>"><?php echo $catname ?></a>
			</h5>
			<h5 class="text-right"><?php echo $user ?></h5>
			<h5 class="text-right"><?php echo $date ?></h5>
		</div>
		<!-- 相关图片推荐：当有标签时推荐同标签的图片，当无标签时推荐热门图片 -->
		<div class="well">
			<div class="row">
			<?php
			if( empty($tag[0]) ) {
				$fir_tag = "";
			} else {
				$fir_tag = $tag[0];
			}
			$images = $this->pic_model->alltag($fir_tag);
			foreach ($images as $img) {
				if (!file_exists($img['pic_url'])) {
					continue;
				}
				$thumb    = explode(".",$img['pic_url']);
				$thumbpic = $thumb[0] . "_thumb." . $thumb[1];
				if (file_exists($thumbpic)) {
					$imageurl  = base_url($thumbpic);
				} else {
					$imageurl  = base_url($value['pic_url']);
				}
			?>
				<div class="col-xs-6 col-sm-4 col-md-2">
					<a href="<?php echo base_url('view/' . $img['ID']) ?>" class="thumbnail">
  						<img src="<?php echo $imageurl ?>" alt="<?php echo $img['pic_name'] ?>" style="height: 220px;">
						</a>
					</div>
			<?php } ?>
			</div>
		</div>
		<?php if($comment) : ?>
		<div class="well">
			<textarea class="form-control border" rows="5" id="text"></textarea>
			<div class="alert alert-danger border hide" id="alert" style="margin-top:10px;" role="alert">警告</div>
			<div class="alert alert-success border hide" id="success" style="margin-top:10px;" role="alert">成功</div>
			<div class="text-right" style="margin-top:10px;">
				<button class="btn btn-primary border" onClick="javascript:SendMessage('<?php echo $uuid ?>')">发布</button>
			</div>
		</div>
		<div class="well" id="message">
			<?php if (!$this->message_model->pic_count($uuid)) { ?>
				<p class="text-left" id="nullmessage">快来留下第一条评论吧~</p>
			<?php } ?>
			<?php
				$query = $this->message_model->pic_message($uuid);
				foreach ($query as $value) {
					$msgid = $value['ID'];
			?>
			<div>
				<p class="text-left">
					<?php
						$pic = 'upload/user/' . $this->user_model->picture($value['msg_user']) . '_3.jpg';
						if (file_exists($pic)) {
							$pic_u = base_url('upload/user/' . $this->user_model->picture($value['msg_user']) . '_3.jpg');
						} else {
							$pic_u = base_url('upload/user/default_3.jpg');
						}
					?>
					<img class="img-circle" src="<?php echo $pic_u ?>">
					<strong><?php echo $value['msg_user'] ?></strong>
				</p>
				<blockquote><p class="text-left"><?php echo urldecode($value['msg_text']) ?></p></blockquote>
				<p class="text-right"><a style="" onClick="javascript:delMessage('<?php echo $msgid ?>')">删除</a></p>
				<p class="text-right"><?php echo $value['msg_datetime'] ?></p>
				<hr>
			</div>
			<?php } ?>
		</div>
	<?php endif; ?>
	</div>

	<!-- Modal -->
	<div class="modal fade" id="addtagModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top:200px;">
	  <div class="modal-dialog">
	    <div class="modal-content border">
	      <div class="modal-header">
	        <h4 class="modal-title" id="myModalLabel"><strong>添加标签</strong></h4>
	      </div>
	      <div class="modal-body">
	        <div class="form-horizontal">
    	        <div class="form-group">
    	        	<label class="col-sm-2 control-label">标 签</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control border" id="tag" value="<?php foreach ($tag as $value) { echo $value . ','; } ?>" autofocus="true" placeholder="使用回车键入标签" data-role="tagsinput">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12">
                    <?php
                        $query = $this->tags_model->tags();
                        foreach ($query as $value) {
                    ?>
                        <span class='label label-info' style="cursor: pointer;" onClick="ClickTag('<? echo $value['tag_name'] ?>')"><? echo $value['tag_name'] ?></span>
                    <?php } ?>
                    </div>
                </div>
	        </div>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default border" data-dismiss="modal">关闭</button>
	        <button type="button" class="btn btn-primary border" onClick="EditTag()">保存</button>
	      </div>
	    </div>
	  </div>
	</div>

</div>
<script src="<?php echo base_url('dist/js/bootstrap-tagsinput.min.js') ?>"></script>
<script>
    $('#tag').tagsinput({
      maxTags   : 6,
      maxChars  : 32,
      trimValue : true
    });
    function ClickTag (argument)
    {
        $('#tag').tagsinput('add', argument);
    }

    function EditTag () {
    	var pic       = '<?php echo $id; ?>';
    	var tags      = $('#tag').val();
    	var server    = Home + "xixi/edittag/" + pic + "/" + tags;
		$.ajax({
		   	type : "POST",
		   	url  : server,
		   	success: function(recvice){
		   		if (recvice == "0") {
		   			$('#addtagModal').modal('hide');
		   			 location.reload();
		   		}


		   }
		})
    }

    function SendMessage (view) {
		var text  = $('#text').val();
		var dataStr  = '<?php echo date("Y-m-d H:i:s"); ?>';
		var username = '<?php echo $username; ?>';
		var userpic  = '<?php echo $userpic; ?>';
		$('#alert').removeClass('show');
		$('#alert').addClass('hide');

		if (username == 0) {
			window.location.href = Home + "login";
			return;
		}
		if (text.length < 6) {
			$('#alert').html("留言内容不得少于六个字符。");
			$('#alert').removeClass('hide');
			$('#alert').addClass('show');
			setTimeout(function () {
				$('#alert').removeClass('show');
				$('#alert').addClass('hide');
			}, 3000);
			return;
		}

		var server = Home + "message/addmessage/" + view + "/" + text + "/" + username;
		$.ajax({
		   	type : "POST",
		   	url  : server,
		   	success: function(recvice){
		    	$('#success').html("留言发布成功。");
				$('#success').removeClass('hide');
				$('#success').addClass('show');

				var m_div = $('<div>')
				$('#message').prepend(m_div);

				var p_user = $('<p>');
				p_user.addClass("text-left");
				m_div.append(p_user); 


				var user_img = $('<img />');
				user_img.addClass("img-circle");

				var userImg = new Image();
				userImg.onload = function() {
					user_img.attr('src', this.src);
				}
				userImg.src = userpic;
				p_user.append(user_img);

				p_user.append(" ");

				var strong = $('<strong>');
				strong.html(username);
				p_user.append(strong); 

				var block = $('<blockquote>');
				m_div.append(block);

				var p_text = $('<p>');
				p_text.addClass("text-left");
				p_text.html(text);
				block.append(p_text);

				var p_data = $('<p>');
				p_data.addClass("text-right");
				p_data.html(dataStr);
				m_div.append(p_data);

				m_div.append("<hr/>");

				$('#text').val("");
				$('#nullmessage').addClass('hide');
		   }
		})
	
		setTimeout(function () {
			$('#success').removeClass('show');
			$('#success').addClass('hide');
		}, 3000);

	}

	function delMessage (id) {
		var server = Home + "message/delmessage/" + id;
		$.ajax({
		   	type : "POST",
		   	url  : server,
		   	success: function(recvice){
		   		location.reload();
		   }
		})
	}


	function Down () {
		var download = $('#download').html();
		$('#download').html(parseInt(download) + 1);
	}

	function Like (uuid) {
		$.get("<?php echo base_url('xixi/like') . '/' ?>" + uuid,function(data){
			$.each($.parseJSON(data), function(idx, obj) {
				if (obj.is_like) {
					$('#likeBtn').removeClass("btn-default");
					$('#likeBtn').addClass("btn-success");
					$('#like').html(obj.like);
				} else {
					$('#likeBtn').removeClass("btn-success");
					$('#likeBtn').addClass("btn-default");
					$('#like').html(obj.like);
				}
			});
		});
	}
	function Love (uuid) {
		$.get("<?php echo base_url('xixi/love') . '/' ?>" + uuid,function(data){
			$.each($.parseJSON(data), function(idx, obj) {
				if (obj.is_login) {
					if (obj.is_love) {
						$('#collectBtn').removeClass("btn-default");
						$('#collectBtn').addClass("btn-success");
						$('#collect').html(obj.love);
					} else {
						$('#collectBtn').removeClass("btn-success");
						$('#collectBtn').addClass("btn-default");
						$('#collect').html(obj.love);
					}
				} else {
					window.location.href = Home + "login";
				}
			});
			
		});
	}

	function Random () {
    	var server    = Home + "xixi/random";
		$.ajax({
		   	type : "POST",
		   	url  : server,
		   	success: function(recvice){
		   		var view = Home + "view/" + recvice;
		   		location.href = view;
		   }
		})
	}
	$(document).ready(function() {
		$(document).bind('keydown', function(event) {
		    switch(event.keyCode) {
		  		case 37:
		  			if ($('#Btnprse').length > 0) {
		  				window.location.href = $('#Btnprse').attr("href");
		  			}
		  			break;
		  		case 39:
		  			if ($('#Btnnext').length > 0) {
		  				window.location.href = $('#Btnnext').attr("href");
		  			}
		  			break;
		  		default:
		  			break;
		  	}
		});
	});
</script>
<script>
	window._bd_share_config = {
		image : [{
			"tag" : "xixi_picture",
			viewType : 'list',
			viewPos : 'top',
			viewColor : 'black',
			viewSize : '16',
			viewList : ['qzone','tsina','huaban','tqq','renren']
		}]
	}
</script>
<script>
	with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>