jQuery.noConflict();
(function($) {
	$(function(){
		var num = $('#lb li').length;
		var current = 1;
		var direction = true;
		var t;
		var minWidth = 960;
		var picWidth = 1680;
		var totalWidth = picWidth*num;
		var w, fWidth;
		var sn=1;
		function init(){
			if ((t!=undefined) && (t!=null)) clearInterval(t);
			if((sn!=undefined)&&(sn!=null)){current = sn;}
			var pcWidth = $(window).width();
			
			if (pcWidth > minWidth){
				if(pcWidth >= picWidth){
					fWidth = picWidth;
					w = 0;
				}else{
					fWidth = pcWidth;
					w = -(picWidth - pcWidth)/2;
				}
			}else{
				fWidth = minWidth;
				w = -(picWidth - minWidth)/2;
			}
			$("#flash").css({"width":fWidth+"px"});
			if (current!=1){
				w = w-(current-1)*picWidth;
				$("#lb").css({"width":totalWidth+"px", "left":w+"px"});
			}else{
				$("#lb").css({"width":totalWidth+"px", "left":w+"px"});
			}
			t = setInterval(autoScroll, 6000);
		}
		$("#prev").unbind().bind("click",turnLeft);
		$("#next").unbind().bind("click",turnRight);
		function turnLeft(){
			$("#prev").unbind("click");
			if (1<current){
				current--;
				sn = current;
				$("#next").show();
				$('#lb').animate({ left: "+=1680" }, 1000,function() {
					if (current<=1){$("#prev").unbind("click"); $("#prev").hide(); direction = true;}
					$("#prev").bind("click",turnLeft);
				});
			}
		}
		function turnRight(){
			$("#next").unbind("click");
			if (current<num){
				current++;
				sn = current;
				$("#prev").show();
				$('#lb').animate({ left: "-=1680" }, 1000,function() {
					if (current>=num){$("#next").unbind("click"); $("#next").hide(); direction = false;}
					$("#next").bind("click",turnRight);
				});
			}
		}
		function autoScroll(){
			if (direction){
				if (current<num){
					$("#next").trigger("click");
				}
			}else{
				if (current>1){
					$("#prev").trigger("click");
				}
			}
		}
		$('#flash').mouseover(function(){
			clearInterval(t);
		});
		$('#flash').mouseout(function(){
			t = setInterval(autoScroll, 6000);
		});
		$( window ).wresize( init );
		init();
	});
})(jQuery);
