// Versão 2.0

/*if(thumb_order == "DESC") {
  credito = credito.reverse();
  legenda = legenda.reverse();
  tamanho = tamanho.reverse();
}*/

var Album =  {

	"$": function () { return document.getElementById(argumes[0]); },

	// objeto do div principal
	"objTable": null,

	// objeto imagem
	"objImagem": null,

	// total de imagens
	"qtdImages": legenda.length,

	// Objeto da última TR clicada
	"objLastDiv": null,
	"numLastFoto": null,

	// monta a primeira lista de imagens
	"montar": function () {

		// obj Table
		this.objTable = $("tblListaFotos");

    /*if(thumb_order == "DESC") {
      credito = credito.reverse();
      legenda = legenda.reverse();
      tamanho = tamanho.reverse();
		  for(var i = 0; i < this.qtdImages; i++)
			 this.createThumbs(i);
		}
		else*/
		  for(var i = this.qtdImages - 1; i >= 0; i--)
			 this.createThumbs(i);

		/* RegExp created via www.regexp.com.br */
		var regExp = new RegExp('(abrefoto=[0-9]{1,3})', 'gi');
		var myString = location.href;

		if(myString.match(regExp) != null) eval("var " + myString.match(regExp));
		else                               var abrefoto = this.qtdImages;

		if(abrefoto > this.qtdImages || abrefoto < 1)
			abrefoto = this.qtdImages;

		this.showImage(abrefoto - 1 , this.objTable.getElementsByTagName("div")[ this.qtdImages - abrefoto ])

		this.scrollThumbs();

	},

	// Cria a lista de thumbs
	"createThumbs": function (i, acao) {

		// nova DIV
		var objDiv = document.createElement("div");
				objDiv.onclick = function () { Album.showImage(i, this); };
				objDiv.className = "foto";
				if(this.numLastFoto == i)
				{
					objDiv.className +=  " clicado";
					this.objLastDiv  = objDiv;				
				}

		// Se houver imagem a ser exibida
		if(i >= 0)
		{
			// Cria a imagem para o div
		  var objImg = document.createElement("img");
		  		objImg.src = path_fotos + "/" + id_album + "_t_" + (i+1 > 99  ? (i+1) : (( i+1 > 9 ) ? "0"+(i+1) : "00"+(i+1))) + ".jpg?time="+new Date().getTime();

			// Cria todos os elementos
			objDiv.appendChild(objImg);
		}

		this.objTable.appendChild(objDiv);

		return objDiv;
	},


	// Exibe o div "carregando..."
	"carregando": function () {
		// obj div carregando
		var objCarregando = document.getElementById("divCarregando");
		var objAlbumFoto  = document.getElementById("albumFoto");
		var objLegenda    = document.getElementById("albumLegenda");

		// tira o link de 'enviar por e-mail'
		if(document.getElementById("envieEmail")) {
			document.getElementById("envieEmail").style.display = "none";
		}
		
		if(document.getElementById("imprimirAlbum")) {
			document.getElementById("imprimirAlbum").style.display = "none";
		}

		objCarregando.style.display = "block";
		objAlbumFoto.style.display = objLegenda.style.display = "none";

		// se img está completa
		if(this.objImagem.complete)
		{
			objCarregando.style.display = "none";
			objAlbumFoto.style.display = objLegenda.style.display = "block";
			
			// mostra o link de 'enviar por e-mail'
			if(document.getElementById("envieEmail")) {
				document.getElementById("envieEmail").style.display = "block";
				// document.getElementById("envieEmail").getElementsByTagName("a")[0].href = "http://noticias.bol.uol.com.br/enviar.jhtm?url=http://fotos.noticias.bol.uol.com.br/"+location.href.replace(/http:\/\/fotos\.noticias\.bol\.uol\.com\.br\/(.*?)\/(.*).jhtm/, "$1")+"/"+id_album+"_album.jhtm?abrefoto="+(this.numLastFoto+1);
				// document.getElementById("envieEmail").getElementsByTagName("a")[0].href = "http://noticias.bol.uol.com.br/enviar.jhtm?url=http://fotos.noticias.bol.uol.com.br/"+location.href.replace(/\?abrefoto=([0-9]{1,3})/, "").replace(/http:\/\/fotos\.noticias\.bol\.uol\.com\.br\/(.*?)\/(.*).jhtm/, "$1")+"/"+id_album+"_album.jhtm?abrefoto="+(this.numLastFoto+1);
				document.getElementById("envieEmail").getElementsByTagName("a")[0].href = "http://noticias.bol.uol.com.br/indicar-link.jhtm?title="+escape( (typeof nome_album == "undefined" ? titulo_album : nome_album) )+"&url=http://fotos.noticias.bol.uol.com.br/"+location.href.replace(/\?abrefoto=([0-9]{1,3})/, "").replace(/http:\/\/fotos\.noticias\.bol\.uol\.com\.br\/(.*?)\/(.*).jhtm/, "$1")+"/"+id_album+"_album.jhtm?abrefoto="+(this.numLastFoto+1);;
			}
			
			if(document.getElementById("imprimirAlbum")) {
			 document.getElementById("imprimirAlbum").style.display = "block";
			}
		}
		else
			setTimeout("Album.carregando()", 300);
	},

	// Toda preparação (e execução) para exibir uma imagem
	"showImage": function (i) {
		this.numLastFoto = i;
		this.objImagem = null;

		// Retira a classe da antiga DIV ativa
		if(this.objLastDiv != null)
			this.objLastDiv.className = "foto";

		// Guarda o objeto da TR clicada
		this.objLastDiv = typeof(arguments[1]) == "undefined" ? this.objLastDiv : arguments[1];

		// altera a classe da TR clicada
		this.objLastDiv.className += " clicado";

		// Obj do div onde a imagem irá aparecer
		var objFoto = document.getElementById("albumFoto");

		// Remove a imagem anterior
		if(objFoto.getElementsByTagName("img").length > 0)
			objFoto.removeChild(objFoto.getElementsByTagName("img")[0]);

		// Obj do div onde a legenda irá aparecer
		var objLegenda = document.getElementById("albumLegenda");
				objLegenda.innerHTML = "";

		// Pré-carrega as imagens
		this.objImagem = new Image();
		this.objImagem.src = path_fotos + "/" + id_album + "_f_" + (i+1 > 99  ? (i+1) : (( i+1 > 9 ) ? "0"+(i+1) : "00"+(i+1))) + ".jpg?time="+new Date().getTime();

		// div carregando...
		this.carregando();

		// cria o obj da imagem...
		var objImg = document.createElement("img");
		// ... e altera o source para a imagem já carregada		
		objImg.src = this.objImagem.src;
		//objImg.title = credito[this.numLastFoto];

		// cria o objeto
		objFoto.appendChild(objImg);

		// adiciona a legenda
		objLegenda.innerHTML = legenda[this.numLastFoto];
		
		if(url[this.numLastFoto] != "")
			objLegenda.innerHTML += " <a href='"+url[this.numLastFoto]+"'>Mais</a>"

				objLegenda.innerHTML += "<br /><cite>" + credito[this.numLastFoto] + "</cite>";

		// tamanho da imagem
		var tamanhoImg = new Array();
				tamanhoImg = tamanho[this.numLastFoto].split("x");

		objImg.className = tamanho[this.numLastFoto] == "300x200" || tamanhoImg[0] > 325 ? "legendaEmBaixo" : "legendaDoLado";
		document.getElementById("divFoto").className = "ftTam"+tamanho[this.numLastFoto];

		// dá um hit no servidor
		//parent.albx.location.href = id_album + "_album-hit.htm";
		//parent.albx.location.href = id_album + "_album.jhtm";
		parent.albx.location.replace(id_album + "_album.jhtm");
		
		// Omniture
    if( typeof uol_sc != "undefined" && (typeof uol_sc.t).toLowerCase() == 'function'){
      uol_sc.prop5='fotoId ' + (this.numLastFoto+1);
      uol_sc.t();
    }

	},

	"scrollThumbs": function () {
		var calc = this.qtdImages - this.numLastFoto;
		var position = 38 * (calc - 7);
		$("tblListaFotos").scrollTop = position;
	},
	
	"proximo": function () {
	  if(thumb_order == "DESC" && typeof arguments[0] == "undefined") {
	    this.anterior(false);
	    return;
	  }

		// se for a ultima foto, volta para o inicio	
		var lastFoto = !this.numLastFoto ? true : false;

		if(lastFoto)
			this.numLastFoto = this.qtdImages

		// carrega a imagem grande
		this.showImage( this.numLastFoto - 1 );

		// remove a classe da antiga foto ativa
		this.objLastDiv.className = "foto";

		if(lastFoto)
			this.objLastDiv = this.objTable.getElementsByTagName("div")[0];
		else
			this.objLastDiv = this.objLastDiv.nextSibling;

		// coloca o clicado
		this.objLastDiv.className += " clicado";
		
		this.scrollThumbs();
	},
	
	"anterior": function () {
	  if(thumb_order == "DESC" && typeof arguments[0] == "undefined") {
	    this.proximo(false);
	    return;
	  }
		// se for a primeira foto, vai para o fim	
		var firstFoto = this.numLastFoto+1 == this.qtdImages ? true : false;

		if(firstFoto)
			this.numLastFoto = -1;

		// carrega a imagem grande
		this.showImage( this.numLastFoto + 1 );

		// remove a classe da antiga foto ativa
		this.objLastDiv.className = "foto";

		if(firstFoto)
			this.objLastDiv = this.objTable.getElementsByTagName("div")[this.qtdImages-1];
		else
			this.objLastDiv = this.objLastDiv.previousSibling;

		this.objLastDiv.className += " clicado";
		
		this.scrollThumbs();
	}
}

window.onload = function () { Album.montar() };




//EOF













