// JavaScript Document


function jsDisplay(){

	this.instanceName = null;
	this.parent = null;
	this.duration = 5;
	this.width = null;
	this.height = null;
	this.show_legend = false;
	
	this.execute = function(){
		var $browserName = (navigator.appName.indexOf('Netscape') > -1) ? 'NS' : 'IE';
		
		//configurar objeto de referencia
		var $__instanceName = this.instanceName;
		var $__duration = this.duration;
		var $__parent = document.getElementById(this.parent);
		var $__width = this.width;
		var $__height = this.height;
		var $__subtitle = this.subtitle;
		var $__getURL = this.getURL;		

		//links
		var $__imgURL = $__parent.getElementsByTagName('a');
		var $__url = new Array($__imgURL.length);
		
		//Carrega as imagens
		var $__imagens = $__parent.getElementsByTagName('img');		
		var $__gallery = new Array($__imagens.length);
		
		//legendas
		var $__subtitle = new Array($__imagens.length);
		this.preloadImg('bgLegend.png');
		for (i=0;i<$__imagens.length;i++){
			$__imagens[i].style['display']='none';
			$__gallery[i] = this.preloadImg($__imagens[i].src).src;
			$__subtitle[i] = $__imagens[i].title;
		}
			
		//Objeto onde as imagens serão projetadas
		with($__parent){
			setAttribute('class', 'jsDisplay');
			className = 'jsDisplay';
			style['overflow']	= 'hidden';
			style['width'] = $__width;
			style['height'] = $__height;
			style['background'] = '#000 URL(' + $__gallery[0] + ')';
			onclick = function() {location.href = $__imgURL[0];}
		}
		
		showLegend($__instanceName, $__subtitle[0], $__parent);
				
		//Projeção das imagens
		var $__count = 1;		
		var $__slider = setInterval(
			function(){
				if($__count<$__gallery.length){
										
					//efeito de transparencia absoluta
					var $__opacity = 0;
					if($browserName == 'NS'){ $__parent.style['opacity'] = 0; }else{ $__parent.style['filter'] = "alpha(opacity=0)";	}
					//atribui link
					$__parent.onclick = function(){location.href = $__imgURL[$__count-1]};
					$__parent.style['background'] = 'url(' + $__gallery[$__count] + ')';															
					
					showLegend($__instanceName, $__subtitle[$__count], $__parent);
					
					//efeito de transparencia gradual
					var $__fader = setInterval(
						function(){
							if($__opacity<=100){
								if($browserName == 'NS'){ $__parent.style['opacity'] = ($__opacity / 100); }else{ $__parent.style['filter'] = "alpha(opacity=" + $__opacity + ")";	}
								$__opacity = $__opacity + 2;								
							}else{
								if($browserName == 'NS'){ $__parent.style['opacity'] = 1; }else{ $__parent.style['filter']="alpha(opacity=100)";	}									
								clearInterval($__fader);								
							}
						}
					,1);					
					
					$__count ++;
				}else{
					$__count=0;
				}
			}
		, $__duration * 1000);		
	},
	
	this.preloadImg = function(url){
		if (url){
			var imgPl = new Image();
			imgPl.src = url;
			return imgPl;
		}
	}
	
	//Objeto onde as legendas serão projetadas
	function showLegend($_name, $_str, $_trg){
		var $__legend = document.createElement('div');		
		with($__legend){			
			setAttribute('id', $_name + '_LegendBar');		
			setAttribute('class', 'jsLegendBar');
			className = 'jsLegendBar';	
			innerHTML = $_str;
			style['top'] = ($_trg.offsetHeight - 40) + 'px';
		}
		if(!document.getElementById($_name + '_LegendBar')) {
			$_trg.appendChild($__legend);
		}else{
			document.getElementById($_name + '_LegendBar').innerHTML = $_str;
		}
	}
	
}
