// JavaScript Document
$(function(){
	
	function jcarousel2(){
		var $jc = $('#jcarousel2');
		
		var $t = $('table.main',$jc);
		var w2 = $t.width();
		var w = $('div.in',$jc).width();
		
		var res = w2-w;
		var t,t2;
		var $a = $('a.link',$jc)
		if(res>0){
			function anima1(){
				t = setTimeout(function(){$t.animate({'marginLeft':'-'+res},(20*res),function(){anima2()})},2000)
				
			}
			
			anima1()
			
			function anima2(){
				t2 = setTimeout(function(){$t.animate({'marginLeft':0},(20*res),function(){anima1()})},2000);
			}
			$jc.hover(function(){
				$t.stop();
				clearTimeout(t);
				clearTimeout(t2);
				
			},function(){anima1()})
			
		}
		$a.each(function(){
			var $obj = $(this);
			var $ta = $('table.spec',$obj);
			
			$obj.hover(function(){
				$obj.stop().animate({'width':'140px','marginTop':'-20px'},500);
				$ta.stop().animate({'width':138+'px','height':110+'px'},500);
			},function(){
				$obj.stop().animate({'width':'110px','marginTop':0},500);
				$ta.stop().animate({'width':'108px','height':'80px'},500);
			})
		
		})
		
		
	}
	jcarousel2();
	function jcarousel(){
		var $jc = $('#jcarousel');
		var $next = $('a.next',$jc);
		var $prev = $('a.prev',$jc);
		var $t = $('table.main',$jc);
		var $tr = $('tr.main',$jc);			
		var t;
		
		$next.click(function(){clearInterval(t);})
		$prev.click(function(){clearInterval(t);})
		$next.bind('click.next',function(){				
			
			$t.find('td.item').removeClass('act')														
			var $obj = $t.find('td.item:first-child');
			$tr.append($obj.clone());
			$obj.remove();
			$t.stop().css('marginLeft','-'+150+'px').animate({'marginLeft':'-'+(450)},500,function(){$t.find('td.item').eq(2).addClass('act');});				
			return false;
		})
		
		$prev.bind('click.prev',function(){
		
		$t.find('td.item').removeClass('act')
			var $obj = $t.find('td.item:last-child');
			$tr.prepend($obj.clone());
			$obj.remove();
			$t.stop().css('marginLeft','-'+750+'px').animate({'marginLeft':'-'+450},500,function(){$t.find('td.item').eq(2).addClass('act');});
				
			return false;
		});
		t = setInterval(function(){$next.trigger('click.next')},2000)
		
	}
	jcarousel();


})

