// JavaScript Document

var ss;
var fadein_opacity = 0.04;
var fadein_img;

// exibe determinado album
function mostraAlbum(idAlbum, pagina) {
	
	$('spaPaginaAtual').innerHTML = pagina;
	var pars   = 'idAlbum=' + idAlbum;
	var url    = 'paginas/mostraAlbum.php';
	var myAjax = new Ajax.Updater( {success: 'divConteudo'}, url, {method: 'get', parameters: pars, onFailure: reportError});
	
}

// exibe determinada foto
function mostraFoto(idFoto) {
	
	var pars   = 'idFoto=' + idFoto;
	var url    = 'paginas/mostraFoto.php';
	var myAjax = new Ajax.Updater( {success: 'divFotoAmpliada'}, url, {method: 'get', parameters: pars, onFailure: reportError});
	
}

// exibe o slideshow do álbum
function mostraSlideShow(idAlbum) {
	
	var pars   = 'idAlbum=' + idAlbum;	
	var url    = 'paginas/mostraSlideShow.php';
	var myAjax = new Ajax.Updater( {success: 'divConteudo'}, url, {method: 'get', parameters: pars, onComplete: setSlides, onFailure: reportError});
	
}

function setSlides() {
	
	ss = new slideshow("ss");
	ss.timeout = 5000;
	
	// album nao publicado ou vazio
	if (!$("divSlides")) {
		return;
	}
	
	var fotos = $("divSlides").getElementsByTagName("div");
	
	//percorre as divs de slides para extrair os dados
	for (var i = 0; i < fotos.length; ++i) {
		
		var itens = fotos[i].getElementsByTagName("span");
		//contéudo dos spans carregados
		var legenda   =  itens[0].innerHTML;
		var src       =  itens[1].innerHTML;
		var descricao =  itens[2].innerHTML;
		
		s = new slide();
		s.title = url_decode(legenda);
		s.src = url_decode(src);
		s.text = url_decode(descricao);
		//s.link = "";
		//s.target = "";
		//s.attr = "";
		//s.filter = "";
		//s.timeout = "";
		ss.add_slide(s);
		
		//custom filters for Microsoft IE
		s.filter = 'progid:DXImageTransform.Microsoft.Fade()';
		
	}
	
	runSlides();
	
}
	
// Set up the select list with the slide titles
function config_ss_select() {
  var selectlist = $('ss_select');
  if (selectlist) {
	  selectlist.options.length = 0;
	  for (var i = 0; i < ss.slides.length; i++) {
		selectlist.options[i] = new Option();
		selectlist.options[i].text = (i + 1) + '. ' + ss.slides[i].title;
	  }
	  selectlist.selectedIndex = ss.current;
  }
}

function runSlides() {
	
	// Finish defining and activating the slideshow
	
	// If you want some code to be called before or
	// after the slide is updated, define the functions here
	
	ss.pre_update_hook = function() {
	  // For the select list with the slide titles,
	  // set the selected item to the current slide
	  if ($('ss_select')) {
		  $('ss_select').selectedIndex = this.current;
	  }
	  else {
		  this.fim = true;
	  }
	  return;
	}
	
	ss.post_update_hook = function() {
	  fadein(0.04);
	  return;
	}
	
	if (document.images) {
	
	  // Tell the slideshow which image object to use
	  ss.image = document.images.ss_img;
	  
	  fadein_img = ss.image;
	
	  // Tell the slideshow the ID of the element
	  // that will contain the text for the slide
	  ss.textid = "ss_text";
	
	  // Randomize the slideshow?
	  // ss.shuffle();
	
	  // Set up the select list with the slide titles
	  config_ss_select();
	
	  // Update the image and the text for the slideshow
	  ss.update();
	
	  // Auto-play the slideshow
	  ss.play();
	}
	
	ss.update();
	
}

// Create a function to ramp up the image opacity in Mozilla
function fadein(opacity) {
  if (typeof opacity != 'undefined') { fadein_opacity = opacity; }
  if (fadein_opacity < 0.99 && fadein_img && fadein_img.style &&
      typeof fadein_img.style.MozOpacity != 'undefined') {
    fadein_opacity += .05;
    fadein_img.style.MozOpacity = fadein_opacity;
    setTimeout("fadein()", 50);
  }
}
