$(function() {
	//搜索框
	var keyWord = $("input#s");
	if (keyWord.val().length >= 1 ) keyWord.prev("label").hide();
	keyWord.focus(function(){ keyWord.prev("label").hide(); })
	keyWord.blur(function(){
		if (keyWord.val() == "") {
			keyWord.val("");
			keyWord.prev("label").show();
		}
	});

	//主菜单下拉
	$("#nav li li").has('ul').children("a").append(" &raquo;");
	$("#nav li").has('ul').hover(
		function() {
			$(this).children("ul").slideDown(200);
		},
		function() {
			$(this).children("ul").slideUp(200);
		}
	);

	//赞助我
	$("#sponsor").html($("#sponsor-me").attr("title"));
	$("#sponsor-me").attr("title","");
	$("#sponsor-me").hover(
		function() {
			$("#sponsor").slideDown(200);
			$("#sponsor").attr("style","display:block;");//这一行是为了解决 jQuery IE8 bug
		},
		function() { $("#sponsor").fadeOut(200); }
	);

	//列表隔行换色
	$(".list li:odd").addClass("odd");

	//初始化选项卡
	$("#choice ul:first").idTabs();
	$("#side-cmt ul:first").idTabs();
	$("#column-nav ul:first").idTabs();

	//首页相册文字
	$("#home-album li a").hover(
		function() {
			$(this).children("span").slideDown(200);
		},
		function() {
			$(this).children("span").slideUp(200);
		}
	);

	//鼠标经过tips效果
	$("#container a").not("#home-album li a").mouseover(function(tips){
		this.tipsTxt = this.title;
		this.tipsTxt = (this.tipsTxt.length>100?this.tipsTxt.toString().substring(0,100)+"...":this.tipsTxt);
			if (this.tipsTxt){
				this.tipsUrl = this.href;
				this.title = '';
				var tips = '<div id="tips"><p>' + this.tipsTxt + '</p><p><em>' + this.tipsUrl + '</em></p></div>';
				$('body').append(tips);
				$('#tips').css({"opacity":"0.8"})
			}
		}).mouseout(function(){
			this.title=this.tipsTxt;
			$('#tips').remove();
		}).mousemove(function(tip){ $('#tips').css({"top":(tip.pageY+22)+"px","left":(tip.pageX-10)+"px"});
	});
	//鼠标经过tips效果结束

	//彩色tag云
	tagColor(".tags a");	

	//新窗口打开
	$(function() { $("a[rel*='external']").attr("target","_blank") });

	//滑动到顶部
	$('#to-top').click(function() { $("html,body,#wrap").animate({ scrollTop: 0 }, 1000); });
	var showDistance = 50;//距离顶端多少距离开始显示to-top
	$(window).scroll(function(){
		if($(this).scrollTop() < showDistance){
			$("#to-top").fadeOut("fast");
		}else{
			$("#to-top").fadeIn("fast");
		}
	});

});

//图片渐显
function TsLazyload(templateUrl) {
	if(window.XMLHttpRequest){
		$(function() {
			$("img").not("#slide-pic img, #side-cmtli-2 img, .gallery img").lazyload({
				placeholder: templateUrl,
				effect: "fadeIn"
			});
		});
	}
}

//闪动联系我
function TsFlicker(getObject,times) {
	if (times == null) times = 5;
	for (i = 0; i<times; i++) {
		$("#" + getObject).fadeOut(200);
		$("#" + getObject).fadeIn(50);
	}
}

//彩色tag
function tagColor(getObject) {
	var colors = ["#0cf","#06f","#900","#990","#f36","#639","#60f","#0c0","#f90","#c66","#6cc","#f0f","#00f","#333"];
	var tags = $(getObject);
	var tagCount = tags.length;
	for ( i=0; i<tagCount; i++ ) {
		n = Math.floor( Math.random() * colors.length );
    	tags.eq(i).css({"color":colors[n]});
	}
}
