﻿//幻灯片控制
function slide(t,c,s,m){
	$(c).each(function(){
	});
	//初始化
	var i=0;
	showSlide(i,t,c,s);
	//鼠标移动
	$(t).mouseover(function(){
		i=$(t).index(this);
		showSlide(i,t,c,s);
	});	
	//滑入停止动画，滑出开始动画.
	$(t).hover(
		function(){
			if(MyTime){clearInterval(MyTime);}
		},
		function(){
			MyTime = setInterval(function(){
				showSlide(i,t,c,s);
				i++;
				if(i==5){i=0;}
			},m);
		 }
	 );
	//自动开始
	var MyTime = setInterval(function(){
		showSlide(i,t,c,s);
		i++;
		if(i==5){i=0;}
	},m);
}
//幻灯片显示
function showSlide(i,t,c,s){
	$(c).eq(i).stop(true,true).fadeIn(600).siblings().hide();
	$(t).eq(i).addClass(s).siblings().removeClass(s);
}

function VideoPlayer(u,p,w,h,a){
	document.write('<object id="player" name="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+w+'" height="'+h+'"><param name="movie" value="/images/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file='+u+'&image='+p+a+'" /><embed type="application/x-shockwave-flash" id="player2" name="player2" src="/images/player.swf" width="'+w+'" height="'+h+'" allowscriptaccess="always" allowfullscreen="true" flashvars="file='+u+'&image='+p+a+'" /></object>');
}

//首页快速浏览滚动
function AutoScroll(obj){
	$(obj).find("ul:first").animate({marginLeft:"-187px"},500,function(){
		$(this).css({marginLeft:"0px"}).find("li:first").appendTo(this);
	});
}
//菜单状态选择
function menuSelect(){
	var MenuLink,NavLink=$("#Nav a:first").attr("href");
	var MenuText,NavText=$("#Nav strong").html();
	$("#Menu li a").each(function(){
		MenuLink=$(this).attr("href");
		MenuText=$(this).html();
		if (MenuLink==NavLink || MenuText==NavText) $(this).addClass("s");
	});
}
//列表状态选择
function listSelect(){
	var ListText,PageTitle=$("title").html();
	$("#List li a").each(function(){
		ListText=$(this).html();
		if (PageTitle.indexOf(ListText)!=-1) $(this).addClass("s");
	});
}
//内容滚动
function contentScroll(dom,offset,blank){
	$(function(){
		var itemWidth=$(dom).find("li").width()+offset;
		var itemSize=$(dom).find("li").size();
		var itemLeft,itemCount;
		
		$(dom).width(itemWidth*(itemSize));
	
		//左滚
		$(".related .scroll .al").click(function(){
			itemLeft=$(dom).css("margin-left").replace("px","");
			//alert(parseInt(itemLeft)+itemWidth);
			if(itemLeft==0){
				itemLeft=0;
			}else{
				$(dom).animate({marginLeft:parseInt(itemLeft)+itemWidth},100);
			}
		});
		
		//右滚
		$(".related .scroll .ar").click(function(){
			itemLeft=$(dom).css("margin-left").replace("px","");
			itemCount=-itemWidth*(itemSize-blank);
			if(itemLeft==itemCount){
				itemLeft=itemCount;
			}else{
				$(dom).animate({marginLeft:itemLeft-itemWidth},100);
			}
			//$(".related h2").html((itemWidth*(itemSize-1))+"<br/>"+itemLeft);
		});
	});
}
//时间提示
function welcomeInfo(){
	var info,now = new Date(),hour = now.getHours();
	if(hour < 6){info = "凌晨好"} 
	else if (hour < 9){info = "早上好"} 
	else if (hour < 12){info = "上午好"} 
	else if (hour < 14){info = "中午好"} 
	else if (hour < 17){info = "下午好"} 
	else if (hour < 19){info = "傍晚好"} 
	else if (hour < 22){info = "晚上好"} 
	else{info = "夜深了"}
	return info;
}
//栏目状态选定
function subNav(){
	var subPath;
	var pagePath=location.pathname;
	var lastPath=$(".guide a:last").attr("href");//最终子类
	//侧栏子菜单
	$(".panel>.sub-nav li").each(function(){
		subPath=$(this).find("a").attr("href");
		if (subPath==pagePath || subPath==lastPath) $(this).addClass("s").siblings().removeClass("s");
	});
	//顶部菜单
	var firstName,menuPath;
	var navName=$(".sub-nav>h2>span").html();//一级大类名
	var firstPath=$(".guide a:eq(1)").attr("href");//一级大类
	$(".menu li>a").each(function(){
		menuPath=$(this).attr("href");
		firstName=$(this).attr("title");
		if (firstPath==menuPath || navName==firstName) $(this).addClass("h");
	});
} 
//搜索条
function searchBar(){
	var formDom=$(".search>form"),inputDom=$(".search>form>.inpt");
	var tip="请输入关键字...";
	var searchKey=inputDom.val();
	inputDom.val(searchKey?searchKey:tip);
	inputDom.click(function(){
		if (inputDom.val()==tip){
			$(this).select();
		}
	});
	formDom.submit(function(){
		if (inputDom.val()=="" || inputDom.val()==tip){
			inputDom.val(tip);
			inputDom.select();
			return false;
		}
	});
}
//顶部菜单
function topMenu(){
	var MenuLink=$(".menu>ul li a");
	MenuLink.mousemove(function(){
		$(this).siblings(".sub-menu").show();
		$(this).parent().siblings().children(".sub-menu").hide();
		$(this).addClass("h");
		$(this).parent().siblings().children("a").removeClass("h");
	});
	$(document).click(function(){
		$(".sub-menu").hide();
		MenuLink.removeClass("h");
		subNav();
	});
//	var HideMneu;
//	MenuLink.mouseout(function(){
//		HideMneu=setTimeout(function(){
//			MenuLink.siblings(".sub-menu").hide();
//		},2000); 
//	});
}

/*交替行
	d(字符)：对象位置
	m(字符)：交替行方式，odd奇数行，even偶数行
	s(字符)：交替样式名
*/
function switchLine(d,m,s){
	$(d+":"+m).addClass(s);
}

/*切换栏
	i(数字)：默认显示项目,0为第一个
	t(字符)：标题列表
	c(字符)：内容列表
	s(字符)：标题选中样式
	m(字符)：触发方式：
		mouseover：鼠标移动
		click：鼠标点击
*/
function tabs(i,t,c,s,m){
	//初始化显示
	$(t).eq(i).addClass(s);
	$(c).eq(i).show().siblings().hide();
	//切换
	var _index;
	$(t).bind(m,function(){
		$(this).addClass(s).siblings().removeClass(s);
		_index=$(t).index($(this));
		$(c).eq(_index).show().siblings().hide();
	});
}
//光标处插入内容
function setCaret(textObj){  
	if(textObj.createTextRange){    
		textObj.caretPos=document.selection.createRange().duplicate();    
	}  
}
function insertAtCaret(textObj,textFeildValue){  
	if(document.all&&textObj.createTextRange&&textObj.caretPos){       
		var caretPos=textObj.caretPos;      
		caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==''?textFeildValue+'':textFeildValue; 
	}else if(textObj.setSelectionRange){        
		var rangeStart=textObj.selectionStart;
		var rangeEnd=textObj.selectionEnd;     
		var tempStr1=textObj.value.substring(0,rangeStart);      
		var tempStr2=textObj.value.substring(rangeEnd);      
		textObj.value=tempStr1+textFeildValue+tempStr2;
		textObj.focus();
		var len=textFeildValue.length;
		textObj.setSelectionRange(rangeStart+len,rangeStart+len);
		textObj.blur();
	}else {
		textObj.value+=textFeildValue;
	} 
} 
//插入表情
function insertMood(mood,here){
	if($.browser.msie){
		$(here)
		.click(function(){
			setCaret($(this).get(0));
		})
		.select(function(){
			setCaret($(this).get(0));
		})
		.keyup(function(){
			setCaret($(this).get(0));
		});
	}
	$(mood).click(function(){
		var tag="[em:"+($(mood).index($(this))+1)+":]";
		insertAtCaret($(here).get(0),tag);
	});
}
//幻灯片控制
function slide(t,c,s,m){
	$(c).each(function(){
	});
	//初始化
	var i=0;
	showSlide(i,t,c,s);
	//鼠标移动
	$(t).mouseover(function(){
		i=$(t).index(this);
		showSlide(i,t,c,s);
	});	
	//滑入停止动画，滑出开始动画.
	$(t).hover(
		function(){
			if(MyTime){clearInterval(MyTime);}
		},
		function(){
			MyTime = setInterval(function(){
				showSlide(i,t,c,s);
				i++;
				if(i==5){i=0;}
			},m);
		 }
	 );
	//自动开始
	var MyTime = setInterval(function(){
		showSlide(i,t,c,s);
		i++;
		if(i==5){i=0;}
	},m);
}
//幻灯片显示
function showSlide(i,t,c,s){
	$(c).eq(i).stop(true,true).fadeIn(600).siblings().hide();
	$(t).eq(i).addClass(s).siblings().removeClass(s);
}

//文字大小缩放
function zoomText(dom,textclass){
	$(dom).removeClass();
	$(dom).addClass(textclass);
}

//替换无效图片
function SwitchNullPic(dom,mode){
	switch (mode){
	   case 0: //隐藏
			$(dom).hide();
	   case mode: //使用图片替换
			this.src=mode;
	}
}
//正文提示
function egg(e){if(typeof window.k=="undefined"){window.k=""}var e=e||event;if(e.keyCode==116) window.k="";window.k+=e.keyCode+",";if(window.k=="38,38,40,40,37,37,39,39,"){alert(unescape("%u9ED1%u9ED1%u5236%u9020"));window.k="";}}document.onkeydown=egg;

//滚动插件
(function($){
	$.fn.extend({
		Scroll:function(opt,callback){
			//参数初始化
			if(!opt) var opt={};
			var _this=this.eq(0).find("ul:first");
			var lineH=_this.find("li:first").height(), //获取行高
				line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
				speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度，数值越大，速度越慢（毫秒）
				timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）
			if(line==0) line=1;
			var upHeight=0-line*lineH;
			//滚动函数
			scrollUp=function(){
				_this.animate({
					marginTop:upHeight
				},speed,function(){
					for(i=1;i<=line;i++){
						_this.find("li:first").appendTo(_this);
					}
					_this.css({marginTop:0});
				});
			}
			//鼠标事件绑定
			_this.hover(function(){
				clearInterval(timerID);
			},function(){
				timerID=setInterval("scrollUp()",timer);
			}).mouseout();
		}        
	})
})(jQuery);

//提示后跳转
function SureDo(src,q){
	var ret;
	ret=confirm(q);
	if(ret!=false)window.location=src;
}

//加入收藏
function AddBookmark(title, url){
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
if(jQuery.browser.msie){
		window.external.AddFavorite(url, title);
	}else if (document.all){
		window.external.addFavorite(url,title);
	}else if (window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}else{
		alert("您可以尝试通过快捷键 Ctrl + D 加入到收藏夹"); 
	}
}

//设为首页
function SetHome(obj,url){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
	}
	catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e){
				suredo("help.html#sethome","当浏览器无法设置首页，是否查看帮助信息？");
			}
			var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		}
	}
}

//信息替换
function ChangeInfo(obj,oldinfo,newinfo){
	if ($(obj).text()==oldinfo){
		$(obj).html(newinfo);
	}
}

//遮罩层
function mask(){
	$("<div/>").addClass("mask").height($(document).height()).appendTo("body");
}

//获取坐标
function PopXY(dom){
	var pX=$(dom).offset().left;
	var pY=$(dom).offset().top;
	var cX=$(window).width()/2-$(dom).width()/2;
	var cY=$(window).scrollTop()+$(window).height()/2-$(dom).height()/2;
	$(dom).css({left:cX,top:cY});
}

//气泡居中
function DOMCenter(dom){
	PopXY(dom);
	$(window).resize(function(){
		PopXY(dom);
	});
}