// davidguoshuang@gmail.com

jQuery(function($){
////////////////////////////////////

/*menu*/

$('#menu .u2').css({opacity:0.9});

$('#menu .m1>a').mouseenter(function(){
	$('#menu .u2').slideUp('fast');
	$(this).parent().find('.u2').slideDown(300);	
})

$('#menu .u2').mouseleave(function(){
	$(this).hide();	
})

$('#body').mouseenter(function(){
	$('#menu .u2').hide();	
})

$('#menu').mouseleave(function(){
	$('#menu .u2').hide();	
})



//splash
var slideHtml='';
var slideIndex=0;
var slideTimer=null;
var slideDelay=6000;

$('#neck .preview li').each(function(){
	oimg=$(this).find('img');
	slideHtml+='<li data-img="'+oimg.attr('src')+'" title="'+oimg.attr('title')+'"></li>';
})
$('#neck').append('<ul id="imgSlider">'+slideHtml+'</ul>')


$('#neck .preview li:first').css({display:'block'});
//console.log($('#neck .preview').html())
$('#imgSlider li:first').addClass('current');


$('#imgSlider li').mouseenter(function(){
	clearInterval(slideTimer);
	$('#neck .preview li').hide();
	$('#imgSlider li').removeClass('current');	
	switchIt($('#neck .preview li:nth-child('+($(this).index()+1)+')'))
	$(this).addClass('current');
	slideTimer = setInterval(doit,slideDelay);
})



function switchIt(obj){
	if($.browser.msie==true){
		obj[0].filters[0].transition=parseInt(Math.random()*23);
		obj[0].filters[0].apply();
		obj.show().css('visibility','visible')
		obj[0].filters[0].play();
	}else{
		obj.css({display:'block'}).show('fast');
	}
}

if($('#neck').length!=0){
	slideTimer = setInterval(doit,slideDelay);
}

function doit(){	
	var oLen=$('#neck .preview li').length;
	$('#neck .preview li').css({display:'none'}).hide();		
	var num=parseInt($('#imgSlider li.current').index())+2;
	if(num>oLen){num=1}
	$('#imgSlider li').removeClass('current');	
	switchIt($('#neck .preview li:nth-child('+num+')'));
	$('#imgSlider li:nth-child('+num+')').addClass('current');
}


//pNews
$('#pNews').append('<div class="info"></div>')

$('#pNews li').hide();
$('#pNews li:first').show();
$('#pNews').find('.info').append('<a href="'+$('#pNews li:first').find('a').attr('href')+'">'+$('#pNews li:first').find('img').attr('title')+'</a>');

setInterval(function(){
	var obj=$('#pNews li:visible');
	obj.fadeOut('fast',function(){
		if(obj.next().length!=0){
		obj.next().fadeIn('fast');
		
		t=obj.next().find('img').attr('title');
		l=obj.next().find('a').attr('href');
		
		$('#pNews').find('.info').empty().append('<a href="'+l+'">'+t+'</a>');
	}else{

		t=$('#pNews li:first').find('img').attr('title');
		l=$('#pNews li:first').find('a').attr('href');
		
		$('#pNews').find('.info').empty().append('<a href="'+l+'">'+t+'</a>');
		$('#pNews li:first').fadeIn('fast');

	}
	});	
},6000)

//gMarquee
var w=$('#products').find('table').width();

var tr=$('#products').find('tr');
tr.append(tr.find('td').clone())

var reset=function(){
		$(this).css({'margin-left':0});
		$(this).animate({'margin-left':-+w+'px'},15000,'linear',reset)
}

reset.call($('#products').find('table'));


var ran;

$('#products').mouseenter(function(){
	//$('#products').find('table').stop();
	$('#products').find('table').stop();
	//记住 停住 的地方，mouseleave 继续
	ran=1-Math.abs(parseInt($('#products').find('table').css('margin-left')))/w;
	
}).mouseleave(function(){
	//$('#products').find('table').css({'margin-left':0});
	$('#products').find('table').animate({'margin-left':-+w+'px'},15000*ran,'linear',reset);
})


////////////////////////////////////	
})

$(window).load(function(){
////////////////////

$('#leftSec img').each(function(){

	if($(this).width()>640){$(this).css({width:'640px'})}
})

////////////////////
})
