var slideShow=function(){
	var ys,ta,ia,st,fs,ci,t,tar,tarl,paused;
	ta=document.getElementById(thumbid);
	ia=document.getElementById(imgid);
	t=ta.getElementsByTagName('li');
	fs=5;
	paused=1;
	
	return{
		init:function(){
			len=t.length;
			tar=[];
			for(i=0;i<len;i++){
				var id=t[i].value;
				tar[i]=id;
				t[i].onclick=new Function("slideShow.getimg('"+id+"')");
				if(i==0)
				{this.getimg(id)}
			}
			tarl=tar.length;			
		},
		getimg:function(id){
			if(auto){clearTimeout(ia.timer)}
			document.getElementById("captionTitle").innerHTML=caption_title[id];
			document.getElementById("captionTxt").innerHTML=caption_txt[id];
			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(id)){
				var i=document.createElement('img');
				ia.appendChild(i);
				for(var j = 1; j <= totalImg; j++)
				{
					if(j == id)
						document.getElementById("img"+j).className="active";
					else
						document.getElementById("img"+j).className="inactive";
				}									
				i.id=id; i.av=0; i.style.opacity=0;
				i.style.filter='alpha(opacity=0)';
				i.src=imgdir+'/gw'+id+imgext;	
				if((id == totalImg) && loop && paused)
				{
					loopcnt();					
				}
			}else{				
				i=document.getElementById(id); clearInterval(i.timer);				
			}
			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*2000)},
		pause:function(){
			if(loop){
				if(paused){
					paused=0;
					if(auto)clearTimeout(ia.timer)
					auto=false;
				}
				else
				{
					auto=true;
					paused=1;
					slideShow.auto();					
				}
			}
			else
			{
				loop = true;
				auto = true;
				slideShow.auto();
			}
		},
		start:function(){
			if(!paused)auto=false;
			if(auto)clearTimeout(ia.timer);
			slideShow.init();
		},
		prev:function(){
			slideShow.nav(-1); clearTimeout(ia.timer);
		},
		next:function(){
			slideShow.nav(1); clearTimeout(ia.timer);
		},
		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)}}
		}		
	};
}();
window.onload=function(){slideShow.init()};

function playpause(oImg){ 
	aImgname=new Array();
	aImgname=oImg.src.split('/');
	iArraycount=aImgname.length;
	ImgName=aImgname[iArraycount-1];
	if(ImgName=="pause.jpg")
	{
		oImg.src=oImg.src.replace(/pause.jpg/,'play.jpg');		
		
	}
	else if(ImgName=="play.jpg")
	{
		oImg.src=oImg.src.replace(/play.jpg/,'pause.jpg');		
	}
}
function show(){
	document.getElementById("controller").style.visibility="visible";	
}
function hide(){
	if(loop)
	document.getElementById("controller").style.visibility="hidden";
}
function loopcnt(){
	auto = false;
	loop = false;
	document.getElementById("controller").style.visibility="visible";
	oImg= new Image();
	oImg=document.getElementById("pauseId");
	oImg.src=oImg.src.replace(/pause.jpg/,'play.jpg');	
}
