$("document").ready(function(){
	//双击文档快速导航
	$(this).dblclick(function(){
		if(document.getElementById("quickPlane")){return;}
		var plane=$('<div id="quickPlane"></div>')
			.css({
				"width":"100%",
				"height":$(document).height()+"px",
				"background-color":"#000000",
				"position":"absolute",
				"z-index":"8888",
				"top":"0",
				"left":"0",
				"opacity":"0.8"
			})
			.click(function(){$("#quickNav").css("display","none");$("#quickBox").remove();$(this).remove();});
		$("body").append(plane);
		$("#quickNav").css("display","block");
	});


	//文章搜索
	var keyword=$("#keyword");
	keyword.keypress(function(e){
		var ev=e||window.event;
		if(keyword.val()!="" && ev.keyCode==13){
			if($ .browser.msie){window.open('http://www.baidu.com/s?wd='+keyword.val()+' site:178.com');}
			else{window.open('http://www.baidu.com/s?ie=UTF-8&wd='+keyword.val()+' site:178.com');}
		}
	}).mouseover(function(){this.select();});
	$("#searchbtn").click(function(){
		if(keyword.val()!=""){
			if($ .browser.msie){window.open('http://www.baidu.com/s?wd='+keyword.val()+' site:178.com');}
			else{window.open('http://www.baidu.com/s?ie=UTF-8&wd='+keyword.val()+' site:178.com');}
		}
	});



	//日历
	var year=new Date().getFullYear();
	var month_a=new Date().getMonth()+1;
	var month=month_a<10?'0'+month_a:month_a;
	var date_a=new Date().getDate();
	var date=date_a<10?'0'+date_a:date_a;
	var calendar=$(".calendar ol li");
	var calendarbox=$(".calendarbox");
	$("#today").html('今天是：'+year+'年'+month+'月'+date+'日').mouseover(function(){
		calendarbox.removeClass("here");
		calendar.removeClass("here")
		.each(function(i,o){
			var that=$(o);
			if(that.find("span").html()==(month+"."+date)){that.addClass("here");calendarbox.eq(i).addClass("here");}
		});
	});
	calendar.each(function(i,o){
		var that=$(o);
		if(that.find("span").html()==(month+"."+date)){that.addClass("here");calendarbox.eq(i).addClass("here");}
		that.mouseover(function(){calendar.removeClass("here");$(this).addClass("here");calendarbox.removeClass("here").eq(i).addClass("here");});
	});


	//头图开始
	var hotimg={};
	hotimg.me=$("#hotimg");
	hotimg.data=hotimg.me.find(".imgdata span");//图像数据节点
	
	if(hotimg.data.length!=0){//图像数据不为空时执行
		hotimg.size=hotimg.data.length;//图像数据长度
		hotimg.imgbox=hotimg.me.find(".imgbox");//图像框，图像作为背景
		hotimg.title=hotimg.imgbox.find("span");//显示新闻标题
		hotimg.tip=hotimg.me.find(".tip");//显示新闻摘要
		hotimg.thumbnailbox=hotimg.me.find(".thumbnailbox");//预览缩略图
		hotimg.mask=hotimg.me.find(".mask");//缩略图位置指示器
		hotimg.thumbnail=hotimg.me.find(".thumbnail");//缩略图容器
		hotimg.thumbnail.css("width",hotimg.size*100+"px");
		hotimg.index=hotimg.me.find("ol");//轮盘索引
		hotimg.timer=null;//时钟
		hotimg.on=true;//自动播放开关
		hotimg.current=0;//当前轮盘索引

		hotimg.imgbox.css("backgroundImage","url("+hotimg.data.eq(0).attr("i")+")").attr("href",hotimg.data.eq(0).attr("url"));
		hotimg.title.html(hotimg.data.eq(0).attr("title"));
		hotimg.tip.html(hotimg.data.eq(0).html()+'<strong>详细阅读→</strong>').attr("href",hotimg.data.eq(0).attr("url"));
		var str_index="";
		var str_icon="";
		for(var i=0,len=hotimg.data.length;i<len;i++){
			i==0?str_index+="<li class='here'>"+(i+1)+"</li>":str_index+="<li>"+(i+1)+"</li>";
			str_icon+='<span><img src="'+hotimg.data.eq(i).attr("icon")+'" /></span>';
		}
		hotimg.index.html(str_index);
		hotimg.thumbnail.html(str_icon);
		hotimg.index.find("li").each(function(i,o){//鼠标在索引上移动
			$(o).hover(function(){
				window.clearTimeout(hotimg.timer);
				jQuery.fx.off=true;
				if($(this).is(".here")){return;}
				var _index=parseInt(this.innerHTML);
				hotimg.current=(_index==1?hotimg.size-1:_index-2);
				hotimg.on=false;
				hotimg.play();
			},function(){
				jQuery.fx.off=false;
				hotimg.on=true;
				hotimg.timer=window.setTimeout(hotimg.play,"1000");
			});
		});
		hotimg.thumbnail.find("span").each(function(i,o){//鼠标在缩略图上点击
			$(o).click(function(){
				window.clearTimeout(hotimg.timer);
				hotimg.current=(i==0?hotimg.size-1:i-1);
				hotimg.play();
			});
		});

		hotimg.play=function(){
			window.clearTimeout(hotimg.timer);
			hotimg.current=(hotimg.current==hotimg.size-1?0:hotimg.current+1);

			hotimg.imgbox.fadeOut("fast",function(){
				hotimg.imgbox.css("backgroundImage","url("+hotimg.data.eq(hotimg.current).attr("i")+")").attr("href",hotimg.data.eq(hotimg.current).attr("url"));
				hotimg.title.html(hotimg.data.eq(hotimg.current).attr("title"));
				hotimg.tip.html(hotimg.data.eq(hotimg.current).html()+'<strong>详细阅读→</strong>').attr("href",hotimg.data.eq(hotimg.current).attr("url"));
				hotimg.index.find("li").removeClass("here").eq(hotimg.current).addClass("here");
				if(hotimg.on){hotimg.timer=window.setTimeout(hotimg.play,"5000");}

				hotimg.imgbox.fadeIn("fast");
			});

			//缩略图动画
			if((hotimg.current+1)%2!=0){
				hotimg.mask.animate({"left":"0px"},"slow");
				hotimg.thumbnail.animate({"left":"-"+hotimg.current/2*200+"px"},"slow");
			}else{
				hotimg.mask.animate({"left":"100px"},"slow");
				hotimg.thumbnail.animate({"left":"-"+(hotimg.current-1)/2*200+"px"},"slow");
			}
		};
		if(hotimg.size>1){hotimg.timer=window.setTimeout(hotimg.play,"3000");}//如果有1张以上图片就开始轮播
	}
	//头图程序结束

	//选项卡
	var optionTAB=function(t,c){
		t.each(function(i,o){
			$(o).mouseover(function(){
				t.removeClass("here");
				$(this).addClass("here");
				c.removeClass("here").eq(i).addClass("here");
			});
		});
	};
	optionTAB($("div.allgames div.options span"),$("div.allgames .box"));//视频排行
	optionTAB($("div.sort1 ul li"),$("div.sort1.opt .box"));//公会排行榜
	optionTAB($("ul.t1 li"),$("ol.t1"));//一周新闻排行榜
	optionTAB($("ul.t2 li"),$("ol.t2"));//动漫排行榜
	optionTAB($("ul.t3 li"),$("div.t3"));//游戏评测
	optionTAB($("ul.t4 li"),$("div.books"));//小说
	optionTAB($("div.cont3 ul li"),$("div.cont3 ol"));//视频排行
	optionTAB($("ul.t5 li"),$("div.t5"));//小游戏
	optionTAB($(".hotnews li"),$(".hotnews-box"));//头条
	optionTAB($(".tab li"),$(".tab-cont"));//热门活动


	//热点新闻鼠标经过
	$("div.newslist li").hover(function(){$(this).addClass("here");},function(){$(this).removeClass("here");});
	//排行榜鼠标经过
	$("div.sort1 ol li")//新游戏期待榜、网游下载榜、公会榜
		.add("ol.sortlist li")//一周新闻排行榜、其它排行榜
		.add("div.sort2 tbody tr")//网游测试表
		.add("div.marking ol li")//评测排行榜
		.hover(function(){$(this).css("backgroundColor","#f2f2f2");},function(){$(this).css("backgroundColor","transparent");});

	//排行榜图标
	$("div.sort1 ol").each(function(){
		$(this).find("li").each(function(i,o){
			var that=$(o);
			that.css("backgroundPosition","10px -"+(i*22)+"px");
			if(i<=1){that.find("a").css("color","#c40f15");}else if(i>8){that.find("a").css("color","#717171");}
		});
	});

	//排行榜图标
	$("ol.sortlist").each(function(){
		$(this).find("li").each(function(i,o){
			var that=$(o);
			that.css("backgroundPosition","8px -"+(i*24)+"px");
		});
	});

	//视频排行图标
	$("div.cont3 ol").each(function(){
		$(this).find("li").each(function(i,o){
			var that=$(o);
			that.css("backgroundPosition","8px -"+(i*22)+"px");
		});
	});
});

//快速导航
var quickShow=function(str){
	var obj=$(str).eq(0);
	var abs=obj.offset();
	var objBox=$('<div id="quickBox"></div>')
		.css({
			"width":obj.outerWidth(),
			"height":obj.outerHeight(),
			"top":abs.top,
			"left":abs.left,
			"position":"absolute",
			"z-index":"999999",
			"background-color":"#ffffff"
		})
		.append(obj.clone());
	$("body").append(objBox);
	window.scroll(abs.left,abs.top-100);
	$("#quickNav").css("display","none");
};

