/// browser ///
ie4 = document.all;
ie = (document.all)? true:false;
nn4 = document.layers;
n4 = nn4;
ie5 = (ie && navigator.appVersion.indexOf('MSIE 5')>0)? true:false;
ie6 = (ie && navigator.appVersion.indexOf('MSIE 6')>0)? true:false;
if(ie6)
	ie5 = true;

ver4 = ie4 || nn4;
currScoreElem = null;
var improc = ver4 || ie5;


/// funcoes ///

function elem(objname)
{
	if(nn4 != null)
		return document.layers[objname];
	else
		return obj(objname);
}

function obj(objname){
	return document.getElementById(objname);
}

function hide(object) {
	if(!object)
		return;
	obj(object).style.visibility = 'hidden';
}

function show(object) {
	if(!object)
		return;
	obj(object).style.visibility = '';
}

/// processamento de imagem //

var bew = false;
var afonte = null;

function bw() {
	if (document.images.foto.src!=null && afonte==null)
		afonte=document.images.foto.src;

	if (afonte!=null)
	{
		show('wait');
		//document.images.wait.src="/img/wait.gif";
		bew = !bew;
		if (bew)
			{
			document.images.foto.src=afonte+'&pb=1';
			document.images.bandw.src='/img/cor.gif';
		}
		else
		{
			document.images.foto.src=afonte;
			document.images.bandw.src='/img/bw.gif';
		}
	}
}


/// fundo das fotos ///

var corseleccionada='#ffffff';

function bg(color){
	corseleccionada=color;

	elem("fotobg").style.backgroundColor = color;

	if (color == '#ffffff')
	{
		show("fotoframetop");
		show("fotoframebottom");
		show("fotoframeleft");
		show("fotoframeright");
		elem("fotobg").style.padding = "0px"
		}
	else
	{
		hide("fotoframetop");
		hide("fotoframebottom");
		hide("fotoframeleft");
		hide("fotoframeright");
		elem("fotobg").style.padding = "30px"
	}
}


/// Zoom das miniaturas do SuperImagens ///

var passosizefoto=40;
var ozoom = true;
var factorfoto = 1.5;
var factorthumb = 2;
var origwid = 0;
var orighei = 0;
var widhei = 0;

var objectoimg;

function zoom()	{

	objectoimg = elem("foto");
	oicon = elem("ozoom");

	if (origwid==0) {
		origwid = objectoimg.width;
		orighei = objectoimg.height;
		widhei = origwid/orighei;
	}

	var oTamanhoHor = origwid*factorfoto;
	var MaxSize = windowSize()-150;

	if (ozoom)
	   {
		zoomin( ((MaxSize < oTamanhoHor) ? MaxSize : oTamanhoHor), widhei, passosizefoto);
		oicon.src='/images/lupamais.gif';
	   }
	else
	{
		zoomout(origwid, widhei, passosizefoto);
		oicon.src='/images/lupamenos.gif';
	}
	
	ozoom = !ozoom;
}

var zoominligado = false;
var zoomoutligado = false;
var passosizethumb=15;
var origwidthumb = 0;
var origheithumb = 0;
var widheithumb = 0;
var ozoomthumb = true;
var ficheiro = '';


function fotozoom(nomeobjecto)	{

	objectoimg = elem(nomeobjecto);

	if (origwidthumb==0) {
		origwidthumb = objectoimg.width;
		origheithumb = objectoimg.height;
		widheithumb = origwidthumb/origheithumb;
	}

	var oTamanhoHor = origwidthumb*factorthumb;
	var oTamanhoVer = origheithumb*factorthumb;

	if (ozoomthumb)
	   {
		zoomin(oTamanhoHor, widheithumb, passosizethumb);
		ficheiro = objectoimg.src;

		if (origwidthumb > origheithumb)
			{
			if (objectoimg.src != ficheiro+"&tm="+oTamanhoHor)
				objectoimg.src = ficheiro;
			}
		else
			{
			if (objectoimg.src != ficheiro+"&tm="+oTamanhoVer)
				objectoimg.src = ficheiro;
			}

		ozoomthumb = !ozoomthumb;
	   }
	else
	{
		zoomout(origwidthumb, widheithumb, passosizethumb);
		origwidthumb=0;

// Não há necessidade de recarregar o original
// Criar uma classe para ver se o thumb já mudou

		if (ficheiro!='')
			{
			objectoimg.src=ficheiro;
			ficheiro='';
		}
		ozoomthumb = !ozoomthumb;
	}
}


function zoomin(novotamanhohor, conversao, passoresize) {

	if (zoomoutligado)
		return true;

	if (objectoimg.width < novotamanhohor)
		{

		var otamanhohor = objectoimg.width+passoresize;

		if (otamanhohor > novotamanhohor) 
			{ otamanhohor=novotamanhohor;	}

		var otamanhover = otamanhohor/conversao;

		resizeobj(objectoimg, otamanhohor, otamanhover);
		setTimeout("zoomin("+novotamanhohor+","+conversao+","+passoresize+")",0);
		}
		else
		{
		return true;
	}
}



function zoomout(novotamanhohor, conversao, passoresize) {

	zoomoutligado=true;

	if (objectoimg.width > novotamanhohor)
		{

		var otamanhohor = objectoimg.width-passoresize;

		if (otamanhohor < novotamanhohor) 
			{ otamanhohor=novotamanhohor;	}

		var otamanhover = otamanhohor/conversao;

		resizeobj(objectoimg, otamanhohor, otamanhover);
		setTimeout("zoomout("+novotamanhohor+","+conversao+","+passoresize+")",0);
		}
		else
		{
		zoomoutligado=false;
		return true;
	}
}


function resizeobj(Obj,width,height) {
	Obj.width = width; Obj.height = height; obj.refresh; return true;
}



/// Opacidade ///

function Opacidade(objId, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  objId.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  objId.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  objId.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  objId.style.opacity = opacity/100;
}


/// funções de tempo ///

function wait(millis) 
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); } 
while(curDate-date < millis);
} 



/// Tamanho do Ecrã ///

function windowSize() {

  var myWidth = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;

  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;

  }
  return myWidth;
}

/// botão direito do rato ///
/// document.oncontextmenu = new Function("return false"); ///


/// POP-UP ///


/// Votos ///

function votar(valor) {

	objvoto = elem('voto');
	objcaixa = elem('caixavoto');

	if (valor==0) {

		objvoto.src='img/nothumbs.gif';
		objcaixa.style.backgroundColor='#f0f0f0';

		} else if (valor==1) {

		objvoto.src='img/thumbsup.gif';
		objcaixa.style.backgroundColor='#c0ffc0';

		} else {

		objvoto.src='img/thumbsdown.gif';
		objcaixa.style.backgroundColor='#ffc0c0';

	}
}