var TINY={};
var tamanhoThumb = 0;
var passo = 0;
var imagens = new Array();
var thumb;
var cont = 0;
var img;
var thumbAtual = 0;

function PegaElementoPorId(i) {
	return document.getElementById(i)
}

function PegaElementoPorTag(e,p) {
	p = p || document;
	return p.getElementsByTagName(e)
}

function testeFlash()
{

TINY.slideshow=function(n){
	this.infoSpeed=this.imgSpeed=this.speed=10;
	this.thumbOpacity=this.navHover=70;
	this.navOpacity=25;
	this.scrollSpeed=5;
	this.letterbox='#000';
	this.n=n;
	this.c=0;
	this.a=[];
	
	this.n+'.mv(-1,1)';
	};
};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

TINY.slideshow=function(n){
	this.infoSpeed=this.imgSpeed=this.speed=10;
	this.thumbOpacity=this.navHover=70;
	this.navOpacity=25;
	this.scrollSpeed=5;
	this.letterbox='#000';
	this.n=n;
	this.c=0;
	this.a=[]
};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

TINY.slideshow.prototype={
	init:function(slideshow,image,imgprev,imgnext,imglink) {
		slideshow = PegaElementoPorId(slideshow);
		var m = PegaElementoPorTag('li',slideshow);
		var	i = 0;
		var w = 0;
		this.l = m.length;
		this.imglink = PegaElementoPorId(imglink);
		this.imgnext = PegaElementoPorId(image);
		this.r = PegaElementoPorId(this.info);
		this.o = parseInt(TINY.style.val(image,'width'));
		
		//alert(this.n+'.mv(-1,1)');
		if(this.thumbs) { //responsável por iniciar os scrolls dos thumbs
			var esquerda = PegaElementoPorId(this.left);
			var direita  = PegaElementoPorId(this.right);
			esquerda.onclick = new Function(this.n+'.mv(-1,1)'); //scroll para esquerda
			direita.onclick =  new Function(this.n+'.mv(1,1)');  //scroll para direita
			this.p = PegaElementoPorId(this.thumbs);
			thumb = PegaElementoPorId(this.thumbs);
		}
		for(i; i < this.l; i++) {
			this.a[i] = {};
			var h = m[i];
			var a = this.a[i];
			a.t = PegaElementoPorTag('h3', h)[0].innerHTML; //pega os valores da tag h3 do html
			a.d = PegaElementoPorTag('p', h)[0].innerHTML;  //pega os valores da tag p do html
			a.l = PegaElementoPorTag('a', h)[0]? PegaElementoPorTag('a',h)[0].href : ''; //pega os valores da tag a do html
			a.p = PegaElementoPorTag('span', h)[0].innerHTML; //pega os valores da tag span do html

			
			if(this.thumbs) { //responsável por mostrar os thumbs
				//var imagem = PegaElementoPorTag('img', h)[0]; //pega os valores da tag img do html
				var imagem = PegaElementoPorTag('h5', h)[0]; //pega os valores da tag img do html
				//var leg = PegaElementoPorTag('h5', h)[0]; //pega os valores da tag img do html
				//alert(leg);
				this.p.appendChild(imagem);
				imagens[i] = imagem;
				w += parseInt(imagem.offsetWidth);
				/**
				if(i != this.l - 1) {
					imagem.style.marginRight = this.spacing + 'px';
					w += this.spacing;
				}
				this.p.style.width = w + 'px';
				*/
				imagem.style.opacity = this.thumbOpacity / 100;
				imagem.style.filter = 'alpha(opacity=' + this.thumbOpacity + ')';
				imagem.onmouseover = new Function('TINY.alpha.set(this,100,5)');
				imagem.onmouseout =  new Function('TINY.alpha.set(this,' + this.thumbOpacity + ',5)');
				imagem.onclick = new Function(this.n+'.pr(' + i + ', 1)');

				//alert(this.p);
				//this.p.appendChild(leg);
			}
		}
		if(imgprev && imgnext){ //responsável pelas setas nas imagens maiores
			imgprev = PegaElementoPorId(imgprev);
			imgnext = PegaElementoPorId(imgnext);
			imgprev.style.opacity = imgnext.style.opacity = this.navOpacity / 100;
			imgprev.style.filter = imgnext.style.filter = 'alpha(opacity=' + this.navOpacity + ')';
			imgprev.onmouseover = imgnext.onmouseover = new Function('TINY.alpha.set(this,' + this.navHover + ',5)'); //responsável pelo alpha das setas das imagens maiores
			imgprev.onmouseout =  imgnext.onmouseout = new Function('TINY.alpha.set(this,' + this.navOpacity + ',5)');//responsável pelo alpha das setas das imagens maiores
			imgprev.onclick = new Function(this.n+'.mv(-1,1)'); //responsável pelo clique das setas das imagens maiores
			imgnext.onclick = new Function(this.n+'.mv(1,1)');  //responsável pelo clique das setas das imagens maiores
		}
		this.auto? this.is(0,0) : this.is(0,1)
		imagens[0].style.borderColor = this.active;
		//imagens[1].style.filters.alpha.opacity = 100;
	},
	
//-----------------------------------	
	
	mv:function(direcao, c) { //responsável pelo clique das setas das imagens maiores
		//Imagens		
		var t = this.c + direcao;
		this.c = t = t < 0? this.l-1 : t > this.l-1? 0 : t;

		//Thumbs
		if(direcao > 0) { //direita
			//passo -= 87;
			if (thumbAtual == tamanhoThumb - 1) {
				this.p.appendChild(imagens[thumbAtual]);
				thumbAtual = 0;
				imagens[thumbAtual].style.borderColor = this.active;
				imagens[tamanhoThumb - 1].style.borderColor = '';
			} else {
				this.p.appendChild(imagens[thumbAtual]);
				thumbAtual++;
				imagens[thumbAtual].style.borderColor = this.active;
				if(thumbAtual != 0) {
					imagens[thumbAtual - 1].style.borderColor = '';
				}
			}
		} else { //esquerda
			//passo += 87;
			if (thumbAtual == 0) {
				this.p.insertBefore(imagens[tamanhoThumb - 1], imagens[thumbAtual]);
				imagens[tamanhoThumb - 1].style.borderColor = this.active;
				imagens[thumbAtual].style.borderColor = '';
				thumbAtual = tamanhoThumb - 1;
			} else {
				this.p.insertBefore(imagens[thumbAtual - 1], imagens[thumbAtual]);
				imagens[thumbAtual - 1].style.borderColor = this.active;
				if(thumbAtual != 0) {
					imagens[thumbAtual].style.borderColor = '';
				}
				thumbAtual--;
			}
		}
		//thumb.style.left = passo + 'px';
		this.pr(t, c);
	},
		
//-----------------------------------	
		
	pr:function(t,c) { //responsável pelo clique do mouse nos thumbs
		clearTimeout(this.lt);
		if(c) {
			clearTimeout(this.at)
		}
		this.c = t;
		this.is(t, c);
	},
	
//-----------------------------------	

	is:function(slideshow, c) { //responsável pelo scroll das imagens maiores
		if(this.info) {
			TINY.height.set(this.r, 1, this.infoSpeed / 2, -1);
		}
		var imagem = new Image();
		imagem.style.opacity = 0;
		imagem.style.filter = 'alpha(opacity=0)';
		this.i = imagem;
		imagem.onload = new Function(this.n + '.le(' + slideshow + ',' + c + ')');
		imagem.src = this.a[slideshow].p;
		
		if(this.thumbs) { //responsável pelas bordas dos thumbs
			var a = PegaElementoPorTag('img', this.p);
			var l = a.length;
			tamanhoThumb = l;
			for(x = 0; x < l; x++) {
				//a[x].style.borderColor = x != slideshow? '' : this.active;
			}
		}
	},

//-----------------------------------		
		
	le:function(slideshow,c) { //responsável pelo scroll das imagens maiores
		this.imgnext.appendChild(this.i);
		var w = this.o - parseInt(this.i.offsetWidth);
		if(w > 0){
			var l = Math.floor(w / 2);
			this.i.style.borderLeft=l+'px solid '+this.letterbox;
			this.i.style.borderRight=(w-l)+'px solid '+this.letterbox
		}
		TINY.alpha.set(this.i,100,this.imgSpeed);
		var n = new Function(this.n + '.nf(' + slideshow + ')'); //responsável pelas informações das imagens maiores
		this.lt = setTimeout(n, this.imgSpeed * 100);
		if(!c) {
			this.at = setTimeout(new Function(this.n + '.mv(1,0)'), this.speed * 1000)
		}
		if(this.a[slideshow].l != '') {
			this.imglink.onclick = new Function('window.location="' + this.a[slideshow].l + '"');
			this.imglink.onmouseover = new Function('this.className="' + this.link + '"');
			this.imglink.onmouseout = new Function('this.className=""');
			this.imglink.style.cursor = 'pointer'
		} else {
			this.imglink.onclick = this.imglink.onmouseover=null;
			this.imglink.style.cursor = 'default'
		}
		var m = PegaElementoPorTag('img',this.imgnext);
		if(m.length > 2) {
			this.imgnext.removeChild(m[0])
		}
		
		
	},
		
//-----------------------------------
		
	nf:function(slideshow) { //responsável pelas informações das imagens maiores
		if(this.info) {
			slideshow=this.a[slideshow];
			PegaElementoPorTag('h3',this.r)[0].innerHTML=slideshow.t;
			PegaElementoPorTag('p',this.r)[0].innerHTML=slideshow.d;
			//alert(slideshow.l);
			document.getElementById('endereco').href=slideshow.l;

			this.r.style.height='auto';
			var h=parseInt(this.r.offsetHeight);
			this.r.style.height=0;
			TINY.height.set(this.r,h,this.infoSpeed,0)
		}
	}
};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

TINY.height=function() {
	return {
		set:function(e,h,s,d) {
			e=typeof e=='object'?e:PegaElementoPorId(e);
			var oh=e.offsetHeight, ho=e.style.height||TINY.style.val(e,'height');
			ho=oh-parseInt(ho);
			var hd=oh-ho>h?-1:1;
			clearInterval(e.si);
			e.si=setInterval(function() {
								TINY.height.tw(e,h,ho,hd,s)
							 },20)
		},
		tw:function(e,h,ho,hd,s){
			var oh=e.offsetHeight-ho;
			if(oh==h) {
				clearInterval(e.si)
			} else {
				if(oh!=h) {
					e.style.height=oh+(Math.ceil(Math.abs(h-oh)/s)*hd)+'px'
				}
			}
		}
	}
}();

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

TINY.alpha=function() {
	return {
		set:function(e,a,s) {
			e = typeof e == 'object'? e : PegaElementoPorId(e);
			var o = e.style.opacity || TINY.style.val(e, 'opacity'), d = a > o * 100? 1 : -1;
			e.style.opacity = o;
			clearInterval(e.ai);
			e.ai = setInterval(function() {
								TINY.alpha.tw(e,a,d,s)
							 },20)
		},
		tw:function(e,a,d,s) {
			var o = Math.round(e.style.opacity * 100);
			if(o == a) {
				clearInterval(e.ai)
			} else {
				var n = o + Math.ceil(Math.abs(a - o) / s) * d;
				e.style.opacity = n / 100;
				e.style.filter = 'alpha(opacity=' + n + ')'
			}
		}
	}
}();

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

TINY.style=function() {
	return {
		val:function(e,p) {
			e = typeof e == 'object'? e : PegaElementoPorId(e);
			return e.currentStyle? e.currentStyle[p] : document.defaultView.getComputedStyle(e,null).getPropertyValue(p)
		}
	}
}();