/// 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.fotoMax.src!=null && afonte==null)
		afonte=document.images.fotoMax.src;

	if (afonte!=null)
	{
		Effect.Appear('wait');
		bew = !bew;
		if (bew)
			{
			document.images.fotoMax.src=afonte+'&pb=1';
			document.images.bandw.src='/img/cor.gif';
		}
		else
		{
			document.images.fotoMax.src=afonte;
			document.images.bandw.src='/img/bw.gif';
		}
		Effect.Fade.delay(1,'wait');
	}
}


/// fundo das fotos ///

var corseleccionada='#ffffff';
var apareceu=false;

function bg(color){
	corseleccionada=color;
	
	if (color == '#ffffff') 
		{ 
			if (apareceu==true) { 
					Effect.Fade('modalFoto');
					Effect.Appear('btnScroll', { duration: 0.5 });
					$('btnFechar').hide();
					$('barraFoto').toggleClassName('transparencia30');
					apareceu=false;
				}
			//$('fotoMax').morph('border: 1px solid #e0e0e0;');
			$('fotoMax').style.borderColor='#e0e0e0';
		}
		else 
		{ 
			if (apareceu==false) {
				verificaModalFoto()
				Effect.Appear('modalFoto');
				Effect.ScrollTo('wrapFoto');
				Effect.Appear('btnFechar', { duration: 0.5 });
				$('btnScroll').hide();
				$('barraFoto').toggleClassName('transparencia30');
				apareceu=true;
			}
			
			$('modalFoto').morph('background-color:'+color+';');
			//$('fotoMax').morph('border: 1px solid '+color+';');
			$('fotoMax').style.borderColor=color;
		}
}

// adaptar a modal ao ecrã //
function verificaModalFoto()
{
if ($('modalFoto')!=null) {
	var aAltura = $('divContentWrap').getHeight()+45;
	var aLargura = $('body').getWidth();
	elem("modalFoto").style.width = aLargura+"px";
	elem("modalFoto").style.height = aAltura+"px";
	}
}


function showModal(id) {

objModalWindow=(id+"ModalWindow");
objModalWrap=(id+"ModalWrap");

Effect.Appear(objModalWindow, { from: 0.0, to: 0.6 });
Effect.Appear(objModalWrap, { from: 0.6, to: 1.0 });

}

function hideModal(id) {

objModalWindow=(id+"ModalWindow");
objModalWrap=(id+"ModalWrap");
objModalMsg=(id+"ModalMsg");

Effect.Fade(objModalWindow);
Effect.Fade(objModalWrap);
$(objModalMsg).update('<center><img src="/img/wait2.gif"></center>');

}

function fechaModal()
{
	bg('#ffffff');
	//$('fotoMax').morph('border: 1px solid #e0e0e0;'); 
	$('fotoMax').style.borderColor='#e0e0e0';
	return false;
}




/// Zoom ///
var aThumbs=new Array();

// thumb class //
function thumb(sIdObjecto, index)
{
this.sObjecto=sIdObjecto;
this.oObjecto=$(this.sObjecto);
this.bindIn=zoomInThumb.bindAsEventListener(this.sObjecto,index);
this.bindMove=hZoomMouseMove.bindAsEventListener(this.sObjecto,index);
this.bindOut=hZoomMouseOut.bindAsEventListener(this.sObjecto,index);
this.ficheiro=this.oObjecto.src;
this.ficheiroLrg=this.oObjecto.getAttribute("lrgsrc");
this.preLoad=new Image();
this.preLoad.src=this.ficheiroLrg;
this.largura=this.oObjecto.width;
this.altura=this.oObjecto.height;
this.zoomed=false;
this.zooming=false;
this.mexeu=false;
}
thumb.prototype.zoomIn=zoomIn;
thumb.prototype.zoomInThumb=zoomInThumb;
thumb.prototype.zoomOut=zoomOut;
thumb.prototype.zoomOutThumb;
thumb.prototype.hZoomMouseOut;
thumb.prototype.hZoomMouseMove;
thumb.prototype.factorZoom=2.7;
thumb.prototype.esperaZoom=0.2;
thumb.prototype.duracaoZoomIn=0.2;
thumb.prototype.duracaoZoomOut=0.05;

function hZoomMouseOut(event)
{
var idx = $A(arguments);
idx.shift();
with (aThumbs[idx])
	{
	zooming=false;
	zoomOutThumb.delay(duracaoZoomOut,idx) 
	}
}



function hZoomMouseMove(event)
{
var idx = $A(arguments);
idx.shift();

with (aThumbs[idx])	
	{ if (zooming) { mexeu=true; } 
	// if (zoomed) { zoomOutThumb(idx); } 
	}
}


function zoomIn(idx)
{  
with (this)
	{
	if(mexeu)
		{
		mexeu=false;
		setTimeout('aThumbs['+idx+'].zoomIn('+idx+')', esperaZoom*1000);
		}
	else
		{	
		if (!zoomed && zooming)
			{ 
			$('fZoom').innerHTML="<img id=\"zoomImg\" class=\"fotoThumbZoom shadowThick\" src=\"" + preLoad.src + "\" />";
						
			var osT=-(((factorZoom-1)*altura)/2);
			var osL = largura+10;
			
			$('fZoom').clonePosition(oObjecto, { setLeft: true, setTop: true, offsetLeft: osL, offsetTop: osT });
			
			var zPos = new Element.Layout('fZoom', true);
			var zLeft = zPos.get('left');
			
			if(zPos.get('left')+factorZoom*largura > document.viewport.getWidth()) { zLeft-=largura*(factorZoom+1)+20; $('fZoom').setStyle('left:'+ zLeft +'px'); }
			
			var maxHeight = document.viewport.getScrollOffsets()[1]+document.viewport.getHeight();
			var zTop=maxHeight-(factorZoom*altura)-10;
						
			if(zPos.get('top')+factorZoom*altura > maxHeight) { $('fZoom').setStyle('top: ' + zTop +'px'); }
			if(zPos.get('top') < document.viewport.getScrollOffsets()[1]) { $('fZoom').setStyle('top: ' + document.viewport.getScrollOffsets()[1] + 'px;'); }
			
			Effect.Appear('fZoom', { duration: duracaoZoomIn } );
				
			zooming=false;
			zoomed=true;
			}
		}
	 }
}


function zoomOut()
{ 
with (this) 
	{	
	if (zoomed)
		{
		Effect.Fade('fZoom', { duration: duracaoZoomOut } );
		
		zoomed=false;
		}
		
	Event.stopObserving(sObjecto, 'mousemove', bindMove);
	Event.stopObserving(sObjecto, 'mouseout', bindOut);
	Event.observe(sObjecto, 'mouseover', bindIn);
	}
}

function zoomInThumb(event)
{
 var aThumb = $A(arguments);
 aThumb.shift();
 idx=aThumb.shift();
 with(aThumbs[idx])
	{
		zooming=true;
		Event.observe(sObjecto, 'mousemove', bindMove);
		Event.observe(sObjecto, 'mouseout',  bindOut);
		Event.stopObserving(sObjecto, 'mouseover', bindIn);
		setTimeout('aThumbs['+idx+'].zoomIn('+idx+')',esperaZoom*1000);
	}
	
}

function zoomOutThumb(idx)
{ aThumbs[idx].zoomOut(); }

/// end zoom class ///


/// 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';

	}
}



/// Forms ///

function LigaDesliga(objecto) {

	var objdaform = elem(objecto);
	objdaform.disabled=false;
	
}


/// Validacao Forms ///

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function validaForm(idFrm)
{
var validaForm=true;

$$('.req').each(function(control){
	if (trim(control.value)=="") {
		//control.insert( { 'after': "obrigatório" } );
		control.style.backgroundColor='#ffffc0';
		validaForm=false;
	} else {
		control.style.backgroundColor='#fff'
	}
	});
	
return validaForm;
}

/// Previews ///

var passosizepreview=40;
var factorpreview = 1.5;
var imagem;

function zoompreview(origem)	{

	objectoimg = elem("aFoto");
	
	if (origwid==0) {
		origwid = objectoimg.width;
		orighei = objectoimg.height;
	}

	if (origem.value=="")
	{
		hide("aFoto");
		ficheiroorigem = 'img/blank.gif'
		}
	else
	{
		show("aFoto");
		ficheiroorigem = 'file:///' + origem.value;
	}
	
	imagem = new Image();
	imagem.src=ficheiroorigem;
	
	objectoimg.height=imagem.height;
	objectoimg.src=imagem.src;
	
}


var previeworig="";

function mostrapreview()    {

	objectoimg = elem("foto");
	var objectonome = elem("nome");
	
	/// Guardar o nome do ficheiro sem parametros
	if (previeworig=="") 
	{
	previeworig = objectoimg.src;
	}
	
	/// Verificar as selecções
	   var i 
	    for (i=0;i<document.inserefoto.LogoPos.length;i++){ 
	       if (document.inserefoto.LogoPos[i].checked) 
	          break; 
	    } 
	    pl = document.inserefoto.LogoPos[i].value;

	    for (i=0;i<document.inserefoto.LogoTr.length;i++){ 
	       if (document.inserefoto.LogoTr[i].checked) 
	          break; 
	    } 
	    tl = document.inserefoto.LogoTr[i].value;

	    for (i=0;i<document.inserefoto.TextoPos.length;i++){ 
	       if (document.inserefoto.TextoPos[i].checked) 
	          break; 
	    } 
	    pt = document.inserefoto.TextoPos[i].value;
	    
	    for (i=0;i<document.inserefoto.TextoTr.length;i++){ 
	       if (document.inserefoto.TextoTr[i].checked) 
	          break; 
	    } 
	    tt = document.inserefoto.TextoTr[i].value;
	    
	    for (i=0;i<document.inserefoto.TextoOr.length;i++){ 
	       if (document.inserefoto.TextoOr[i].checked) 
	          break; 
	    } 
	    ot = document.inserefoto.TextoOr[i].value;
	    
	    for (i=0;i<document.inserefoto.TextoTM.length;i++){ 
	    	       if (document.inserefoto.TextoTM[i].checked) 
	    	          break; 
	    	    } 
	    tmt = document.inserefoto.TextoTM[i].value;

	objectoimg.src = previeworig + "&m=0&pl="+pl+"&tl="+tl+"&pt="+pt+"&tt="+tt+"&ot="+ot+"&tmt="+tmt+"&n="+objectonome.value;
	
}


function CopyField(theField) {

var copytoclip=1
var tempval=eval("document."+theField);

tempval.focus();
tempval.select();

if (document.all&&copytoclip==1&&tempval.createTextRange){
	therange=tempval.createTextRange()
	if(therange.execCommand)
	therange.execCommand("Copy")
	else
	return;
	}
}


function buttonOnOff(btnObj, idDivControlo, novaClass,  prefixoControlo, valorControlo)
{
if ($(idDivControlo).innerHTML!=prefixoControlo+valorControlo) 
	btnObj.className=novaClass;
}

function buttonOff(idDivControlo, classOff)
{
if($(idDivControlo))
{
	var btnSel = $(idDivControlo).innerHTML;
	if (btnSel!='')
		$(btnSel).className=classOff;
	}
}

function buttonSelect(btnObject, idDivControlo, classOn, classOff, prefixo, valor)
{
var btnSel = $(idDivControlo).innerHTML;

if (btnSel!='')
	$(btnSel).className=classOff;
	
$(btnObject).className=classOn;

$(idDivControlo).update(prefixo+valor);
}


function buttonClear(idDivControlo, classOff, prefixo)
{
var btnSel = $(idDivControlo).innerHTML;

if (btnSel!='')
	$(btnSel).className=classOff;
	
$(idDivControlo).update("");
}


function filtraFotos(idDiv, prefixo, tipo)
{

$('1').className='btnGeral cxLeft cxRound';
$('2').className='btnGeral cxLeft cxRound';
$('3').className='btnGeral cxLeft cxRound';
$('4').className='btnGeral cxLeft cxRound';
$(idDiv).className='btnGeralOn cxLeft cxRound';

var count = 0;

switch(tipo)
{
	case '1':
		var valDisplayOn='block';
		var valDisplayOff='block';
		var valDisplayNone='block';
		break;
	case '2':
		var valDisplayOn='block';
		var valDisplayOff='none';
		var valDisplayNone='none';
		break;
	case '3':
		var valDisplayOn='none';
		var valDisplayOff='block';
		var valDisplayNone='block';
		break;
	case '4' :
		var valDisplayOn='none';
		var valDisplayOff='none';
		var valDisplayNone='block';
}
$$('div.lstFotoOn, div.lstFotoOff, div.lstFotoNone').each(function(index)
	{
	if (index.className=='lstFotoOn pointer')
		{
		if (valDisplayOn=='none') 
			Effect.Fade(index, { duration: 0.2 } );
		else
			{
			Effect.Appear(index, { duration: 0.2 } );
			count++
			}
		}
	//	index.style.display = valDisplayOn;
	else if (index.className=='lstFotoOff pointer')
		{
		if (valDisplayOff=='none') 
			Effect.Fade(index, { duration: 0.2 } );
		else
			{
			Effect.Appear(index, { duration: 0.2 } );
			count++
			}
		}
	else
		{
		if (valDisplayNone=='none') 
			Effect.Fade(index, { duration: 0.2 } );
		else
			{
			Effect.Appear(index, { duration: 0.2 } );
			count++
			}
		}
	//	index.style.display = valDisplayOff;
	});
	
	$('nFotosTema').update(count);
}


function toggleSeta(idSeta, pathImg)
{
var novaSrc;

if ($(idSeta).src.endsWith(pathImg+"img/icons/pq/expand.gif"))
		novaSrc="img/icons/pq/colapse.gif";
else
		novaSrc="img/icons/pq/expand.gif";

$(idSeta).src=pathImg + novaSrc

}



function getFoldDivClick(idDiv, path)
{
if (path=="") path="/";
Effect.toggle(idDiv, 'slide');
toggleSeta("img" +idDiv, path); 
return false;
}



function botoes(idBotao, idDiv, accao, prm, prefixo, estilo, nBotoes)
{
var i;
var valor;

for (i=0;i<=nBotoes-1;i++)
	{
	valor = (i==idBotao) ? "On" : "Off";
	$(prefixo+i).className=estilo+valor+" cxRound";
	}

prm = (prm=="") ? "opc="+idBotao : prm+"&opc="+idBotao;

if (accao!="" && idDiv!="") chamaAjax(idDiv, accao, prm);

}


function setSeleccao(objSelect, valor)
{
$$('select#'+objSelect).each(function(control){
	control.selectedIndex=valor; 
	});
}


function setTitulo()
{
if ($('divTituloPaginaRef')!=null && $('divTituloPagina')!=null)
	$('divTituloPagina').innerHTML = $('divTituloPaginaRef').innerHTML;

if ($('divTituloPagina')!=null && $('divTituloPagina'))
	if ($('divTituloPagina').innerHTML != "")
		Effect.Appear('divTituloPaginaWrap', { duration: 0.2 });

}


/// slider class ///

var iSlider=1;
var pe;

var browserV = Object.extend(Prototype.Browser, {
    ie6: (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ? (Number(RegExp.$1) == 6 ? true : false) : false,
    ie7: (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ? (Number(RegExp.$1) == 7 ? true : false) : false,
    ie8: (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ? (Number(RegExp.$1) == 8 ? true : false) : false,
    ie9: (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ? (Number(RegExp.$1) == 9 ? true : false) : false
});

if (browserV.ie7 || browserV.ie8)
	{
	var sliderFade=0;
	var sliderAppear=0;
	}
else
	{
	var sliderFade=0.1;
	var sliderAppear=1;
	}

var sliderDuration = 4;
	
function verificaSlider()
{
if ($('sliderIndex')!=null) {
	Effect.Fade('sliderWait', { duration: sliderFade });
	Effect.Appear('slider1', { duration: sliderAppear });
	Effect.Appear('sliderThumb1', { duration: sliderAppear });
	$('sliderRef1').toggleClassName('sliderRefOff');
	$('sliderRef1').toggleClassName('sliderRefOn');
	
	var i=0;
	for(i=0;i<6;i++) { if ($('sliderRef'+i)!=null) { Effect.Appear('sliderRef'+i, {duration: 0}); } }

	pe=new PeriodicalExecuter(iniciaSlider,sliderDuration);
	}
}


function startSlider()
{
Effect.Fade('sliderStart', { duration: sliderFade });
pe=new PeriodicalExecuter(iniciaSlider,sliderDuration);
}

function iniciaSlider()
{	
	if(iSlider!=0)
		{	
			var nextPhoto=iSlider+1;
			if($('slider'+nextPhoto)==null) nextPhoto=1;
			
			Effect.Fade('slider'+iSlider, { duration: sliderFade });
			Effect.Fade('sliderThumb'+iSlider, { duration: 0 });
			
			Effect.Appear('slider'+nextPhoto, { duration: sliderAppear });
			Effect.Appear('sliderThumb'+nextPhoto, { duration: sliderAppear });
			
			$('sliderRef'+iSlider).toggleClassName('sliderRefOn');
			$('sliderRef'+iSlider).toggleClassName('sliderRefOff');
			$('sliderRef'+nextPhoto).toggleClassName('sliderRefOff');
			$('sliderRef'+nextPhoto).toggleClassName('sliderRefOn');

		}
	iSlider++;
	if($('slider'+iSlider)==null) iSlider=1;
}


function stopSlider(idPhoto)
{
pe.stop();
Effect.Appear('sliderStart');

if (iSlider!=idPhoto) // Se a que clicou não é a que está a ser mostrada
	{
	Effect.Fade('slider'+iSlider);
	Effect.Fade('sliderThumb'+iSlider);
	Effect.Appear('slider'+idPhoto);
	Effect.Appear('sliderThumb'+idPhoto);
	$('sliderRef'+iSlider).toggleClassName('sliderRefOn');
	$('sliderRef'+iSlider).toggleClassName('sliderRefOff');
	$('sliderRef'+idPhoto).toggleClassName('sliderRefOff');
	$('sliderRef'+idPhoto).toggleClassName('sliderRefOn');
	
	iSlider=idPhoto
	}
}


function loadThumbs()
{
$('divContentWrap').insert( {top: '<div style="display: none;" id="fZoom" class="zoomWrap"></div>'} );

var arrThumbs=$$('.zoom');
arrThumbs.each(function(oThumb, index) {
	with (oThumb) {
		//aThumbs[index]=new thumb(id, index);
		aThumbs[index]=new thumb(oThumb.identify(), index);
		with(aThumbs[index]) { Event.observe(sObjecto, 'mouseover', bindIn); }
	}
  });
}


function loadButtons()
{
var arrBtns=$$('.btn');
arrBtns.each(function(oBtn, index) {
	with (oBtn) {
		aBtn[index]=new getButton(id, index);
		with(aBtn[index])
		{
			Event.observe(sObjecto, 'mouseover', bindIn);
			if(sEstado=='Off') { Event.observe(sObjecto, 'click', bindClick); }
			Event.observe(sObjecto, 'mouseout', bindOut);
		}
	}
  });
}


/// EXIF ///

function readExif(what)
{
var value = $('divExif').innerHTML;

switch(what)
{
	case 'Titulo':
		var posI = value.indexOf('Title') + 11;
		var posF = value.indexOf('<br>', posI);
		if(posI>10)	value = value.substring(posI,posF); else value="";
		break;
	case 'A':
		var posI = value.indexOf('Aperture') + 8;
		var posF = value.indexOf('<br>', posI);
		if(posI>8)	value = value.substring(posI,posF); else value="";	
	case 'V':
		var posI = value.indexOf('Exposure Time') + 8;
		var posF = value.indexOf('<br>', posI);
		if(posI>8)	value = value.substring(posI,posF); else value="";		
	case 'ISO':
}
return value;
}


/// Fórum ///

function InsereSmiley(osmiley,id) {
	$('postmsg'+id).Mensagem.focus();
	$('postmsg'+id).Mensagem.value = $('postmsg'+id).Mensagem.value + " " + osmiley + " ";
	$('postmsg'+id).Mensagem.focus();
return true;
}

function InsereLink(olink,adescricao,id) {
	$('postmsg'+id).Mensagem.focus();
	if(olink.value.indexOf('http://')==-1 | olink.value.indexOf('http://')>0 | olink.value.length<12 | olink.value.indexOf('http://http://')>=0)
	{
		alert("O endereço é inválido! Um link deve ter o formato http://servidor.nome.domínio - Ex: http://www.1000imagens.com");
	} 
	else 
	{
		var descricao = adescricao.value;

		if (descricao.length==0) { descricao=olink.value; }

		$('postmsg'+id).Mensagem.value = $('postmsg'+id).Mensagem.value + " [link url=" + olink.value + "]" + descricao + "[/link] ";
		olink.value="http://"
		adescricao.value=""
		$('postmsg'+id).Mensagem.focus();
	}
	return true;
}

function InsereTexto(oTexto, id) {
	$('postmsg'+id).Mensagem.value = $('postmsg'+id).Mensagem.value + oTexto;
	return true;
}

/// end Fórum ///


/// Menu Autor ///

function showMenuAutor(id, sPathImg) {
	idx=id+1;
	$('cxMenuSel'+id).show(); 
	$('menuAutor'+idx).src=sPathImg+'_on.gif'; 
}

function hideMenuAutor(id, sPathImg) {
		idx=id+1;
		$('cxMenuSel'+id).hide(); 
		$('menuAutor'+idx).src=sPathImg+'.gif'; 
}

///

/// btn class ///

var aBtn=new Array();
var btnSel;
var nBotoes=0;

function getButton(sIdObjecto, index)
{
this.sObjecto=sIdObjecto;
this.oObjecto=$(this.sObjecto);
this.sEstado=this.oObjecto.getAttribute("value");
if (this.sEstado=='On') btnSel=index;
nBotoes++;
this.bindIn=hBtnMouseIn.bindAsEventListener(this.sObjecto,index);
this.bindOut=hBtnMouseOut.bindAsEventListener(this.sObjecto,index);
this.bindClick=hBtnMouseClick.bindAsEventListener(this.sObjecto,index);
}
getButton.prototype.hBtnMouseIn;
getButton.prototype.hBtnMouseOut;
getButton.prototype.hBtnMouseClick;

function hBtnMouseIn(event)
{
var idx = $A(arguments);
idx.shift();

with(aBtn[idx])
	{
	if (sEstado=='Off')	{ oObjecto.toggleClassName('btnGeralOver'); }
	}
}


function hBtnMouseOut(event)
{
var idx = $A(arguments);
idx.shift();

with(aBtn[idx])
	{
	if(sEstado=='Off') { oObjecto.toggleClassName('btnGeralOver'); }
	}
}


function hBtnMouseClick(event)
{
var idx = $A(arguments);
idx.shift();

with(aBtn[btnSel])
	{
	aBtn[btnSel].sEstado="Off";
	Event.observe(sObjecto, 'click', bindClick);	
	}

with(aBtn[idx])
	{
	btnSel=idx;
	sEstado="On";
	Event.stopObserving(sObjecto, 'click', bindClick);
	
	switch($('btnID').value)
		{
		case 'btnFotos':
			botoes(idx, $('btnDiv').value, $('btnAct').value, $('btnPrm'+idx).value, $('btnID').value, $('btnCla').value, nBotoes);
			
			if(idx==2)
				{ Effect.Appear('divCmbDesafios'); }
			else
				{ Effect.Fade('divCmbDesafios', { duration: 0.5 } ); setSeleccao('IDDT', 0); }
			break;
		default:
			botoes(idx, $('btnDiv').value, $('btnAct').value, $('btnPrm'+idx).value, $('btnID').value, $('btnCla').value, nBotoes);	
		}
	}
}

/// end btn class //



/// translation ///
function checkTranslation()
{
	if($('cronicaFotoTxt')) {
		sText=$('cronicaFotoTxt').innerHTML
		google.language.detect(sText, function(result) { 
			thisLang=result.language;
			if (thisLang!='pt' && thisLang!='en') {	if (googleIsTranslatable(thisLang)) { $('cronicaFotoTrans').show(); } }
			});
	}
}


/// Window Load Actions //

window.onload=function()
{
setTitulo();
verificaModalFoto();
verificaSlider();
loadThumbs();
loadButtons();
setCarPos();
checkTranslation();
}


function writeDebug(what) { $("divDebug").innerHTML+='<p>'+what; }

function goToURL (sDestination) { window.location=sDestination; }

function verFotos (sQuery) {

with (window.location) {
	goToURL(pathname+"?"+sQuery);
	}
}




/// Carrossel ///
posCar=0;
var iTam = 125;
var posY = 35;
function moveC(sDir, iLim)
{
var iWidth=iLim*iTam
$('tira').style.width=iWidth + 'px';
iLim-=2;

if (sDir.id=="carRight")
	{ if (posCar<iLim) { posCar++; } else { posCar=0; }	}
else
	{ if (posCar>0)	{ posCar--; } else { posCar=iLim; }	}
	var iPos=-(posCar*iTam)
	new Effect.Move('tira', { x: iPos, y: posY, mode: 'absolute', duration: 0.4, queue: { position: 'end', scope: 'carScope' } }); 
}


function setCarPos()
{
if($('tira'))
{
	posCar=$('iPos').innerHTML;
	posCar-=2
	$('tira').style.left=(-1)*iTam*posCar+"px";
	Effect.Appear('tira', { duration: 0.2 } );
}
}

function editPortfolio(ida, idt) { chamaAjax('divFotosPortfolio', 'galeriaautoradd.asp', 'ida='+ida+'&idt='+idt+'&ac=e'); }

function reloadWindow() { window.location.reload(); }


/// DropDownMenu ///

var closeTime = 50;
var isClosing;

function initMenu(idMenu)
{
}

function openMenu(idMenu)
{
	if (idMenu)
	{
	cancelCloseMenu(idMenu);
	$(idMenu).show();
	}
}

function closeMenu(idMenu)
{
	isClosing = window.setTimeout("endCloseMenu('"+idMenu+"')", closeTime);
}

function cancelCloseMenu(idMenu)
{
	if (isClosing) {
		window.clearTimeout(isClosing);
		isClosing = null;
	}
}

function endCloseMenu(idMenu)
{
	$(idMenu).hide()
}
