// JavaScript Document

function validarEmail(email) {
 
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,5})$/;
   var address = $(email).value;

   if(reg.test(address) == false) {
      return false;
   }
   return true;
}

function validarContacto(){
	
	if($('Telefone').value == $('Telefone').get('placeholder') && $('Email').value == $('Email').get('placeholder')){
		alert("Por favor preencha pelo menos uma forma de contacto (Telefone ou Email).");
		return false;	
	}
	if($('Email').value != $('Email').get('placeholder') && !validarEmail('Email')){
		alert("O endereço de email introduzido não é válido.");
		return false;	
	}
	
	return true;	
}

function alternar(botao, ar){
	
	var texto = $(botao).get('html');
	ar.each(function(item){
		if(texto == item[1]){
			$(item[0]).style.display = 'block';
		} else {
			$(item[0]).style.display = 'none';
			$(botao).set('html', item[1]);
		}
	});
	
}

function initToolTips(){
	
	document.getElements('[title]').addEvent('mouseover', function() {
	    ToolTip.instance(this, this.get('title')).show();
	});
	
}

function initPlaceHolders(){
	
	new NS.Placeholder({
		color: '#999'
	});
}

function initSlide(){
	
	if($$('.galeria')){
	
		var slide = new slideGallery($$(".galeria"), {
			steps: 1,
			current: 0,
			direction: "horizontal",
			paging: false,
			autoplay: true,
			duration: 4000,
			transition: Fx.Transitions.Quad.easeOut
			/*onStart: function() {
				this.gallery.getElement(".info").set("html", this.items[this.current].getElement("img").title);
			},
			onPlay: function() {
				this.fireEvent("start");
			}*/
		});
		
	}
		
}




window.addEvent('domready', function(){

	initToolTips();
	initPlaceHolders();
	initSlide();
	
});
