// 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 = parseInt(abrefoto)-1 : fotoabre = parseInt(abrefoto)+1;
}

atual=fotoabre-2;

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) 
	{
	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 * (parseInt((calc+1)/2)-2);
document.getElementById('thumbs').scrollTop = topPosition;
}

function showPicture(id)
{
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 = imagesPath+'/'+albumName+'_f_'+pictureName(atual)+'.jpg';

tm = tamanho[atual].split("x");
if (tm[0]==300 && tm[1]==200) { pos[0]=7; pos[1]=15; idimagem='imagemhorizontal300x200'; } // imagem 300x200
else if(tm[0]<tm[1]) { pos[0]=0; pos[1]=15; idimagem='imagemvertical'; } // imagens verticais
else { pos[0]=7; pos[1]=0; idimagem='imagemhorizontal'; } // imagens horizontais (excluindo 300x200)

if (url[atual] != "") urlat = "<a href="+ url[atual] +">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" class="sem-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]+"em";
document.getElementById(idimagem).style.left = pos[1]+"em";
document.getElementById(idimagem).getElementsByTagName('img')[0].style.width = tm[0].substring(0,2)+"em";

document.getElementById('t'+lastActive).style.borderWidth = 0;
document.getElementById('t'+lastActive).style.margin = "0.2em";
lastActive = atual;
document.getElementById('t'+atual).style.borderColor = activeColor;
document.getElementById('t'+atual).style.borderWidth = "0.2em";
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 (n=0,i=credito.length-1;i>=0;n++,i--) out += '<a href=javascript:showPicture('+i+') class="thumblnk"><img src="'+imagesPath+'/'+prv+albumName+'_t_'+pictureName(i)+'.jpg?ts='+timestamp+'" 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="'+imagesPath+'/'+prv+albumName+'_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 = out;
}

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();
}


