// Muda o destaque
var ATUAL_DEST=0;
function MD(cod){
	// esconde atual
	if(ATUAL_DEST) Element.hide("bx_"+ATUAL_DEST);
	//
	ATUAL_DEST = cod;
	// mostra nova
	Element.show("bx_"+cod);
}

// Ativa o muda do destaque
var MDD_V=0;
var MDD_T=false;
function MDD(){
	MDD_V++;
	if(MDD_V>MDD_TOTAL) MDD_V=1;
	MD(MDD_V);
	MDD_T=setTimeout('MDD()',10000);
}

// muda manualmente
function MDD_M(modo){
	clearTimeout(MDD_T);
	if(modo==1){
		MDD_V=MDD_V-2;
		if(MDD_V<0) MDD_V=MDD_TOTAL-1;
	}
	MDD();
}

function MDD_SETA(modo){
	if(modo){
		Element.hide("bant");
		Element.hide("bnext");
	}
	else{
		Element.show("bant");
		Element.show("bnext");
	}
}

/////////////////
// cria o menu funcional
function AtivaFormulario(){
	var form = document.contato;
	for(var i=0;i<form.elements.length;i++){
		if(form[i].type=="submit") continue;
		form[i].onblur = function(){if(!form[this.name].value) form[this.name].value = form[this.name].defaultValue;}
		form[i].onchange = function(){if(!form[this.name].value) form[this.name].value = form[this.name].defaultValue;}
		form[i].onclick = function(){if(form[this.name].value==form[this.name].defaultValue) form[this.name].value = "";}
		form[i].onselect = function(){if(form[this.name].value==form[this.name].defaultValue) form[this.name].value = "";}
	}
}


// Verifica o formulario
function VerForm(){
	var form = document.contato;
	var cp = "";
	var erro = "";
	var val = "";
	var campos = arguments;
	Element.hide('erros');
	for(var i=0;i<campos.length;i++){
		cp = campos[i];
		val = "";
		if(form[cp].type=="select-one"){
			val = form[cp].selectedIndex;
			if(val<1) val = 0;
		}
		else{
			//if(form[cp].value!=form[cp].defaultValue) val = form[cp].value;
			val = form[cp].value;
		}
		cp = cp.replace(/ /g,'_');
		if(!val || val==0){
			erro = 1;
			Element.addClassName('c'+cp,'erro');
		}
		else{
			Element.removeClassName('c'+cp,'erro');
		}
	}
	if(erro){
		Element.show('erros');
		return false;
	}
	return true;
}



/********************************************************
* Fotos
********************************************************/
var ABERTA = false;
function Fotos(codigo,album){
	var tam = MyLib.getInnerXY();
	if(!ABERTA) Element.setStyle('fotos',{ 'height':tam[1]+'px', 'width': tam[0]+'px'});
	var opt = {
		postBody:'ajax=1&t='+LANG+'/album/verfoto/'+album+'/'+codigo,
		method: 'post',
		onSuccess: function(t){
			var valor = MyLib.decode(t.responseText);
			var val = valor.split("\n");
			$('fotoarq').innerHTML="<img src='"+val[0]+"' name='foto' width='"+val[1]+"' height='"+val[2]+"' alt='Aguarde, Carregando' />";
			var larg = parseInt(val[1]);
			var aumenta = 80;
			if(val[7]) aumenta += 20;
			var alt = parseInt(val[2])+aumenta;
			CentralFotos(larg,alt);
			//
			//$('fotosautor').innerHTML=val[3];
			$('fotosdown').innerHTML=val[4];
			// botao fechar
			var fl = parseInt(larg)-20;
			Element.setStyle('fotosfechar',{'left': fl+'px'});
			//
			var topo = parseInt(val[2]/2)-20;
			var esq = parseInt(val[1])-40;
			$('fotosant').innerHTML=val[5];
			Element.setStyle('fotosant',{'top': topo+'px'});
			$('fotosprox').innerHTML=val[6];
			Element.setStyle('fotosprox',{'left': esq+'px', 'top': topo+'px'});
			//
			$('fotoslegenda').innerHTML=val[7];
			
			Element.show('fotos');
			ABERTA = true;
		}
	}
	new Ajax.Request(SUBPASTA+'/'+LANG+'/index.php', opt);
}

// Centraliza as fotos
var tempo = false;
function CentralFotos(largura,altura,modo){
	if(modo){
		clearTimeout(tempo);
		tempo=false;
	}
	else{
		var central = MyLib.CentralArea(largura,altura);
		var pos = MyLib.getScrollXY();
		var tam = Element.getDimensions('body');
		Element.setStyle('fotos',{ 'height':tam.height+'px', 'width': tam.width+'px', 'top': '0px'});
		//Element.setStyle('fotos',{ 'height':tam[1]+'px', 'width': tam[0]+'px', 'top': pos[1]+'px'});
		//var tam = MyLib.getInnerXY();
		Element.setStyle('fotoscont',{ 'top':pos[1]+'px', 'left':central[0]+'px', 'width': largura+'px', 'height': altura+'px'});
		//clearTimeout(tempo);
		//tempo=setTimeout('CentralFotos('+largura+','+altura+',0)',100);
	}
}

// fecha foto
function FechaFoto(){
	//CentralFotos(0,0,1);
	$('fotoarq').innerHTML="";
	ABERTA = false;
	Element.hide('fotos');
}



