$(function() {
var thumbid = "gal1";
if (document.getElementById(thumbid)) {
	var slideShow = function() {
		var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl;
		ta = document.getElementById(thumbid);
		t=ta.getElementsByTagName('li');
		ie=document.all?true:false;
		st=3;
		ss=3;
		ft=10;
		fs=5;
		xp,yp=0;
		return {
			init:function(){
				document.onmousemove = this.pos;
				window.onresize = function() {
					setTimeout(function() { slideShow.lim(); },500)
				};
				xs=this.leftpos(ta);
				xe=xs+ta.offsetWidth;
				len=t.length;
				tar=[];
				for(i=0;i<len;i++){
					var id=t[i].value;
					tar[i]=id;
				}
				tarl=tar.length;
			},
			scrl:function(d){
				clearInterval(ta.timer);
				var l=(d==-1)?0:(t[tarl-1].offsetTop-(ta.parentNode.offsetHeight-t[tarl-1].offsetHeight)+10)
				ta.timer=setInterval(function(){slideShow.mv(d,l)},st);
			},
			mv:function(d,l){
				ta.style.top=ta.style.top||'0px';
				var top=ta.style.top.replace('px','');
				if(d==1){
					if(l-Math.abs(top)<=ss){
						this.cncl(ta.id); ta.style.top='-'+l+'px';
					}else{ta.style.top=top-ss+'px'}
				}else{
					if(Math.abs(top)-l<=ss){
						this.cncl(ta.id); ta.style.top=l+'px';
					}else{ta.style.top=parseInt(top)+ss+'px'}
				}
			},
			cncl:function(){clearTimeout(ta.timer)},
			
			lim:function(){
				var taw,taa,len;
				taw=ta.parentNode.offsetHeight;
				taa=taw/4; 
				
				bys=slideShow.toppos(ta);
				bye=bys+taa;
				fye=bys+taw;
				fys=fye-taa;
			},
			pos:function(e){
				xp=ie?event.clientX+document.documentElement.scrollLeft:e.pageX; 
				yp=ie?event.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop):e.pageY;
				if(xp>xs&&xp<xe&&yp>bys&&yp<bye) {
					slideShow.scrl(-1);
				} else if(xp>xs&&xp<xe&&yp>fys&&yp<fye){
					slideShow.scrl(1);
				} else{slideShow.cncl()}
			},
			leftpos:function(t){
				var l = $(t).offset().left;
				return l;
			},
			toppos:function(t){
				var p = $(t).offset().top;
				return p;
			}
		};
	}();
	
	slideShow.init();
	slideShow.lim();
}
});

