﻿(function(){
	
//清除所有input的value
	function ClearValue(forms){
		this.forms = forms;
		this.load();	
	}
	
	ClearValue.prototype = {
		constructor : this,
		load : function(){
			var _this = this;			
			this.forms.each(function(){
				_this.clearValue($(this));	
			});
		},
		clearValue : function(fm){			
			this.inputs = $("input.text,input.keyword",fm);
			this.textarea = $("textarea",fm);
			var _this = this;
			var dValues = [];	
			var aValues = [];		
			this.inputs.each(function(n){
				dValues[n] = $(_this.inputs[n]).val();
			});
			this.textarea.each(function(n){
				aValues[n] = $(_this.textarea[n]).html();
			});
						
			this.inputs.each(function(n){
				$(this).focus(function(){
					if($(this).val() == dValues[n]){
						$(this).val("");	
					}
				});	
				$(this).blur(function(){
					if($(this).val() == ""){
						$(this).val(dValues[n]);	
					}	
				});
			});	
			this.textarea.each(function(n){
				$(this).focus(function(){
					if($(this).html() == aValues[n]){
						$(this).html("");	
					}
				});	
				$(this).blur(function(){
					if($(this).html() == ""){
						$(this).html(aValues[n]);	
					}	
				});	
			});
		}	
	};
	
	window.ClearValue = ClearValue;
	//清除所有input的value
	
//顶端adver渐隐
	
function FadeAdver(args){
	for(var i in args){
			this[i] = args[i];	
		}	
		this.speed = args.speed ? args.speed : 3000;	//间隔时间默认3秒
		this.sTime = args.sTime ? args.sTime : 800;	//渐进时间，默认0.8秒
		this.load();
		this.start();
}

FadeAdver.prototype ={
	constructor : this,
	load : function(){
		var _this = this;
		this.num = 0;	//计时器
		this.mNum = this.num+1;	//轮播计时
		this.len = this.divs.length;					
		
		//所有div设置absolute并排好index
		this.divs.each(function(num){
			var z_index = 500-num;
			$(this).css({
				"position" : "absolute",
				"left" : 0,
				"top" : 0,
				"z-index" : z_index,
				"display" : "none"	
			})
		});
		
		$(this.divs[0]).show();
		
		//所有div设置absolute并排好index
		
			
		this.btns.each(function(num){
			$(this).mouseover(function(){
				_this.show(num);	
				_this.stop();				
			}).mouseout(function(){
				_this.start();	
			});	
		});
		
		//左右按钮的使用
		if(!!this.preBtn && !!this.nextBtn){
			this.preBtn.css("z-index",1000);
			this.preBtn.click(function(){
				var num = _this.num - 1;
				if(num < 0){
					num = _this.len-1;		
				}	
				_this.show(num);
			});	
			this.nextBtn.css("z-index",1000);
			this.nextBtn.click(function(){
				var num = _this.num + 1;
				if(num >= _this.len){
					num = 0;		
				}	
				_this.show(num);
			});	
		}
		
		this.divs.each(function(num){
			$(this).mouseover(function(){					
				_this.stop();				
			}).mouseout(function(){
				_this.start();	
			});	
		});
	},
	show : function(num){
		if(num == this.num) return;	//同一个返回
		
		
		var _this = this;
		this.flag  = false;	//关闭控制开关
		this.btns.each(function(i){
			if(i == num){
				$(this).addClass("hover");	
			}else{
				$(this).removeClass("hover");	
			}				
		});
				
		$(this.divs[this.num]).fadeOut(this.sTime);	//旧的淡出
						
		$(this.divs[num]).fadeIn(_this.sTime);		//新的淡入
		_this.num = num;	
		_this.mNum = num+1;			
				
	},
	start : function(){
		var _this = this;					
		this.interval = setInterval(function(){					
			if(_this.mNum >= _this.len){
				_this.mNum = 0;
			}						
			_this.show(_this.mNum);								
		},this.speed);
	},
	stop : function(){
		clearInterval(this.interval);
	}	
};

window.FadeAdver = FadeAdver;
//顶端adver	

//ChangeDiv切换效果
function ChangeDiv(args){
	for(var i in args){
		this[i] = args[i];	
	}	
	this.type = this.type ? this.type : "mouseover";
	this.load();
}

ChangeDiv.prototype = {
	constructor : this,
	load : function(){
		var _this = this;
		this.btns.each(function(num){
			if(_this.type == "click"){
				$(this).click(function(){
					_this.change(num)	
				});		
			}else{
				$(this).mouseover(function(){
					_this.change(num)	
				});		
			}			
		});	
	},
	change : function(num){
		var _this = this;
		
		this.btns.each(function(n){
			if(n ==num){
				$(this).addClass("hover");		
			}else{
				$(this).removeClass("hover");		
			}				
		});
		
		this.divs.each(function(n){
			if(n ==num){
				$(this).addClass("show");		
			}else{
				$(this).removeClass("show");		
			}				
		});
	}	
};

window.ChangeDiv = ChangeDiv;
//ChangeDiv切换效果

//PopWindow弹窗类
	
	function PopWindow(args){
		for(var i in args){
			this[i] = args[i];	
		}	
		this.flog = this.flog ? this.flog : $(".flog2");
		this.load();
	}
	
	PopWindow.prototype = {
		load : function(){
			var _this = this,
			      dW = $(window).width(),
			      dH = $(document.body).height();					      			      
			 this.flog.css({
			 	width : dW,
			 	height : dH
			 });
			 this.btn.click(function(evt){
			 	evt.preventDefault();
			 	_this.show();	
			 });
			 $(".close",this.popDiv).click(function(evt){
			 	evt.preventDefault();
			 	_this.close();	
			 });	
			 	
			 $(".flog2").click(function(evt){
			 	evt.preventDefault();
			 	_this.close();	
			 });	 	
		},
		show : function(){		
			var pL = ($(window).width() - this.popDiv.width())/2 + $(window).scrollLeft(),
			      pT = ($(window).height()-this.popDiv.height())/2+$(window).scrollTop();			    
			 this.popDiv.css({
			 	left : pL,
			 	top : pT	
			 });	
			this.popDiv.show();
			this.flog.show();			
		},
		close : function(){
			this.popDiv.hide();
			this.flog.hide();
		}	
	};
	
	window.PopWindow = PopWindow;
//PopWindow弹窗类

//showWelcome欢迎光临

function showWelcome(){
	var closeTime;
	var dW =  $(window).width(),
      dH = $(document.body).height();					      			      
	$(".flog").css({
	 	width : dW,
	 	height : dH,
	 	"display" : "block"
	 });
	 
	var welLeft =  (dW-$(".welcome").width())/2;
	var welTop = ($(window).height()-$(".welcome").height())/2+$(window).scrollTop();	
	
	if(welTop < 0){
		welTop = 0;	
	}
	
	$(".welcome").css("left",welLeft);
	$(".welcome").css("top",welTop);
	
	
	
	$(".welcome").fadeIn(1500,function(){
		closeTime = setTimeout(closeWelcome,12000);		
	});
	
	$(".welcome").hover(function(){
		clearTimeout(closeTime);	
	},function(){
		closeTime = setTimeout(closeWelcome,1000);	
	});
	
	$(".welcome .close").click(function(){
		closeWelcome();	
	});
	
	$(".flog").click(function(){
		closeWelcome();	
	});
			
}

function closeWelcome(){	
	$(".welcome").fadeOut(500);
	$(".flog").fadeOut(1500);
}

window.showWelcome = showWelcome;

})();

$(function(){
	
	//顶部时间
	
	function getCurDate(){
		var d = new Date();
		var week;
		switch (d.getDay()){
		case 1: week="星期一"; break;
		case 2: week="星期二"; break;
		case 3: week="星期三"; break;
		case 4: week="星期四"; break;
		case 5: week="星期五"; break;
		case 6: week="星期六"; break;
		default: week="星期天";
	}
		var years = d.getFullYear();
		var month = add_zero(d.getMonth()+1);
		var days = add_zero(d.getDate());
		var hours = add_zero(d.getHours());
		var minutes = add_zero(d.getMinutes());
		var seconds=add_zero(d.getSeconds());
		var ndate = years+"年"+month+"月"+days+"日 "+week+" "+hours+":"+minutes;
		$(".nav p").html(ndate);
	}
		
		function add_zero(temp)
		{
		if(temp<10) return "0"+temp;
		else return temp;
		}
	
	getCurDate();		
	setInterval(getCurDate,1000);

	//二级nav下拉
	$(".nav_in").hover(function(){
		$(".nav_child",this).fadeIn("2500");
	},function(){
		$(".nav_child",this).fadeOut("1500");
	});
	
	//tabs的统一调用
	$(".tabs").each(function(){
		new ChangeDiv({
			btns : $(".change span",this),
			divs : $(".con",this)	
		});	
	});
	
	//nav_slide的二级分类
	$(".nav_aside>ul>li>a").click(function(){
		var par = $(this).parent();	
		
		if($("ul",par).length == 0){
			return;	
		}		
		
		if(!par.hasClass("hover")){
			$(".nav_aside>ul>li").removeClass("hover");
			par.addClass("hover");	
		}else{
			par.removeClass("hover");		
		}	
		
	});
	
	//同步aside和section的高度
	if($(".nav_aside").height()+15 < $(".section").height()+40){
		$(".nav_aside").height($(".section").height()+25);	
	}
	
	//we_chart微信弹窗
	
	new PopWindow({
		btn : $(".footer .w_2"),
		popDiv  : $(".we_chart_pop")	
	});

});	




function send() {
	<!--self.location.href = "blnews1.html?id=123";-->
	var img=document.getElementById("MyImg").src;
	//img=img.substring(img.indexOf("paper")+6);
	window.open("/paper_show.html?id="+img)
}
function Stroke(){

	if(document.getElementById("textfiled").value==""){
		document.getElementById("textfiled").placeholder="请输入搜索内容！";
		return false;
	}
	return true;
}



