// JavaScript Document by daviguoshuang at gmail.com

/////////////////////////////////for homepage only////////////////////////////////

var currenSlogan=1; //from 1 start
var sloganDelay=5000; //time delay ms time for auto play
var sloganDelayTimer; 
var boardIndex=0;
var boardTimer;
var boardDelay=6000;//秒切换
var activeSlideTimer;
var nowSpan=0;
var activeDelay=5000;//active slide delay
var h3TabsTimer;
var hover3Delay=300;


jQuery(function($){	
//jQuery(window).load(function(){  //fix chrome bug for jquery ready
//////////////////
//oBoard
var oBoard=$('#subMenu .board');
var boardNum=oBoard.find('li').length;

function boardScroll(){
	boardTimer=setInterval(function(){
		oBoard.find('li').css({display:'none'}).hide();
		oBoard.find('li:eq('+boardIndex+')').show().css({opacity:0}).animate({opacity:1},1000);
		boardIndex+=1;
		if(boardIndex>boardNum-1){boardIndex=0}
	},boardDelay);
}

boardScroll();

oBoard.mouseenter(function(){clearInterval(boardTimer);}).mouseleave(function(){boardScroll();})
//splash
$('#gSplash').prepend('<div class="toLeft" title="上一张"></div><div class="toRight" title="下一张"></div>')

if(parseInt($.browser.version)<7&&$.browser.msie){ //ie 6 

	$('#gSplash .toLeft').hide();
	$('#gSplash .toRight').hide();

	$('#gSplash .splashUl li').mousemove(function(e){
		leftSize=e.pageX-$(this).offset().left;
		var oWidth=$(this).width()
		var oParent=$(this).parents('#gSplash');
		if(leftSize<oWidth/2){oParent.find('.toLeft').show();oParent.find('.toRight').hide();}
		else{oParent.find('.toLeft').hide();oParent.find('.toRight').show();}
		clearInterval(sloganDelayTimer);
	})
	
	$('#gSplash').mouseleave(function(){
		$(this).find('.toLeft').hide();
		$(this).find('.toRight').hide();
		clearInterval(sloganDelayTimer);sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay);
	})

}else{

	$('#gSplash .toLeft').css({opacity:0}).show()
	$('#gSplash .toRight').css({opacity:0}).show()
	
	$('#gSplash .splashUl li').mousemove(function(e){
		leftSize=e.pageX-$(this).offset().left;
		var oWidth=$(this).width()
		var oParent=$(this).parents('#gSplash');
		if(leftSize<oWidth/2){oParent.find('.toLeft').stop().animate({opacity:1});oParent.find('.toRight').stop().animate({opacity:0});}
		else{oParent.find('.toLeft').stop().animate({opacity:0});oParent.find('.toRight').stop().animate({opacity:1});}
		//e.stopPropagation()
		clearInterval(sloganDelayTimer);
	})
	
	$('#gSplash').mouseleave(function(){
		$(this).find('.toLeft').stop().animate({opacity:0});
		$(this).find('.toRight').stop().animate({opacity:0});
		clearInterval(sloganDelayTimer);sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay);
	})
}

//从边上中间进来，进入 left right 却不算进入 gSplash
$('#gSplash .toLeft,#gSplash .toRight').mouseenter(function(){
	$(this).stop().animate({opacity:1});
})

//slogan code is here by davdiguoshuang at gmail.com
$('#gSplash .splashPager').append('<div id="slogWizard" style="top:0;left:32px"></div>');

var testabc=1;

function sloganAutoPlay(){

//chrome 越来越快？为何？
//console.log('sloganDelayTimer='+sloganDelayTimer);
//console.log('sloganDelay='+sloganDelay);
testabc+=1;
//console.log(testabc)

	$('#gSplash .splashUl li').hide();
	currenSlogan+=1;
	if(currenSlogan==5){currenSlogan=1;}
	$('#gSplash .splashUl li:nth-child('+currenSlogan+')').fadeIn(400);
	/*4 wizard*/
	oleft=80*currenSlogan-48;
	$('#slogWizard').stop().animate({left:oleft+'px'},400,'easeOutBack');
}

sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay); 


var totalSlogan=$('.splashUl li').length;

$('.toRight').click(function(){
	$('#gSplash .splashUl li').hide();
	currenSlogan+=1;
	if(currenSlogan==totalSlogan+1){currenSlogan=1;}
	$('#gSplash .splashUl li:nth-child('+currenSlogan+')').fadeIn(400);
	/*4 wizard*/
	oleft=80*currenSlogan-48
	$('#slogWizard').animate({left:oleft+'px'},400,'easeOutBack')
	clearInterval(sloganDelayTimer);sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay);
})

$('.toLeft').click(function(){
	$('#gSplash .splashUl li').hide();
	currenSlogan-=1;
	if(currenSlogan==0){currenSlogan=totalSlogan;}
	$('#gSplash .splashUl li:nth-child('+currenSlogan+')').fadeIn(400);
	/*4 wizard*/
	oleft=80*currenSlogan-48	
	$('#slogWizard').animate({left:oleft+'px'},400,'easeOutBack')
	clearInterval(sloganDelayTimer);sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay);
})

$('#gSplash .splashPager').find('li').click(function(){
	oleft=$(this).parent().find('li:first').width();
	oleft=80*($(this).index()+1)-48	
	$('#slogWizard').animate({left:oleft+'px'},400,'easeOutBack')
	/*switch*/
	$('#gSplash .splashUl li').hide();
	currenSlogan=$(this).index()+1;
	$('#gSplash .splashUl li:nth-child('+currenSlogan+')').fadeIn(400);
	clearInterval(sloganDelayTimer);sloganDelayTimer=setInterval(sloganAutoPlay,sloganDelay);
})

//active 
$('.activeHome ul').hide();
$('.activeHome ul:first').show();

$('.activeHome').append('<div class="pagerDiv"><span class="topic current a1""><span class="p9"></span></span><span class="a2 topic"><span class="p9"></span></span><span class="a3 topic"><span class="p9"></span></span></div>');



$('.activeHome .pagerDiv .topic').live('mouseenter',function(){
	$(this).siblings().removeClass('current').end().addClass('current');
	index=$(this).index()+1;
	$('.activeHome ul:visible li').hide();
	$('.activeHome ul:visible li:nth-child('+index+')').show();
})
function getAcTopic(){
	$('.activeHome .pagerDiv span').each(function(i){
		$('.activeHome .pagerDiv span.a'+(i+1)+' .p9').text($('.activeHome ul:visible li:nth-child('+(i+1)+') .i1 .f14').text());
	})
	
}

getAcTopic();
function changeTabs(obj,index){

	h3TabsTimer=setTimeout(function(){		
		sec=obj.parents('.sec');		
		sec.find('ul').hide();
		sec.find('ul:eq('+index+')').show();
		obj.parent().find('span').removeClass('current');
		obj.addClass('current');
		
		nowSpan=0;
		clearInterval(activeSlideTimer);
		sec.find('.pagerDiv span').removeClass('current');
		sec.find('.pagerDiv span:first').addClass('current');
		sec.find('ul:visible').css({'margin-left':0});
		//activeSlide();
		getAcTopic();
		},hover3Delay);
}

$('h2.th3 .h2Tabs span a').mouseenter(function(){
	clearInterval(h3TabsTimer);
	changeTabs($(this).parent(),$(this).parent().index());
}).mouseleave(function(){
	clearInterval(h3TabsTimer);
})

$('.hTeam ul:first').css({display:'block'}).show();//先  css 再  show 否则 firefox 有bug

//新鲜事
var freshNews=$('#freshDiv .freshNews');

function checkFresh(){
	//fix ie cache bug of ajax!or use ajax(){cache:false}
	//$.get("fresh.php?"+new Date().getTime(), function(data) {
	//		freshNews.find('li:last').remove();
	//		freshNews.prepend(data);
	//		freshNews.find('li:first').css({opacity:0}).animate({opacity:1});
	//})
}

var freshDelay=5000;//5000毫秒刷新 新鲜事
//var freshTimer = setInterval(checkFresh,freshDelay);

freshNews.mouseenter(function(){
//	clearInterval(freshTimer);
}).mouseleave(function(){
	//freshTimer = setInterval(checkFresh,freshDelay);
})


//////////////////	
})
