var slideShow=function() {
	var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl,taw,taf;
	ta = document.getElementById(thumbid); 
	ia = document.getElementById(imgid);
	t = ta.getElementsByTagName('li');
	Imagens = ta.getElementsByTagName('img');
	ie = document.all ? true : false;
	st = 3; 
	ss = 3; 
	ft = 30; 
	fs = 30; 
	xp,yp = 0;
  
  var divBarra = document.getElementById('thumbwrapper');
  var divBotaoBarra = document.getElementById('thumbbutton');
  var intervaloBarra;
  var hBarra;
  var hMaxBarra;
  var hMinBarra;
  var image1;
  var image2;
  var imgBotaoBarra = document.getElementById('imgthumbbutton');

	return {
		
		init:function() {
						
			image1 = new Image();
			image1.src = "inc/mostrar_miniaturas.png";
			image2 = new Image();
			image2.src = "inc/ocultar_miniaturas.png";
			
			document.onmousemove = this.pos; 
			
			window.onresize=function() {
			  setTimeout("slideShow.lim()", 1000);
        
			};
			
			ys = this.toppos(ta);
			ye = ys+ta.offsetHeight;
			len = t.length;
			tar = [];
			taw = [];
      		taf = [];
			for (i = 0; i < len; i++) {
				//var id = t[i].title;
        		var id = t[i].getAttribute('idFoto');
				tar[i] = id;
				taw[i] = t[i].value;
        		taf[i] = t[i].getAttribute('swf_detalhe');
				
				t[i].onclick = new Function("slideShow.getimg('"+id+"','"+taw[i]+"','"+taf[i]+"')");
				if (i == 0) {
				  this.getimg(id, taw[i], taf[i])
				}
			}
			tarl = tar.length;

      divBotaoBarra.onclick = this.ocultarExibirBarra;
      hMaxBarra = divBarra.clientHeight;
      hMinBarra = 0; 
      
		},
    
    ocultarExibirBarra:function() {
      
      clearInterval(intervaloBarra);
      hBarra = divBarra.clientHeight;
      if (hBarra == hMaxBarra)
      {
        intervaloBarra = setInterval(function(){slideShow.ocultarBarra()},30);
      }
      else
      {
        intervaloBarra = setInterval(function(){slideShow.exibirBarra()},30);
      }     
      
    },
    
    ocultarBarra:function() {
    
      hBarra = divBarra.clientHeight;
      if (hBarra > hMinBarra)
      {
        hBarra = hBarra - 10;
        divBarra.style.height = hBarra + 'px';
      }
      else
      {
		//divBotaoBarra.style.backgroundImage = "url(inc/mostrar_miniaturas.png)";
		imgBotaoBarra.src = image1.src;
        clearTimeout(intervaloBarra);
      }    
    
    },
    
    exibirBarra:function() {
    
      hBarra = divBarra.clientHeight;
      if (hBarra < hMaxBarra)
      {
        hBarra = hBarra + 10;
        divBarra.style.height = hBarra + 'px';
      }
      else
      {
		//divBotaoBarra.style.backgroundImage = "url(inc/ocultar_miniaturas.png)";
		imgBotaoBarra.src = image2.src;
        clearTimeout(intervaloBarra);
      }
    
    },

		detalhe:function(swf) {
      if (swf == ''){
			var swf = taf[this.indice()];
		    }
      if (swf != '')
      {
        var h = 550;
        var w = 800;
        var divFundo = document.createElement('div');
        divFundo.setAttribute('id', 'wDivFundo');

        var divConteudo = document.createElement('div');
        divConteudo.setAttribute('id', 'wDivConteudo');

        var divFechar = document.createElement('div');
        divFechar.setAttribute('id', 'wDivFechar');
        divFechar.onclick = new Function("slideShow.fechar();");
        
        var iFrame = document.createElement('iframe');
        iFrame.id  = 'wFrame';
        iFrame.setAttribute('src', 'inc/' + swf);
        iFrame.setAttribute('name', 'nomedoframe');
        iFrame.setAttribute('frameborder', '0');
        iFrame.setAttribute('marginheight', '0');
        iFrame.setAttribute('marginwidth', '0');
        iFrame.setAttribute('scrolling', 'no');
        iFrame.setAttribute('allowtransparency', 'true');
                
        divConteudo.appendChild(divFechar);
        divConteudo.appendChild(iFrame);
                
        var inBody = document.getElementsByTagName("body").item(0);
        inBody.insertBefore(divFundo, inBody.firstChild);
        inBody.insertBefore(divConteudo, divFundo.nextSibling);	
        
        divFundo.style.zIndex = '10000';
        divFundo.style.display = 'inline';
        
        divConteudo.style.zIndex = '10001';
        divConteudo.style.display = 'inline';

      }
	  },
    
    fechar:function(){
      document.getElementById('wDivConteudo').style.display = 'none';
      document.getElementById('wDivFundo').style.display = 'none';
    },
		
		scrl:function(d) {
			
			clearInterval(ta.timer);
			var l = (d == -1) ? 0 : (t[tarl-1].offsetLeft-(ta.parentNode.offsetWidth-t[tarl-1].offsetWidth)+10);
			ta.timer = setInterval(function(){slideShow.mv(d,l)},st);
		},
		
		mv:function(d, l) {
			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, id_width, nomeswf) {
			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(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;
				i.style.top = 0;
        i.style.left = 0;
			} 
			else 
			{
				i = document.getElementById(id); 
				clearInterval(i.timer);
			}
			i.timer = setInterval(function(){slideShow.fdin(i)},fs);
			
      var det = document.getElementById('detimg');
      if (nomeswf=='')
      {
        det.style.visibility = 'hidden';
      } else {
        det.style.visibility = 'visible';
      }
      
		},
    
     indice:function() {
      var c = 0;
      for (key in tar) 
      {
				if (tar[key] == ci.id) 
        {
					c = key;
				}
			}
      return c;
    },
		
		nav:function(d) {
			var c = 0;
			var i = 0;
			
			for (key in tar) {
				if (tar[key] == ci.id) {
					c = key
				}
			}
			
			i = parseInt(c)+d;
			
			if (tar[i]) {
				this.getimg(tar[i], taw[i], taf[i]);
			} else {
				if (d == 1) {
					this.getimg(tar[0], taw[0], taf[0]);
				} else {
					this.getimg(tar[tarl-1], taw[tarl-1], taf[tarl-1])
				}
			}
		},
		
		auto:function() {
			ia.timer = setInterval(function(){slideShow.nav(1)},autodelay*8000);
		},
		
		fdin:function(i) {
			
			if (i.complete) {
				i.av = i.av+fs; 
				i.style.opacity = i.av/50; 
				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/50;
			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) {
			xp = ie ? event.clientX+document.documentElement.scrollLeft : e.pageX; 
			yp = ie ? event.clientY+document.documentElement.scrollTop : e.pageY;
			if (xp > bxs && xp < bxe && yp > ys && yp < ye) {
				slideShow.scrl(-1);
			} else if (xp > fxs && xp < fxe && 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;
		},
		
		stop:function() {
			clearInterval(ia.timer)
		},
		
		load:function(){
			this.init(); 
			this.lim();
			document.getElementById("carregando").style.visibility = "hidden";
		}
	};	
}();

/*
window.onload = function() {
	slideShow.init(); 
	slideShow.lim();
	document.getElementById("carregando").style.visibility = "hidden";
};
*/

