var slideShow=function(){
	var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl,browsername,browserversion,osname,appVer,mac1pos,mac2pos,maxwidth,maxheight;
	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;
	 appVer = window.navigator.appVersion;
	 mac1pos = appVer.indexOf("MSIE");
	 mac2pos = appVer.indexOf("Macintosh");
	 if((mac1pos > -1) && (mac2pos > -1)){
 	   browsername = appVer.substring(mac1pos,mac1pos+4);
	   browserversion = appVer.substring(mac1pos+5,mac1pos+6);
	   osname = appVer.substring(mac2pos,mac2pos+9);    
		if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){
			thumbpos=document.getElementById('thumbwrapper');
			arrowleftpos=document.getElementById('leftarrow');
			arrowrightpos=document.getElementById('rightarrow');
			thumbpos.style.paddingTop = 390+'px';
			arrowleftpos.style.paddingTop = 785+'px';
			arrowrightpos.style.paddingTop = 785+'px';
		}
	 }	
	return{
		init:function(){
			//document.onmousemove=this.pos;
			if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){
				document.onclick=this.pos;
			}else{
				document.onmousemove=this.pos;
			}
			window.onresize=function(){setTimeout("slideShow.lim()",500)};
			ys=this.toppos(ta); ye=ys+ta.offsetHeight;
			len=t.length;tar=[];
			for(i=0;i<len;i++){
				var id=t[i].value; tar[i]=id; 
				var extension=t[i].id; 
				var imagelabel=t[i].title;
				t[i].onclick=new Function("slideShow.getimg('"+id+"','"+extension+"','"+imagelabel+"')");
				if(i==0){this.getimg(id,extension,imagelabel)}
			}
			tarl=tar.length;
		},
		scrl:function(d){
			    //alert(d);
				clearInterval(ta.timer);
				var l=(d==-1)?0:(t[tarl-1].offsetLeft-(ta.parentNode.offsetWidth-t[tarl-1].offsetWidth)+0)
				ta.timer=setInterval(function(){slideShow.mv(d,l)},st);
		},
		mv:function(d,l){
			//if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){
			//	alert(d);
			//}else{
				ta.style.left=ta.style.left||'0px';
				var left=ta.style.left.replace('px','');
				if(d==1){
					if(l-Math.abs(left)<=ss){
						this.cncl(ta.id); ta.style.left='-'+l+'px';
					}else{ta.style.left=left-ss+'px'}
				}else{
					if(Math.abs(left)-l<=ss){
							this.cncl(ta.id); ta.style.left=l+'px';
					}else{ta.style.left=parseInt(left)+ss+'px'}
				}
			//}
		},
		cncl:function(){clearTimeout(ta.timer)},
		getimg:function(id,extension,imagelabel){
			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);}
				}
			}	
					tlable=document.getElementById("tmplabel");
					tlable.value=imagelabel;
					if(!document.getElementById(id)){
						var i=document.createElement('img');
						ia.appendChild(i);
						i.id=id; i.av=0; i.style.opacity=0;
						i.style.filter='alpha(opacity=0)';
						i.src=imgdir+'/'+id+'.'+extension;
						i.onmousedown=function(){return false;};
						nleft=0+'px';ntop=0+'px';
								maxwidth = i.width;
								maxheight = i.height;
								if(i.width>490){
								   i.width = 490;
								   i.height = Math.round((490/maxwidth)*maxheight);
								}
								if(i.height>394){
								   i.height	= 394;
								   i.width = Math.round((394/maxheight)*maxwidth);
								}
								if(i.width<490){
									nleft = Math.round((490-(i.width))/2)+'px';
								}else{
									nleft=0+'px';
								}
								if(i.height<394){
									ntop = Math.round((394-(i.height))/2)+'px';
								}else{
									ntop=0+'px';	
								}
								i.style.borderLeft=nleft+" solid #FFFFFF"; 
								i.style.borderTop=ntop+" solid #FFFFFF"; 
								i.style.borderRight=nleft+" solid #FFFFFF"; 
								i.style.borderBottom=ntop+" solid #FFFFFF"; 
								i.style.top = 0+'px';	
								i.style.left = 0+'px';	
								i.title=imagelabel;
						if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){
							i.width = 0+'px';
							i.height = 0+'px';

							i.onload = function(){
								var i=document.createElement('img');
								ia.appendChild(i);
								i.id=id; i.av=0; i.style.opacity=0;
								i.style.filter='alpha(opacity=0)';
								i.src=imgdir+'/'+id+'.'+extension;
								i.onmousedown=function(){return false;};
								maxwidth = i.width;
								maxheight = i.height;
								if(i.width>490){
								   i.width = 490;
								   i.height = Math.round((490/maxwidth)*maxheight);
								}
								if(i.height>394){
								   i.height	= 394;
								   i.width = Math.round((394/maxheight)*maxwidth);
								}
								if(i.width<490){
									nleft = Math.round((490-(i.width))/2)+'px';
								}else{
									nleft=0+'px';
								}
								if(i.height<394){
									ntop = Math.round((394-(i.height))/2)+'px';
								}else{
									ntop=0+'px';	
								}
								i.style.borderLeft=nleft+" solid #FFFFFF"; 
								i.style.borderTop=ntop+" solid #FFFFFF"; 
								i.style.borderRight=nleft+" solid #FFFFFF"; 
								i.style.borderBottom=ntop+" solid #FFFFFF"; 
								i.style.top = 0+'px';	
								i.style.left = 0+'px';	
								i.title=imagelabel;
							}
						}else{
  							/*if(i.width >0){
								maxwidth = i.width;
								maxheight = i.height;
								//alert(maxheight+ 'IE');
								if(i.width>510){
								   i.width = 510;
								   i.height = Math.round((510/maxwidth)*maxheight);
								}
								if(i.height>394){
								   i.height	= 394;
								   i.width = Math.round((394/maxheight)*maxwidth);
								}
								if(i.width<510){
									nleft = Math.round((510-(i.width))/2)+'px';
								}else{
									nleft=0+'px';	
								}
								if(i.height<394){
									ntop = Math.round((394-(i.height))/2)+'px';
								}else{
									ntop=0+'px';
								}
								i.style.borderLeft=nleft+" solid #000000"; 
								i.style.borderTop=ntop+" solid #000000"; 
								i.style.borderRight=nleft+" solid #000000"; 
								i.style.borderBottom=ntop+" solid #000000"; 
								i.style.top = 0+'px';	
								i.style.left = 0+'px';	
						}else{*/
							i.onload = function(){
								maxwidth = i.width;
								maxheight = i.height;
								if(i.width>490){
								   i.width = 490;
								   i.height = Math.round((490/maxwidth)*maxheight);
								}
								if(i.height>394){
								   i.height	= 394;
								   i.width = Math.round((394/maxheight)*maxwidth);
								}
								if(i.width<490){
									nleft = Math.round((490-(i.width))/2)+'px';
								}else{
									nleft=0+'px';
								}
								if(i.height<394){
									ntop = Math.round((394-(i.height))/2)+'px';
								}else{
									ntop=0+'px';	
								}
								i.style.borderLeft=nleft+" solid #FFFFFF"; 
								i.style.borderTop=ntop+" solid #FFFFFF"; 
								i.style.borderRight=nleft+" solid #FFFFFF"; 
								i.style.borderBottom=ntop+" solid #FFFFFF"; 
								i.style.top = 0+'px';	
								i.style.left = 0+'px';	
								i.title=imagelabel;
							//}
							}
						}
					}else{
						i=document.getElementById(id); clearInterval(i.timer);
					}
			if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){		
				//alert('testing id='+i.id+' src='+i.src);
			    //i.style.visibility = 'visible';
			}else{
				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.av=0; 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)}}
		},
		mfdin: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}
		},
		mfdout:function(i){
			//i.av=i.av-fs; i.style.opacity=i.av/100;
			i.av=0; 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.offsetWidth; taa=taw/4; 
			bxs=slideShow.leftpos(ta); bxe=bxs+taa; fxe=bxs+taw; fxs=fxe-taa;
		},
		pos:function(e){
			if(browsername=='MSIE' && browserversion == '5' &&  osname == 'Macintosh'){
				//alert(e.pageX);
				arrowleftpos.onclick
				slideShow.scrl(-1);
			}else{
				xp=ie?event.clientX+document.documentElement.scrollLeft:e.pageX; 
				yp=ie?event.clientY+document.documentElement.scrollTop:e.pageY;
				if(xp>(bxs-60)&&xp<(bxe-105)&&yp>ys&&yp<ye){
					slideShow.scrl(-1);
				}else if(xp>(fxs+105)&&xp<(fxe+60)&&yp>ys&&yp<ye){
					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()};