﻿(function(){
	
//NewsAdver滚动轮播类

function NewsAdver(args){
	for(var i in args){
		this[i] = args[i];	
	}		
	this.speed = args.speed ? args.speed : 3000;	//间隔时间默认3秒
	this.sTime = args.sTime ? args.sTime : 500;	//渐进时间，默认1秒
	this.load();
	this.start();
}

NewsAdver.prototype = {
	
	load : function(){
		
		var _this = this;
		this.num = 0;	//计时器
		this.mNum = this.num+1;	//轮播计时
		this.sNum = 0;	//滚动时的hover位置
		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
		
		//btn.parent()克隆一份放在下面
		var btnClone = this.btns.parent().clone();
		$("li",btnClone).removeClass("hover");
		btnClone.appendTo(this.btns.parent().parent());
		
		/*
		this.btns.each(function(num){
			$(this).mouseover(function(){
				_this.show(num);	
				_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;	
		
		var scrollPar = this.btns.parent().parent();
		var scrollH = this.btns.height()+parseInt(this.btns.css("margin-bottom"));		
						
		this.interval = setInterval(function(){
								
			if(_this.mNum >= _this.len){
				_this.mNum = 0;
			}	
			
			if(scrollPar.scrollTop() >= _this.btns.parent().height()){				
				scrollPar.scrollTop(0);	
				_this.sNum = 0;
			}
											
			scrollPar.animate({
				scrollTop : scrollPar.scrollTop()+scrollH	
			});	
			
										
			_this.show(_this.mNum);		
			
			_this.sNum++;
			
			$("li",scrollPar).removeClass("hover");
			$($("li",scrollPar)[_this.sNum]).addClass("hover");
			
								
		},this.speed);
		
	},
	stop : function(){
		clearInterval(this.interval);
	}	
	
};

window.NewsAdver = NewsAdver;

//NewsAdver滚动轮播类

})();

$(function(){

	//index_banner轮播效果
	$(".index_banner .big li").each(function(){
		$(this).css("background-image","url("+$(this).attr("bg")+")");	
	});
	new FadeAdver({
		btns : $(".index_banner .btns span"),
		divs : $(".index_banner .big li"),
		speed :10000	
	});
	
	//news_adver轮播开始
	new NewsAdver({
		btns : $(".news_adver .btn li"),
		divs : $(".news_adver .big li")	
	});
	
	//active_adver鼠标hover效果
	
	
	/*旧的
	new FadeAdver({
		btns : $(".active_adver .btn span"),
		divs : $(".active_adver .adv"),
		speed :5000	
	});
	*/
	
	var active_adv0 = $(".active_adver .adv_0");
	var active_adv1 = $(".active_adver .adv_1");
	var active_adv2 = $(".active_adver .adv_2");
	
	var adv0_time;
	var adv1_time;
	var adv2_time;
	var count = 0;

	var lunbo = setInterval(function(){
		if (count == 3) {
			count = 0;
		}
		$(".adv_" + count).fadeIn(1000);
		$(".adv_" + count).siblings().fadeOut(1000);
		count++;
	}, 3000);
	/*function showAdv1(){

		adv1_time = setTimeout(function(){

			active_adv1.fadeOut(1000);
			active_adv2.fadeIn(1000,function(){

				adv2_time = setTimeout(function(){
					active_adv2.fadeOut(1000);
					active_adv1.fadeIn(1000,function(){
						showAdv1();
					});
				},3000);

			});

		},6000);
		
	}

	adv1_time = setTimeout(function(){

		active_adv1.fadeOut(1000);
		active_adv2.fadeIn(1000,function(){

			adv2_time = setTimeout(function(){
				active_adv2.fadeOut(1000);
				active_adv1.fadeIn(1000,function(){
					showAdv1();
				});
			},3000);

		});

	},6000);*/

	$(".active_adver").hover(function(){		
		clearTimeout(adv1_time);	
		clearTimeout(adv2_time);	
		clearInterval(lunbo);

	},function(){		
		/*adv1_time = setTimeout(function(){
		
			active_adv1.fadeOut(1000);	
			active_adv2.fadeIn(1000,function(){
				
				adv2_time = setTimeout(function(){
					active_adv2.fadeOut(1000);	
					active_adv1.fadeIn(1000,function(){
						showAdv1();	
					});	
				},3000);
					
			});	
			
		},1000);*/
		lunbo = setInterval(function(){
			if (count == 3) {
				count = 0;
			}
			$(".adv_" + count).fadeIn(1000);
			$(".adv_" + count).siblings().fadeOut(1000);
			count++;
		}, 3000);
	});
	
	
	$(".active_adver .adv_1 a").each(function(){
		var h = $(this).height()+46;
		var w= $(this).width();
		$("span",this).height(h);
		$("span",this).width(w);	
	});
	
	$(".active_adver .adv_1 a").hover(function(){		
		$(".active_adver .adv_1 a span").show();
		$("span",this).hide();
	},function(){
		$(".active_adver .adv_1 a span").hide();
	});
	
	//active_aside的hover效果
	
	var aside_adver_num = 0;
	var aside_adver_time;
	var aside_ads = $(".aside_adver .ad");
	
	function runAsInter(){
		
		aside_adver_time = setInterval(function(){		
			var tNum;		
			
			$(aside_ads[aside_adver_num]).animate({"width":74},"fast",function(){
				$(this).removeClass("hover");	
			});
			
			if(aside_adver_num == 2){
				tNum = 0;	
			}else{
				tNum = aside_adver_num + 1;
			}
			
			$(aside_ads[tNum]).animate({"width" : 170},"fast",function(){
				$(this).addClass("hover");	
			});
							
			aside_adver_num++;
			if(aside_adver_num >= 3){
				aside_adver_num = 0;	
			}		
			
		},5000);	
		
	}
	
	function clearAsInter(){
		clearInterval(aside_adver_time);	
	}
	//runAsInter();
	
	
	
	aside_ads.each(function(num){
		
		$(this).mouseover(function(){	
			var _this = this;	
						
			//clearAsInter();
			
			if(num == aside_adver_num){
				return false;		
			}
			
			
			$(aside_ads[aside_adver_num]).animate({"width":74},"fast",function(){
				$(this).removeClass("hover");	
				$("span",this).show();
			});
			
			$("span",this).fadeOut("fast");
			$(this).animate({"width" : 170},"fast",function(){
				$(_this).addClass("hover");	
			});
			
			aside_adver_num = num;
		});	
		
		$(this).mouseout(function(){
			//runAsInter();	
		});
		
	});
	
	//active_data轮播
	new FadeAdver({
		btns : $(".active_data .change span"),
		divs : $(".active_data .con"),
		speed :5000	
	});

	//welcome广告开始
	
	showWelcome();

});	