﻿/**
 * @package WordPress
 * @subpackage Yuan
 */

$(document).ready(function(){
	//IE浏览器
	if($.browser.msie && $.browser.version<8){ 
			if(bf)
					bf.remove();
				var bf=$("<div  class='bottomInfo'><span>TOPMING提醒您，本站样式版本CSS3，且不对IE8以下版本做兼容，推荐请使用IE8+、firefox 3.0+、Chrome 4.0+、Opera10+浏览以获得最佳效果。</span></div>")
				bf.css("top",0).css("left",0);
				bf.appendTo("body").hide();
				bf.fadeIn(500);
				/*setTimeout(function(){ tip.fadeOut(500)},5000);*/
				return false;
		}
	$("ul li.cat-item").each(function(){
		$(this).find("a").attr("title","");//删除超链接的title属性，否则会妨碍看到二级菜单
		$(this).SubMenu();
	})
	$("#linkIcon").hover($("#linkIcon").ShowLinks(),"");
	
$("#submit").click(function(ev){
		if($("#comment").val().length>0)
			$("#commentform").submit();
		else
			{	
				if(tip)
					tip.remove();
				var tip=$("<div  class='tips'><span class='arrow'></span><span class='tipInfo'>还没有输入评论哦！</span></div>")
				tip.css("top",$(this).offset().top-60).css("left",$(this).offset().left+10);
				tip.appendTo("body").hide();
				tip.fadeIn(500);
				setTimeout(function(){ tip.fadeOut(500)},3000);
				return false;
			}
	})
	
	$("#searchsubmit").click(function(){
			if($("#s").val().length>0)
			$("#searchform").submit();
		else
			{	
				if(tip)
					tip.remove();
				var tip=$("<div  class='tips'><span class='tipInfo'>关键词呢？</span><span class='arrowDown'></span></div>")
				tip.css("top",$("#s").offset().top-25).css("left",$("#s").offset().left);
				tip.appendTo("body").hide();
				tip.fadeIn(500);
				setTimeout(function(){ tip.fadeOut(500)},3000);
				return false;
			}						  
	})
	
	$("#tabPost li").each(function(){
			$(this).mousemove(function(){
				$("#tabPost li").removeClass("currentTab");
				 $(this).addClass("currentTab");
				 $(".archivesList").hide();
				 $(".archivesList:eq("+$(this).index()+")").show();
			})
	})
	$("#startGame").click(function(){
			if($("#game").css("display")=="none")
			{
					$("#game").css("top",-31).css("left",0)
					$("#game").fadeIn(500);
					$(this).text("Stop killing");
			}
			else
			{
					$("#game").fadeOut(500);
					$("#game").attr("src",$("#game").attr("src"));
					$(this).text("Play a game?");
			}
	})
})

//显示友情链接
$.fn.ShowLinks=function(){
	var isShow=false
	var timeout=200
	var effect=500 //菜单显示效果快慢
	var timer=null
	var current=$(this);
	var offset = current.offset();

    var sLinks=$("#links")
	var showMenu=function(){
		if(isShow)
		{
			return false
		}
		sLinks.css("top",offset.top-200).css("left",offset.left-180)
		sLinks.fadeIn(effect)
		isShow=true
		sLinks.mouseover(function(){
			clearTimeout(timer)
		})
		sLinks.mouseout(function(){
			hideMenu()
			})
	};
	var hideMenu=function(){
		clearTimeout(timer)
		timer=setTimeout(function(){
		sLinks.fadeOut(effect)
		isShow=false},timeout)
	};
	current.hover(
		function(){
		clearTimeout()
		timer=setTimeout(function(){showMenu()},timeout)
		},
		function(){
		clearTimeout(timer)
		if(isShow)
			timer=setTimeout(function(){hideMenu()},timeout)})
}

//显示子菜单
$.fn.SubMenu=function(){
	var isShow=false
	var current=$(this)
	var timeout=200
	var effect=300 //菜单显示效果快慢
	var timer=null
	var offset = current.offset();
	var content=$(this).find(".children").html()
	var hasChild=content?content:"null"

    var sMenu=$("<div class='catSubMenu'></div>")
	sMenu.appendTo("body").hide()
	sMenu.append("<ul>"+content+"</ul>")
	sMenu.css("top",offset.top+25).css("left",offset.left)
	var showMenu=function(){
		if(isShow)
		{
			return false
		}
		current.attr("class","current");
		sMenu.fadeIn(effect)
		isShow=true
		sMenu.mouseover(function(){
			clearTimeout(timer)
		})
		sMenu.mouseout(function(){
			hideMenu()
			})
	};
	var hideMenu=function(){
		clearTimeout(timer)
		timer=setTimeout(function(){
		sMenu.fadeOut(effect);
		current.attr("class","normal cat-item");
		isShow=false},timeout)
	};
	current.hover(
		function(){
		if(hasChild!="null"){
		clearTimeout()
		timer=setTimeout(function(){showMenu()},timeout)
		}},
		function(){
		if(hasChild!="null"){
		clearTimeout(timer)
		if(isShow)
			timer=setTimeout(function(){hideMenu()},timeout)
		}})
}
