/*
$BD:Slide - version 0.9.4$
$LastModified: 04/02/2006$

Sistema Free para uso pessoal ou comercial contanto que os
cr&#233;ditos permane&#231;am intactos. Eu j&#225; nem estou colocando um
monte de coisa pra n&#227;o deixar o c&#243;digo pesado. ^^

Maiores Informa&#231;&#245;es:
http://my.opera.com/bimonti/
*/

slide = {

	// vetor com os slides
	_imagens : [
			["http://farm3.static.flickr.com/2458/3833478129_f6dd4c462d.jpg","CD Brazil Essential","Capa do Cd Brazil Essential","1.htm"],
			["2.jpg","Cd Beat","Capa do Cd Beat","2.htm"],
			["3.jpg","CD Bum Bum do Poeta","Capa do Cd Bum Bum do Poeta","3.htm"],
			["4.jpg","Cd Mapa Mundi","Capa do Cd Mapa Mundi","4.htm"]
		],
	
	
	// ID dos elementos que o sistema modifica
	// ID da imagem do slide
	_slideImg : 'slideImg',
	// ID do link do slide, ou seja, um elemento A
	_linkSlide : 'linkSlide',
	// ID do t&#237;tulo do slide, uma div ou span por exemplo
	_titleSlide: 'titleSlide',
	// ID do t&#237;tulo do slide, id&#234;ntico ao de cima
	_textSlide : 'textSlide',
	// ID da imagem de play|pause
	_playPause : 'playpause',
	// ID da div que mostra ou esconde as op&#231;&#245;es de customiza&#231;&#227;o de tempo
	// essa op&#231;&#227;o pode ser omitida do usu&#225;rio, basta retirar o bot&#227;o
	// settings da p&#225;gina, e como a div j&#225; vem com o display:none por
	// padr&#227;o o usu&#225;rio n&#227;o ter&#225; acesso a essas op&#231;&#245;es.
	_showTimer : 'showTimer',
	

	// vari&#225;veis do sistema
	// Daqui para baixo n&#227;o &#233; necess&#225;rio alterar mais nada, aqui o sistema
	// cuidar&#225; de tudo
	_count : 0,
	_length : null,
	_timeOutID : null,
	_pause : false,
	_timer : 4,
	
	// fun&#231;&#227;o que inicia o slide e seta todas os par&#226;metros necess&#225;rios
	start : function(){
		with(this){
			_preLoader();
			_length = _imagens.length;
			_work(); 
		}
	},
	
	// faz o pr&#233;-carregamento das imagens
	_preLoader : function(){
		for(x in this._imagens){
			var image = new Image();
			image.src = this._imagens[x][0];
		}
	},
	
	// fun&#231;&#227;o principal que faz as checagens necess&#225;rias
	_work : function(){
		with(this){
			(_count == _length) ? _count = 0 : (_count < 0) ? _count = _length-1 : void(0);
			var current = _imagens[_count];
			_exchange(current);
			if(!_pause){
				(typeof(_timeOutID) == "number") ? clearTimeout(_timeOutID) : void(0);
				_timeOutID = setTimeout(
						function(){
							slide.next();
							fade(0,0,$(_slideImg));
						}, (Number(_timer)*1000)
				);
			}
		}
	},
	
	// fun&#231;&#227;o que altera os elementos da p&#225;gina, altere os IDs se necess&#225;rio
	_exchange : function(img){
		this.$(this._slideImg).src = img[0];
		this.$(this._titleSlide).innerHTML = img[1];
		this.$(this._textSlide).innerHTML = img[2];
		this.$(this._linkSlide).href = img[3];
		this.fade(0,100,this.$(this._slideImg));
	},
	
	// altera para o pr&#243;ximo slide ao clicar no bot&#227;o Pr&#243;ximo
	next : function(){
		with(this){
			_count++;
			_work();
		}
	},
	
	// altera para o slide anterior ao clicar no bot&#227;o correspondente
	previous : function(){
		with(this){
			_count--;
			_work();
		}
	},
	
	// pausa e continua a apresenta&#231;&#227;o
	pause : function(){
		var img = this.$(this._playPause);
		if(this._pause){
			this._pause = false;
					img.src = 'imgs/pause.gif';
				img.title = 'Parar';
		}
		else{
			this._pause = true;
					img.src = 'imgs/play.gif';
				img.title = 'Continuar';
		}
		with(this){(typeof(_timeOutID) == "number") ? clearTimeout(_timeOutID) : void(0); _work();}
	},
	
	// controla o tempo de troca de cada slide
	tControl : function(act){
		with(this){
		(act=="m")?((_timer==4)?void(0):_timer=_timer-1):((_timer==9)?void(0):_timer= _timer +1);
			this.$(this._showTimer).innerHTML = _timer+"s";	
		}
		
	},
	
	// altera a opacidade do elemento e suaviza a transi&#231;&#227;o entre os slides
	fade : function (){
		
		var type,signal;
		var from 	= arguments[0];
		var to		= arguments[1];
		var el		= arguments[2];
		
		(document.all) ? type = 'filter' : type = 'opacity';
		(from>to) ? signal = '-' : signal= '+';
		
		if(from >= to/2){
			from = eval(from+signal+10);
		}else{
			from = eval(from+signal+5);
		}
		
		if(type=='opacity'){
			try{el.style[type] = Number(from*0.01); }catch(e){}
		}else{
			try{el.style[type] = 'alpha(opacity='+from+')'; }catch(e){}
		}
		
		if(from != to){
			setTimeout( function(){ slide.fade(from,to,slide.$(slide._slideImg)); } ,50);
		}
	},
	
	// retorna o elemento solicitado atrav&#233;s de seu ID
	$ : function(){
		return document.getElementById(arguments[0]);	
	}
}