//galeria = new galeriart("http://www.undergoogle.com/blog/wp-content/uploads/2008/01/google-and-apple.jpg»A maçă do google. Escreveram [Google] na casca da maçă. Năo sei exatamente qual é o motivo, mas o fato é que eu peguei esta imagem na pesquisa do google mesmo para colocar uma legenda e também por que a que tinha antes era muito grande«http://laughingsquid.com/wp-content/uploads/fsm-google-doodle.png»Imagem estranha do google«http://www.softfacade.com/upload_fck/image/google-lego-logo.jpg»Google com pecinhas de encaixar«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste«http://www.imotion.com.br/imagens/data/media/65/the-simpsons-XP_www.imotion.com.br.jpg»Imagem de teste", "galeria_render", "pelicula_render");

/*
	Biblioteca desenvolvida por Rafael Tonello
	para saber mais sobre e utilizar entre em 
	contato: tonello.rafinha@gmail.com
*/
function FaderEffect(id, inicio, fim, incremento, delay, opacity_att){
	//iniciar a funçăo
	if (inicio == null){
		inicio = 0;
	}
	if (fim == null){
		fim = 100;
	}
	if (incremento == null){
		incremento = 10;
	}
	if (delay == null){
		delay = 100;
	}
	opa_ini = inicio/100;
	opa_fim = fim/100;
	opa_inc = incremento/100;
	
	inicio = parseInt(inicio);
	fim = parseInt(fim);
	
	if (opacity_att == null){
		if (inicio < fim){
			opacity_att = opa_ini - opa_inc;
		}
		else{
			opacity_att = opa_ini + opa_inc;
		}
		document.getElementById(id).style.opacity = opa_ini;
	}
	//iniciar o efeito
	if (inicio < fim){
		//efeito surgir
		n_opacity = opacity_att + opa_inc;
		document.getElementById(id).style.opacity = n_opacity;
		document.getElementById(id).style.filter = "alpha(opacity="+n_opacity*100+")";
		funcao = "FaderEffect('"+id+"',"+inicio+","+fim+","+incremento+","+delay+","+n_opacity+")";
		if (n_opacity < opa_fim){
			setTimeout(funcao, delay);
		}
		else{
			//concluido
			document.getElementById(id).style.opacity = opa_fim;
			document.getElementById(id).style.filter = "alpha(opacity="+opa_fim*100+")";
		}
	}
	else if (inicio > fim){
		//efeito esconder
		n_opacity = opacity_att - opa_inc;
		document.getElementById(id).style.opacity = n_opacity;
		document.getElementById(id).style.filter = "alpha(opacity="+n_opacity*100+")";
		funcao = "FaderEffect('"+id+"',"+inicio+","+fim+","+incremento+","+delay+","+n_opacity+")";
		if (n_opacity > opa_fim){
			setTimeout(funcao, delay);
		}
		else{
			//concluido
			document.getElementById(id).style.opacity = opa_fim;
			document.getElementById(id).style.filter = "alpha(opacity="+opa_fim*100+")";
		}

	}
}
function ShowPelicula(imagem, legenda, id_destino){
	document.getElementById(id_destino+"_zoomimg").src = imagem;
	document.getElementById(id_destino+"_legenda").innerHTML = legenda;
	document.getElementById(id_destino+"_ampdiv").style.display = 'block';
	if (navigator.appName != 'Microsoft Internet Explorer'){
		FaderEffect(id_destino+"_ampdiv", 0, 60, 6, 50); //temp de 1 segundo
		setTimeout("ShowPelicula2('"+id_destino+"_imgdiv')",200); // delay de 1/10 segundo
	}else{
			document.getElementById(id_destino+"_imgdiv").style.display = 'block';
	}
}

function ShowPelicula2(id_imagem){
	document.getElementById(id_imagem).style.display = 'block';
	FaderEffect(id_imagem, 0, 100, 10, 50); //temp de 1 segundo
}

function galeriart(imgs, id_destino, id_destino_pelicula, ch_split, ch_split_leg){
	this.charsplit;
	var separalegenda;
	var div_pelicula;
	var imagens = new Array();
	var imagens_total = 0;
	var imagens_posi;
	this.img; //new image
	
	
	function E(id){
		return document.getElementById(id);
	}
	
	function addHtml(texthtml){
		E(id_destino).innerHTML += texthtml;
	}
	
	function addImg(imagem, legenda){
		if (legenda == null){
			legenda = "";
		}
		tag = "<img src=\""+imagem+"\" style=\"width:100px; height:80px; float:left; margin:5px; cursor:pointer;\" onClick=\"ShowPelicula('"+imagem+"','"+legenda+"','"+id_destino+"')\"/>";
		addHtml(tag);
	}
		
	this.inicia = function(){
		//construir o objeto
		if (ch_split == null){
			this.charsplit = '«';
		}
		else{
			this.charsplit = ch_split;
		}
		
		if (ch_split_leg == null){
			separalegenda = '»';
		}
		else{
			separalegenda = ch_split_leg;
		}
		
		if (id_destino_pelicula == null ){
			div_pelicula = id_destino;
		}
		else{
			div_pelicula = id_destino_pelicula;
			
		}		
		
		imagens = imgs.split(this.charsplit); 
			
		imagens_total = imagens.length;
		imagens_posi = 0;
		//aumentar a altura do objeto de destino
		horizontais = parseInt(parseInt(document.getElementById(id_destino).style.width) / 110);
		linhas = parseInt(imagens_total/horizontais)+1;
		document.getElementById(id_destino).style.width = linhas*90+"px";
		
		//desenhar a pelicula
		adicionar = "<div id=\""+id_destino+"_ampdiv\" style=\"position:fixed; -position:absolute; top: expression( ( 0+( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + ‘px’ ); top:0px; left:0px; width:100%; height:100%; -width:"+document.body.clientWidth+"px; -height:"+document.body.clientHeight+"px; background:#000000; z-index:3; display:none; opacity:0.6; *filter:alpha(opacity=60);\"></div>";
		
		adicionar += "<div id=\""+id_destino+"_imgdiv\" style=\"width:500px; position:fixed; -position:absolute; top: expression( ( 0+( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + ‘px’ ); left:50%; margin-left:-250px; top:10px; background:none; color:#FFFFFF; z-index:4; opacity:1; *filter:alpha(opacity=100); display:none;\" onClick=\"document.getElementById('"+id_destino+"_ampdiv').style.display = 'none'; document.getElementById('"+id_destino+"_imgdiv').style.display = 'none';\">";
		adicionar += "<div style=\"text-align:right; color:#FF0000; font-weight:bold; font-size:20px; width:500px; cursor:pointer;\" title=\"Fechar\">X</div>";
		adicionar += "<img src=\"#\" id=\""+id_destino+"_zoomimg\" style=\"width:500px; padding:5px; background:#FFFFFF;\"><br/><div id=\""+id_destino+"_legenda\" style=\"text-align:justify;\"></div></div>";
		
		E(div_pelicula).innerHTML += adicionar;
		
		//E(div_pelicula).innerHTML += "<div id=\""+id_destino+"_imgdiv\" style=\"width:500px; height:300px; position:fixed; -position:absolute; left:50%; margin-left:-250px; top:50%; margin-top:-150px; background:none; color:#FFFFFF; z-index:4; opacity:1; *filter:alpha(opacity=100); display:none;\" onClick=\"document.getElementById('"+id_destino+"_ampdiv').style.display = 'none';\" ><img src=\"#\" id=\""+id_destino+"_zoomimg\" style=\"width:500px; height:300px\" onClick=\"document.getElementById('"+id_destino+"_ampdiv').style.display = 'none'; document.getElementById('"+id_destino+"_imgdiv').style.display = 'none';\"><br/><span id=\""+id_destino+"_legenda\"</div>";
		
		if (navigator.appName == 'Microsoft Internet Explorer'){
			this.renderSimple();
		}
		else{
			render();
		}
	}
	
	function render(){
		
		if (imagens_posi < imagens_total){
			img_att = imagens[imagens_posi];
			imagem_endereco = img_att.split(separalegenda)[0];
			imagem_legenda = img_att.split(separalegenda)[1];
			this.img = new Image();
			this.img.src = imagem_endereco;
			//mensagem com o total de imagens
			
			this.img.onload = function(){
				addImg(imagem_endereco, imagem_legenda);
				imagens_posi++;
				render();
			}
		}
	}
	
	this.renderSimple = function(){
		for (cont = 0; cont < imagens_total; cont++){
			img_att = imagens[cont];
			imagem_endereco = img_att.split(separalegenda)[0];
			imagem_legenda = img_att.split(separalegenda)[1];
			addImg(imagem_endereco, imagem_legenda);
		}
	}
	
	this.inicia();
}