/*
	作者：戴铭
	功能：论坛的一些js功能
*/
$(document).ready(function()
{
	//对公用内容的修改
	$("#logo img").attr("src", "img/logo_091026_2.gif");
	$("#logo a").attr("href", "index.php").attr("target", "_blank");
	$("#right").hide();
	$("#bottom_txt").text('');
	$("#bottom_txt").append('© Starming-全明星 copyright <a href="http://www.starming.com/index.php?action=plugin&v=club&starid=68">戴铭</a> email:ming1016@gmail.com');
	
	$("#top-right a").attr("href", "#").click(function() {
		$("#top-right").html('<form action="" method="post">邮箱：<input type="text" size="8" name="email"/> 密码：<input type="password" size="6" name="password"/> 昵称：<input type="text" size="3" name="nickname"> <input type="submit" value="登录or注册" class="button"/>');
	});
	
	//出现回复按钮以及产生回复动作
	$(".postlistopr").hide();
	$(".clubpostlist tbody tr").mouseover(function() {
		$(".postlistopr").hide();
		$(".addtodigest").hide();
		$(this).children().children("a").show();
		//回复点击事件
		$(".postlistopr").click(function() {
			if($("#postreply")) {
				$("#postreply").remove();
			}
			$(this).parent().append('<form id="postreply" action="" method="post"><input type="hidden" name="tid" value="' + $(this).parent().parent().children(".widfat_tid").children(".p").text() + '"><textarea name="replythread"></textarea> <input type="submit" value="提交回复"></form>');
			$("#postreply textarea").focus();
		});
		//加精操作
		$(".addtodigest").click(function() {
			var tid = $(this).parent().parent().children(".widfat_tid").children(".p").text();
			$.getJSON('index.php?action=plugin&v=club&ajax=addtodigest&tid=' + tid, function(json) {
				if(json['status'] == 'ok') {
					$(this).parent().append('<span>添加精华成功</span>');
				} else {
					$(this).parent().append('<span>添加精华失败</span>');
				}
			});
		});
	});
	
	//控制图片不要过大
	$("img").each(function() {
			if($(this).attr("width") > 305) {
				
				$(this).attr("height", ($(this).attr("height")*305)/$(this).attr("width"));
				$(this).attr("width", "305");
			}
	});
	//功能按钮出现rss添加符号
	$("#moretools ul li a").click(function() {
		$("#toolbar form textarea").val(":rss" + $(this).attr("name"));
	});
	
	//投票
	
	
	//输入框的判断
	var $toolbar = $("#toolbar");
	var $helpcheck = 0;
	/*-----------------发帖框里的控制-------------------*/
	$("#newinput").keyup(function() {
		var t = $(this).val();
		if(t.slice(0,1) == ':') {
			$(this).css("color", "green");
			var $help = $("#newinputhelp");
			
			if($helpcheck == 0) {
				$toolbar.append('<span id="newinputhelp"></span>');
				$helpcheck = 1;
			}		
			$help.html('新模式，<span class="redbold">:</span>后跟<span class="redbold">open</span>(前往指定论坛,或使用更简洁的:o)，<span class="redbold">rss</span>(导入rss资源)，<span class="redbold">/</span>(搜索标题)，<span class="redbold">//</span>(搜索内容)，<span class="redbold">star</span>(获得明星百科)，<span class="redbold">news</span>(获得最新新闻报道)等敲入既可获得相关帮助');
		}
		//前往新论坛方法
		if(t.slice(1,2) == 'o') {
			$help.html('o方式和open一样');
		}
		if(t.slice(1,5) == 'open') {
			$help.html('open方式，后面跟需要前往的论坛名称即可，例如<span class="redbold">:open开心论坛</span>。');
		}		
		
		//导入rss资源
		if(t.slice(1,4) == 'rss') {
			$help.html('rss方式，后面跟一个rss地址即可导入内容，例如<span class="redbold">:rsshttp://www.google.com/reader/shared/ming1016</span>');
		}
		
		//搜索帖子内容
		if(t.slice(1,3) == '//') {
			$help.html('//方式，可以按照内容进行搜索，使用:结束，相关信息会显示在提示栏里。例如<span class="redbold">://飞机事故原因:</span>，注意尽量精准，结果最多显示前10条，如没有查到请将关键字写详细');
			if(t.slice(-1) == ':') {
				$.getJSON('index.php?action=plugin&v=club&ajax=searchcontent&words=' + encodeURIComponent(t.slice(3,-1)), function(json) {
					if(json['status'] == 'ok') {
						$help.html(json['result']);
					}
				});
			}
		} else if(t.slice(1,2) == '/') {
			$help.html('/方式，可以按照标题进行搜索，使用:结束，相关信息会显示在提示栏里。例如<span class="redbold">:/飞机事故:</span>，注意尽量精准，结果最多显示前10条，如没有查到请将关键字写详细');
			if(t.slice(-1) == ':') {
				$.getJSON('index.php?action=plugin&v=club&ajax=searchtitle&words=' + encodeURIComponent(t.slice(2,-1)), function(json) {
					if(json['status'] == 'ok') {
						$help.html(json['result']);
					}
				});
			}
		}
		
		//获得明星信息
		if(t.slice(1,5) == 'star') {
			$help.html('star方式，可以获取明星人物介绍，使用:结束，相关信息会出现在提示栏里。例如<span class="redbold">:star金城武:</span>');
			if(t.slice(-1) == ':') {
				$.getJSON('index.php?action=plugin&v=club&ajax=getstarinfo&starname=' + encodeURIComponent(t.slice(5,-1)), function(json) {
					if(json['status'] == 'ok') {
						$help.html(json['result']);
					}
				});
			}
		}
		
		//获得新闻
		if(t.slice(1,5) == 'news') {
			$help.html('news方式，获取新闻，使用:结束，相关信息会显示在提示栏里。例如<span class="redbold">:news苹果:</span>');
			if(t.slice(-1) == ':') {
				$.getJSON('index.php?action=plugin&v=club&ajax=getnews&starname=' + encodeURIComponent(t.slice(5,-1)), function(json) {
					if(json['status'] == 'ok') {
						$help.html(json['result']);
					}
				});
			}
		}
		
		/*------------暂不开放功能-----------*/
		//gamescript
		if(t.slice(1,11) == 'gamescript') {
			$help.html('gamescript方式，例如<span class="redbold">{山寨大话西游}dahuaxiyou_01</span>');
		}
		
		//roomy
		if(t.slice(1,6) == 'roomy') {
			$help.html('roomy方式，例如<span class="redbold">{新漫画}html的代码</span>');
		}
		
		//shop
		if(t.slice(1,5) == 'shop') {
			$help.html('shop方式，例如<span class="redbold">{紫色系列之某某}price:10元,description:百分百纯棉纯紫色,tel:1353322112</span>');
		}
		
		//cmd
		if(t.slice(1,4) == 'cmd') {
			$help.html('cmd方式，大括号里是标题，例如<span class="redbold">{北京欢乐谷}有很多很好玩的项目</span>');
		}
		
		//poll
		if(t.slice(1,5) == 'poll') {
			$help.html('poll方式，大括号是标题，例如<span class="redbold">{心中理想的城市}type:1,o1:北京,o2:上海,o3:长春,o4:武汉,o5:广州</span>');
		}
	});
	

});

