$(function(){
	var timer;
	var i = -1;
	var speed = 3000;//停留秒數
	var alpha=0.9;//說明文底的透明度0~1
	var myItembox = $("#ItemBox ul li a");

	$("#showinfo").html($("#ItemBox ul li a").attr("rel"));
	$("#showinfobg").css("opacity",alpha);
	
	myItembox.click(function(){		
		var imgfile=$(this).attr("data");
		var imgurl=$(this).attr("href");
		var imginfo=$(this).attr("rel");
// 		$("#showimg").attr("src",imgfile);
// 		$("#showinfo").html(imginfo);
    if(imgurl!='') $("#ShowBox").html("<a  href='"+imgurl+"'><img src='"+imgfile+"' name='showimg' border='0' id='showimg'    /></a>");
    else $("#ShowBox").html("<img src='"+imgfile+"' name='showimg' border='0' id='showimg'    />");  
    
		i = myItembox.index($(this));
		
		$("#ItemBox ul li").removeClass("on");//remove		
		$(this).parent().addClass("on");//add		
		
		return false;	
	}).hover(function(){//滑入時停止輪播
		clearTimeout(timer);
	}, function(){
		timer = setTimeout(autoShow, speed);
	});

	//滑入時停止輪播
	$("#ShowBox").hover(function(){
		clearTimeout(timer);
	}, function(){
		timer = setTimeout(autoShow, speed);
	});
	
	//自動輪播函數
	function autoShow(){
		myItembox.eq(i).css("opacity", alpha);
		if(i+1<myItembox.length){
			i++;
		}else{
			i=0;
		}
		myItembox.eq(i).click();
		myItembox.removeClass("on");
		myItembox.eq(i).parent().addClass("on");
		timer = setTimeout(autoShow, speed);
	}
	//啟動自動輪播
	autoShow();
});
