/************************************
 * KTREE
 * @author kighie
 * @date 2009.05.18
 * **********************************/
if(window.TKCarousel == null){
	window.TKCarousel = function(container){
		this.container = container;
		var carousel = this;
		container.mouseenter(function(){
			carousel.stop();
		});
		container.mouseleave(function(){
			carousel.restart();
		});
	};
	
	window.TKCarousel.prototype = {
		start : function(runningTime,term, bRestart){
			this.runningTime = runningTime;
			this.term = term;
			var carousel = this;
			
			var container = $(this.container);
			
			container.css("height", "300px");
			var size = $("li",container).size();
			
			if(size <= 5){
				return;
			}
			
			var liHeight = $("li:first",container).height();
			
			this.timeoutCallback = function(){
				if(carousel.stopped){
					carousel.timeoutId = window.setTimeout(carousel.timeoutCallback, term);
				} else {
					container.animate({top:-liHeight}
						, runningTime
						, ""
						, function(){
							var $this = $(this);
							var first = $("li:first",container);
							first.remove().appendTo($this);
							
							$this.css("top",0);
							carousel.timeoutId = window.setTimeout(carousel.timeoutCallback, term);
						});
				}
			}
			
			this.timeoutCallback();
		} ,
		stop : function(){
			this.stopped = true;
		} ,
		restart : function(){
			this.stopped = false;
		}
	};
	
}
