var t_out;
var pictureChanged = false
var currfoto;



function picchanged()
{
	return (document.data.foto.value != document.fotografia.src);
}

function GetImage()
{
	if (picchanged())
	{
		with (document.data)
		{
			Img = new Image();
			Img.src = foto.value;
			clearTimeout(t_out)
			largura.value = Img.width;
			altura.value = Img.height;
			ratio = 100/Img.width
			with(document.fotografia)
			{
				width = Img.width * ratio;
				height = Img.height * ratio;
				src = Img.src;
				style.position = 'relative';
				style.visibility = 'visible';
			}
		}

	}
	t_out=setTimeout('GetImage()',100)
}

function limpar_foto()
{
	if (confirm("Voce está apagando a foto referente a esta noticia.\nClique OK para apagar."))
	{
		with( document.fotografia.style)
		{
			position = 'absolute';
			visibility = 'hidden';
		}
		with (document.data)
		{
			foto.value = '';
			hasphoto.value = '';
		}
		clearTimeout(t_out);
	}

}

function apaga_foto(url)
{
	if ( confirm("Voce está apagando esta foto.\nClique OK para apagar.") )
	{
		location.href = url;
	}
}


// PhotoRecords 

function PhotoRecord(codigo, arquivo, descricao, largura, altura)
{
	this.codigo = codigo;
	this.arquivo = arquivo;
	this.descricao = descricao;
	this.largura = largura;
	this.altura = altura;
}


function foto_html(PhotoRecord)
{

	var html , ratio , largura , altura, file;
	ratio = ( 160 / PhotoRecord.largura )
	largura = PhotoRecord.largura * ratio;
	altura = PhotoRecord.altura * ratio;  
	largura = parseInt(largura);
	altura = parseInt(altura);
	thmbsrc = 'thumbnail.asp?foto=' + PhotoRecord.arquivo + '&width=' + largura
	file = '<a href="javascript:zoompre(\'' + domaindir('/fotos/') + PhotoRecord.arquivo + '\',600,' + PhotoRecord.largura + ',' + PhotoRecord.altura + ');">'
	file += '<img src="' + thmbsrc + '" width="' + largura + '" height="' + altura + '" border="0">' 
	file += '</a>'
	return file;
}


var PhotoRecords = new Array();

function next_foto()
{
	currfoto++;
	if (!isnumber(currfoto) || currfoto > (PhotoRecords.length - 1) )
		currfoto = 0;
	var lpfoto = PhotoRecords[currfoto];
	foto.innerHTML =foto_html(lpfoto);
}

function prev_foto()
{
	currfoto--;
	if (!isnumber(currfoto) || currfoto < 0 )
		currfoto = 0;
	var lpfoto = PhotoRecords[currfoto];
	foto.innerHTML =foto_html(lpfoto);
}

