﻿
(function($){
	function BlogerShowScroll(id,totalPage,timeOut){
		this.currPage = 1;
		this.sid = id;
		this.totalPage = totalPage;
		this.timeOut = 	timeOut;
		this.timer = null;
		this.scroller = $("#"+id);
		this.init();
	}	
	BlogerShowScroll.prototype = {
		init:function(){
			this.scroller.bind("mouseover",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.stop();
			});
			this.scroller.bind("mouseout",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.start();
			});
			this.leftBtn = $("#"+this.sid+"_lbtn");
			this.rightBtn = $("#"+this.sid+"_rbtn");
			this.leftBtn.bind("mouseover",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.stop();
			});
			this.leftBtn.bind("mouseout",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.start();
			});
			this.rightBtn.bind("mouseover",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.stop();
			});
			this.rightBtn.bind("mouseout",{obj:this},function(event){
				var thisObj = event.data.obj;
				thisObj.start();
			});
			this.leftBtn.bind("click",{obj:this,direc:"left"},function(event){
				var thisObj = event.data.obj;
				thisObj.scroll(event.data.direc);
			});
			this.rightBtn.bind("click",{obj:this,direc:"right"},function(event){
				var thisObj = event.data.obj;
				thisObj.scroll(event.data.direc);
			});
			this.start();
		},
		start:function(){
			this.timer = setInterval(this.getMethod(this,"scroll",["left"]),this.timeOut);
		},
		stop:function(){
			clearInterval(this.timer);
		},
		scroll : function(direc){
			if(direc=="left"){
				if(this.currPage==this.totalPage){
					this.scroller[0].scrollLeft = 0;
					this.currPage = 1;
					return false;
				}
				this.scroller[0].scrollLeft = this.currPage*644;				
				this.currPage++;								
			}else if(direc=="right"){
				if(this.currPage==1){
					this.scroller[0].scrollLeft = (this.totalPage-1)*644;
					this.currPage = this.totalPage;
					return false;
				}
				this.scroller[0].scrollLeft = (this.currPage-2)*644;
				this.currPage--;
			}
		},
		getMethod:function(variable,method,param){return function(){variable[method](param);}}
	}
	window.BlogerShowScroll = BlogerShowScroll;
})(jQuery);
