// configurações do album //////////////////
albumName = id_album;
imagesPath = path_fotos;

// Preview
(preview == '1') ? prv = '_tmp_' : prv = '';

// Pega as variáveis passada na url
getParser(location.href);

// 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]+"'");
	}
}
////////////////////

if (typeof(abrefoto) == "undefined") {
	(thumb_order == 'ASC') ? fotoabre = fotodefault : fotoabre = parseInt(fotodefault)+2;
} else {
	(thumb_order == 'ASC') ? fotoabre = abrefoto-1 : fotoabre = parseInt(abrefoto)+1;
}

if (fotoabre==-1)
   fotoabre = (Math.round((Math.random()*(thumbs-1))+1))
   
atual=fotoabre-1;

slideTime = 0;
timeOutId = -1;
timeOutIdDelay = -1;
lastActive = 0;
topPosition = 0;
now = new Date();
pos = new Array();

function goURL()
{
if (document.formURL.selectURL.options[document.formURL.selectURL.selectedIndex].value != 0) 
	{
	// alert(document.formURL.selectURL.options[document.formURL.selectURL.selectedIndex].value);
	parent.document.location = document.formURL.selectURL.options[document.formURL.selectURL.selectedIndex].value;
	}
else 
	{ 
        return false; 
       }
}

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");
		
		// 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>');
}

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"; }
}

function setSlideTime()
{
slideTime = (document.slide.time.checked==true) ? 4 : 0; 
clearTimeout(timeOutId);
if(slideTime!=0) showPicture(atual,2)
}

function scrollThumbs()
{
clearTimeout(timeOutId);
calc = (thumb_order == 'DESC') ? credito.length-atual : atual+1 ;
topPosition = 70 * (calc-2);
document.getElementById('thumbs').scrollTop = topPosition;
}

function showPicture(id)
{
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]);

tm = tamanho[atual].split("x");
if (tm[0]==300 && tm[1]==200) { pos[0]=70; pos[1]=150; idimagem='imagemhorizontal300x200'; } // imagem 300x200
else if(tm[0]<tm[1]) { pos[0]=0; pos[1]=150; idimagem='imagemvertical'; } // imagens verticais
else { pos[0]=70; pos[1]=0; idimagem='imagemhorizontal'; } // imagens horizontais (excluindo 300x200)

if (url[atual] != "") urlat = "<br><a href=" + url[atual] + " class=leiamais>Mais</a>";
else urlat = "";

out = '<div id='+idimagem+'><img src="'+imagesPath+'/'+prv+albumName+'_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>';

document.getElementById('fotos').innerHTML = out;

if(idimagem.indexOf('imagemhorizontal')!=-1)document.getElementById(idimagem).style.top = pos[0];
document.getElementById(idimagem).style.left = pos[1];

document.getElementById('t'+lastActive).style.borderWidth = 0;
document.getElementById('t'+lastActive).style.margin = 2;
lastActive = atual;
document.getElementById('t'+atual).style.borderColor = activeColor;
document.getElementById('t'+atual).style.borderWidth = 2;
document.getElementById('t'+lastActive).style.margin = 0;

parent.albx.location.href = albumName +'_album-hit.htm'; // dá um hit no servidor

if(slideTime!=0) timeOutIdDelay = delay();
}

function delay()
{
clearTimeout(timeOutIdDelay);
if(document.images["imgcomplete"].complete==true) timeOutId = setTimeout('showPicture(atual,2)',slideTime*1000); 
else timeOutIdDelay = setTimeout("delay()",1000);
}

function showThumbs()
{
out = "";

if (thumb_order == "DESC") for (i=credito.length-1;i>=0;i--) out += '<div id="t'+i+'" class="thumbimg" onclick="showPicture('+i+')" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';"><div class="thumblnk"><img src="'+imagesPath+'/'+prv+albumName+'_t_'+pictureName(i)+'.jpg?ts='+timestamp+'" width="66" height="66" border="0"></div><div class=chapeu><div class="outer"><div class="middle"><div class="spacer">'+ chapeu[i] +'</div></div></div></div></div>';
else for (i=0;i<credito.length;i++) out += '<div id="t'+i+'" class="thumbimg" onclick="showPicture('+i+')" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';"><div class="thumblnk"><img src="'+imagesPath+'/'+prv+albumName+'_t_'+pictureName(i)+'.jpg?ts='+timestamp+'" width="66" height="66" border="0"></div><div class=chapeu><div class="outer"><div class="middle"><div class="spacer">'+ chapeu[i] +'</div></div></div></div></div>';

document.getElementById('thumbs').innerHTML = "<div id=insidethumbs>"+ out +"</div>";
}

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;
}

function startAlbum()
{
showThumbs();
showPicture(atual,2);
if (document.getElementById('bannertop')) loadBanner();
}