$(function(){ 	 

  	//IE6支持PNG
	if($.browser.msie&&$.browser.version=="6.0"){//IE6 
		DD_belatedPNG.fix('.pngBg');
	}
	
	navInit();//导航条初始化
	toggleInit();//首页切换初始化
	tabNavInit();//tabNav初始化
	sideNavInit();//内页左导航条鼠标停留效果
});


function sideNavInit(){

	var mouseover_tid = [];
	var mouseout_tid = [];
	$('.sideNavCenter > ul > li:not(".selected")').each(function(index){ 
		$(this).hover(function(){
			
			var _self = this; // 停止卷起事件 
			clearTimeout(mouseout_tid[index]); // 当鼠标进入超过 0.2 秒, 展开菜单, 并记录到线程 ID 中 
			mouseover_tid[index] = setTimeout(function() { $(_self).children("a").find("img").show();$(_self).children(".sideNavCenterSon").slideDown(); }, 400);
		},function(){
			var _self = this; // 停止展开事件 
			clearTimeout(mouseover_tid[index]); // 当鼠标离开超过 0.2 秒, 卷起菜单, 并记录到线程 ID 中 
			mouseout_tid[index] = setTimeout(function() { $(_self).children("a").find("img").hide();$(_self).children(".sideNavCenterSon").slideUp(); }, 400);
			
		});
	});	
}


function tabNavInit(){
	
	$(".tabNav").each(function(i){
		var $tabCon = $(this).next(".tabCon");
		var $tabNav= $(this);
		$(this).find("li").each(function(n){
			$(this).mouseover(function(){
				$tabNav.find("li").removeClass("selected");
				$(this).addClass("selected");
				$tabCon.find(".tabConMain").hide();
				$tabCon.find(".tabConMain").eq(n).show();
			});
		});
		
	});
}

function navInit(){
	
	
	var mouseover_tids = [];
	var mouseout_tids = [];
	$('.nav > ul > li').each(function(index){ 
		$(this).hover(function(){
			var _self = this; // 停止卷起事件 
			
			clearTimeout(mouseout_tids[index]); // 当鼠标进入超过 0.2 秒, 展开菜单, 并记录到线程 ID 中 
			mouseover_tids[index] = setTimeout(function() {
				$(_self).children("a").find("img").show();
				$(_self).children(".navSon").width($(_self).width());
				 $(_self).children(".navSon").slideDown(); 
			}, 100);
		},function(){
			var _self = this; // 停止展开事件 
			clearTimeout(mouseover_tids[index]); // 当鼠标离开超过 0.2 秒, 卷起菜单, 并记录到线程 ID 中 
			mouseout_tids[index] = setTimeout(function() {$(_self).children("a").find("img").hide();$(_self).children(".navSon").hide(); }, 100);
			
		});
	});	
	
	/*$(".nav > ul > li").each(function(){
		$(this).hover(function(){
			$(this).children(".navSon").show();
			$(this).children(".navSon").width($(this).width());
		},function(){
			$(this).children(".navSon").hide();	
		})	
	});
	*/
}


//切换
function toggleInit(){
	
	nowToggleNum = 1;
	toggleBoxConLi = $(".toggleBoxCon li");
	toggleBoxConLiNum = toggleBoxConLi.size();
	toggleBoxNavA = $(".toggleBoxNav a");
	
	toggleBoxConLi.css({opacity:0});
	toggleBoxConLi.eq(0).css({opacity:1});
	toggleBoxNavA.eq(0).addClass("selected");
	toggleBoxConLi.css({opacity:0,"z-index":"0"});
	toggleBoxConLi.eq(0).css({opacity:1,"z-index":"1"});
	
	var interval = setInterval(checkNum,4000);
	
	toggleBoxNavA.each(function(index){
		$(this).click(function(){
			nowToggleNum = index;
			checkNum();
			clearInterval(interval);
			interval = setInterval(checkNum,4000);
		});					
	});
	
}

function checkNum(){
	
	if(nowToggleNum<toggleBoxConLiNum-1){
		toggle_scroll("");
		nowToggleNum++;
	}else{
		toggle_scroll("");
		nowToggleNum=0;
	}
}

function toggle_scroll(n){
	
	if(n!=""){
		nowToggleNum = n;
	}	toggleBoxConLi.css("z-index","0");
	toggleBoxConLi.eq(nowToggleNum).css("z-index","1");
	toggleBoxConLi.animate({opacity:0},500);
	toggleBoxConLi.eq(nowToggleNum).animate({opacity:1},500);
	
	
	
	$(".toggleBoxNav a.selected").removeClass("selected");
	toggleBoxNavA.eq(nowToggleNum).addClass("selected");
	
}



