var slideShow=function(){
	var xs,xe,bys,bye,fys,fye;
	var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl;
	ta=document.getElementById(thumbid); ia=document.getElementById(imgid);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("slideShow.lim()",500)};
			xs=this.leftpos(ta); xe=xs+ta.offsetWidth; 
			ys=this.toppos(ta); ye=ys+ta.offsetHeight;
			len=t.length;tar=[];
			for(i=0;i<len;i++){
				var imgChild = t[i].getElementsByTagName('img');
				var id = imgChild[0].id.replace(/[a-z_]+([0-9]+)/g, "$1");
				
				tar[i]=id;
				t[i].onclick=new Function("slideShow.getimg('"+id+"')");
				if(i==0){this.getimg(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)},
		getimg:function(id){
			if(auto){clearTimeout(ia.timer)}
			if(ci!=null){
				var ts,tsl,x;
				ts=ia.getElementsByTagName('img'); tsl=ts.length;x=0;
				for(x;x<tsl;x++){
					if(ci.id!=id){var o=ts[x]; clearInterval(o.timer); o.timer=setInterval(function(){slideShow.fdout(o)},fs)}
				}
			}
			if(!document.getElementById('slide_image'+id)){
				var ah=document.createElement('a');
				var i=document.createElement('img');
				var slth=document.getElementById('slide_thumbs' + id);
				i.id=id; i.av=0; i.style.opacity=0;i.style.filter='alpha(opacity=0)';
				i.src=imgdir+'/'+id+imgext;
				ah.href=imgdir+'/'+id+'_max'+imgext;
				ah.title=slth.title;
				ah.rel='lightbox[slider]';
				ah.appendChild(i);
				ia.appendChild(ah);
			}
			else{
				ah=document.getElementById('slide_image'+id); 
				var i=document.createElement('img');
				var slth=document.getElementById('slide_thumbs' + id);
				
				i.id=id; i.av=0; i.style.opacity=0;i.style.filter='alpha(opacity=0)';
				i.src=imgdir+'/'+id+imgext;
				ah.href=imgdir+'/'+id+'_max'+imgext;
				ah.title=slth.title;
				ah.appendChild(i);
				
				clearInterval(i.timer);
			}
			change_img_desc(i.id);
			i.timer=setInterval(function(){slideShow.fdin(i)},fs);
		},
		nav:function(d){
			var c=0;
			for(key in tar){if(tar[key]==ci.id){c=key}}
			if(tar[parseInt(c)+d]){
				this.getimg(tar[parseInt(c)+d]);}
			else{
				if(d==1){
					this.getimg(tar[0]);
				}else{this.getimg(tar[tarl-1])}
			}
		},
		auto:function(){ia.timer=setInterval(function(){slideShow.nav(1)},autodelay*1000)
		},
		fdin:function(i){
			if(i.complete){i.av=i.av+fs; i.style.opacity=i.av/100; i.style.filter='alpha(opacity='+i.av+')'}
			if(i.av>=100){if(auto){this.auto()}; clearInterval(i.timer); ci=i}
		},
		fdout:function(i){
			i.av=i.av-fs; i.style.opacity=i.av/100;
			i.style.filter='alpha(opacity='+i.av+')';
			if(i.av<=0){clearInterval(i.timer); if(i.parentNode){i.parentNode.removeChild(i)}}
		},
		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: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=0;
			if(t.offsetParent){
				while(1){l+=t.offsetLeft; 
					if(!t.offsetParent){break}; 
					t=t.offsetParent}}
			else if(t.x){l+=t.x}
			return l;},
		toppos:function(t){
			var p=0;if(t.offsetParent){
				while(1){p+=t.offsetTop; 
					if(!t.offsetParent){break}; 
					t=t.offsetParent}}
			else if(t.y){p+=t.y}
			return p;
		}
	};
}();
window.onload=function(){slideShow.init(); slideShow.lim()};