
// GetMethodParserJS ::: fermads @ uol ////
function getParser(L) {
	d=L.substring(L.indexOf("?")+1);
	c=v=new Array();
	c=d.split("&");
	for(i=0;i<c.length&&c.length>0;i++) {
		v=c[i].split("=");
		if(v.length>1)eval(v[0]+"='"+v[1]+"'");
	}
}
////////////////////

// Pega as variáveis passada na url
getParser(location.href);

// Seta o valor de fotoabre baseado no parâmetro opcional "?abrefoto="
if (typeof(abrefoto) == "undefined") {
	fotoabre = (thumb_order == 'ASC') ? fotodefault : parseInt(fotodefault)+2;
} else {
	fotoabre = (thumb_order == 'ASC') ? abrefoto-1 : parseInt(abrefoto)+1;
}

// se fotoabre for -1, é randômica
if (fotoabre==-1) fotoabre = Math.round((Math.random()*(fotos_total-1))+1);

// ajusta o valor do índice com os nomes dos arquivos
atual=fotoabre-1;

// Valores iniciais
slideTime = 0;
timeOutId = -1;
timeOutIdDelay = -1;
lastActive = 0;
topPosition = 0;
now = new Date();
pos = new Array();

// Troca a URL a partir do dropdown
function goURL() {
	if (document.formURL.selectURL.options[document.formURL.selectURL.selectedIndex].value != 0) 
		parent.document.location = document.formURL.selectURL.options[document.formURL.selectURL.selectedIndex].value;
	else 
		return false;
}

// imprime o dropdown na tela
function writeDrop() {
	if (showdropdown == 0) return;
	document.write('<div id=dropdown><form name="formURL"><select name="selectURL" size=1 onChange="goURL()" style=font-size:10px;font-family:verdana>');
	for(var i=0;i<alb.length;i++) {
		aInfo = alb[i].split("|");
		aInfo[0] = aInfo[0].replace(/.htm\?s/,".jhtm\?s");

		if (aInfo[1].length>40) aInfo[1] = aInfo[1].substr(0,37)+"...";
		
		// Verifica se é um submenu
		if ((aInfo[0]==0) && (aInfo[1]!='')) 
			document.write("<option value='"+ aInfo[0] +"' style='background-color:gray;color:white;'>"+ aInfo[1] +"</option>");
		else 
			document.write("<option value='"+ aInfo[0] +"'>"+ aInfo[1] +"</option>");
	}
	document.write('</select></form></div>');
}

// função para as estações com banners em iframe
function loadBanner() {
	if (typeof(document.images["imgcomplete"].complete) == "boolean") {
		if(document.images["imgcomplete"].complete==true) document.getElementById('bannertop').src="banner-iframe.htm";
		else setTimeout("loadBanner()",500);
	} else {
		document.getElementById('bannertop').src="banner-iframe.htm";
	}
}

// Define o tempo de intervalo para o slide
function setSlideTime() {
	slideTime = (document.slide.time.checked==true) ? 4 : 0;
	clearTimeout(timeOutId);
	if(slideTime!=0) showPicture(atual,2)
}

// Atualiza a área dos thumbs
function scrollThumbs() {
	clearTimeout(timeOutId);
	calc = (thumb_order == 'DESC') ? credito.length-atual : atual+1 ;
	topPosition = 70 * (parseInt((calc+1)/2)-2);
	document.getElementById('thumbs').scrollTop = topPosition;
}

// Exibe a imagem na tela, posicionando-a com base no tamanho e orientação
function showPicture(id) {

	// Se existir o div de banner[iframe], chama a função para rodízio de imagens com publicidade
	if (document.getElementById('banner-588x414')) DEcount();
	
	atual = id;
	
	if(thumb_order=='DESC') {
		if(!arguments[1]) atual++;
		(arguments[1]==1) ? atual++ : atual-- ;
	} else { 
		if(!arguments[1]) atual--;
		(arguments[1]==1) ? atual-- : atual++ ; 
	}

	if(atual>=credito.length) atual = 0;
	if(atual<0) atual = credito.length-1;
	
	if(arguments[1]) scrollThumbs(arguments[1]);
	
	img = new Image();
	img.src = path_fotos+'/'+nome_base+'_f_'+pictureName(atual)+'.jpg';
	if (typeof _ATM != "undefined") _ATM.ATMFC(path_fotos+'/'+nome_base+'_f_'+pictureName(atual)+'.jpg');

	
	// Define o posicionamento da imagem na área de fotos
	tm = tamanho[atual].split("x");
	if (tm[0]==300 && tm[1]==200) {
		// imagem 300x200
		pos[0]=70*factor;
		pos[1]=150*factor;
		idimagem='imagemhorizontal300x200';
	} else if(tm[0]<tm[1]) {
		// imagens verticais
		pos[0]=0*factor;
		pos[1]=150*factor;
		idimagem='imagemvertical';
	} else {
		// imagens horizontais (excluindo 300x200)
		pos[0]=70*factor;
		pos[1]=0*factor;
		idimagem='imagemhorizontal';
	}
	
	// Se url[] estiver preenchida, adiciona o texto "Mais" e o link
	urlat = (url[atual] != "") ? "<a href=" + url[atual] + ">Mais</a>" : "";
	
	out = '<div id='+idimagem+'><img src="'+path_fotos+'/'+nome_base+'_f_'+pictureName(atual)+'.jpg?ts='+timestamp+'" class="fotoimg" name=imgcomplete></div><div id="credito"><div id=cr3><div id=cr2><div id=cr1>'+ credito[atual] +'</div></div></div></div><div id="legenda">'+ legenda[atual] +' <span id=url>'+ urlat + '</span></div>';
	
	// Troca o código da área de fotos
	document.getElementById('fotos').innerHTML = out;
	
	if (idimagem.indexOf('imagemhorizontal')!=-1)
		document.getElementById(idimagem).style.top = pos[0]+meas;
	document.getElementById(idimagem).style.left = pos[1]+meas;
	if (meas=="em")
		document.getElementById(idimagem).getElementsByTagName('img')[0].style.width = tm[0].substring(0,2)+meas;
	
	document.getElementById('t'+lastActive).className = "thumbimg";
	lastActive = atual;
	document.getElementById('t'+atual).className = "thumbimgsel";
	
	parent.albx.location.href = nome_base +'_album-hit.htm'; // dá um hit no servidor
	
	// gera hit Omniture
	if( typeof uol_sc != "undefined" && (typeof uol_sc.t).toLowerCase() == 'function' ){
		uol_sc.prop5='fotoId ' + atual;
		uol_sc.t();
	}
	
	if (slideTime!=0) timeOutIdDelay = delay();
}

// Se imagem ainda não foi carregada, segura o delay
function delay() {
	clearTimeout(timeOutIdDelay);
	if (document.images["imgcomplete"].complete==true)
		timeOutId = setTimeout('showPicture(atual,2)',slideTime*1000);
	else
		timeOutIdDelay = setTimeout("delay()",1000);
}

// Imprima a área dos thumbs
function showThumbs() {
	out = "";
	if (thumb_order == "DESC")
		for (n=0,i=credito.length-1;i>=0;n++,i--)
			out += '<a href=javascript:showPicture('+i+') class="thumblnk"><img src="'+path_fotos+'/'+nome_base+'_t_'+pictureName(i)+'.jpg?ts='+timestamp+'" width="66" height="66" class="thumbimg" id="t'+i+'"></a>'+ ((n+1)%2==0 ? '<BR>' : '');
	else
		for (i=0;i<credito.length;i++)
			out += '<a href=javascript:showPicture('+i+') class="thumblnk"><img src="'+path_fotos+'/'+nome_base+'_t_'+pictureName(i)+'.jpg?ts='+timestamp+'" width="66" height="66" class="thumbimg" id="t'+i+'"></a>'+ ((i+1)%2==0 ? '<BR>' : '');
	document.getElementById('thumbs').innerHTML = "<div id=insidethumbs>"+ out +"</div>";
}

// Padroniza a numeração das fotos
function pictureName(number) {
	number++;
	if (number<10)
		return '00'+number;
	else if (number<100)
		return '0'+number;
	else if (number>=100)
		return number;
	else
		return '00'+number;
}

// Inicia o álbum
function startAlbum() {

	// para estações que usam 'em' ao invés de 'px', chamar a função como startAlbum(1)
	if (arguments[0]) {
		factor = 0.1; meas="em";
	} else {
		factor = 1; meas="px";
	}
	showThumbs();
	showPicture(atual,2);
	
	// se a div de banner[iframe] existir, chama a função de exibição
	if (document.getElementById('bannertop')) loadBanner();
}
