function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function ismail( oMail ) {
	// Valida oMail como um e-mail, retorna true/false

	//MyRegExp = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(oMail));
}

function fValidaComentar(oForm) {
	var erro = false;
	var erroMsg = "";
	if(oForm.from_name.value.length < 4){
		if (!erro) { oForm.from_name.select(); oForm.from_name.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}
	if(!ismail(oForm.from_mail.value)) {
		if (!erro) { oForm.from_mail.select(); oForm.from_mail.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}
	if(oForm.captcha.value.length < 4){
		if (!erro) { oForm.captcha.select(); oForm.captcha.focus(); }
		erro = true; erroMsg += "Digite o texto da imagem embaralhada\n";
	}
	if(oForm.comentario.value.length < 5){
		if (!erro) { oForm.comentario.select(); oForm.comentario.focus(); }
		erro = true; erroMsg += "Digite seu comentário";
	}
	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		$('bt_enviar').style.display="none";
		Effect.Appear($("enviando"), {duration: 0.5});	
		return true;
	}
}
function fValidaEnviar(oForm) {
	var erro = false;
	var erroMsg = "";
	if(oForm.from_name.value.length < 4){
		if (!erro) { oForm.from_name.select(); oForm.from_name.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}
	if(!ismail(oForm.from_mail.value)) {
		if (!erro) { oForm.from_mail.select(); oForm.from_mail.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}	
	if(oForm.to_mail.value.length < 4){
		if (!erro) { oForm.to_mail.select(); oForm.to_mail.focus(); }
		erro = true; erroMsg += "Digite endereços de email separados por vírgula";
	}	
	
	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		$('bt_enviar_amigo').style.display="none";
		Effect.Appear($("enviando_amigo"), {duration: 0.5});		
		return true;
	}
}

function comentar() {
	atual_comentar = ( $('form_comentar').style.display != "none");
	goToAnchor("comentarenviar",100);
	if (!atual_comentar) {			
		//$("form_comentar").style.display = "block";
		$("form_envio").style.display = "none";		
		Effect.Appear($("form_comentar"), {duration: 0.7});
	}
}

function enviar_post() {
	atual_comentar = ( $('form_comentar').style.display != "none");
	goToAnchor("comentarenviar", 100);	
	if (atual_comentar) {			
		//$("form_envio").style.display = "block";
		$("form_comentar").style.display = "none";									
		Effect.Appear($("form_envio"), {duration: 0.7});
	}
}

function notset_defaultsto(theVar, theDefault) {
	if (typeof(theVar)=="undefined") {
		theVar = theDefault;
		return theDefault;
	} else {
		return theVar;
	}
}

function goToAnchor(aname, plus)
{		
	var anchors, i, ele;

	if (typeof(plus)=="undefined") {
		plus = 0;
	}
	

	if (!document.getElementById)
		return false;
		
	// get anchor
	anchors = document.getElementsByTagName("a");
	for (i=0;i<anchors.length;i++) {
		if (anchors[i].name == aname) {
			ele = anchors[i];
			i = anchors.length;
		}
	}
	
	// set scroll target
	if (window.scrollY)
		scrSt = window.scrollY;
	else if (document.documentElement.scrollTop)
		scrSt = document.documentElement.scrollTop;
	else
		scrSt = document.body.scrollTop;

	if (!ele) return false;
	
	scrDist = ele.offsetTop - scrSt;
	scrDur = 500;
	scrTime = 0;
	scrInt = 10;
	
	// set interval
	
	window.scrollTo( 0, scrSt+scrDist+plus );
	return true;
}

function getLoading(altura) {
	altura = notset_defaultsto(altura, "");
	if (altura != "") {
		altura -= 16; //load2.gif
		half = parseInt(altura / 2)-1;
		style =  "padding-top:" + half + "px; padding-bottom: "+ (half-1)  + "px;"
	} else {
		style = "padding-top:6px;";
	}
	//return "<p>carregando...</p>";
	return '<p style="padding:4px;'+style+'"><img src="'+asset_path+'imgs/load2.gif" alt="carregando"/></p>';
}

function ajax_loaded() {
	Effect.Fade('loading',  {duration: 0.5});
}

function ajax_mes(url) {
	h = $("calendario").offsetHeight;
	$('calendario').innerHTML = getLoading(h);
	myAjax = new Ajax.Updater('calendario', url,
		 {method: 'get',
		 	 parameters: '', //'rand=' + parseInt(Math.random()*99999999), //cache buster
		 	 onSuccess: function() {
		 	 	Effect.Appear('calendario', {duration: 0.8});		 	
		 	 }
		 });
}


function fAtribuiEvento(obj, evType, fn){
	if (obj.addEventListener) obj.addEventListener(evType, fn, true);
	if (obj.attachEvent) obj.attachEvent("on"+evType, fn);
}


function flash_link(str_uri) {
	uris = [
		"home", "celebrate", "formatura", "servicos", "fotos", "blog", "contato", "arearestrita",
		/*  */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
	];
	links = [
		"info", "info/celebrate", "info/formatura", "info/servicos", "fotos", "blog", "info/contato", "arearestrita",
		/*  */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
	];
	pos = uris.indexOf(str_uri);
	if (pos >= 0) {
		ok = false;
		if (links.length > pos) {
			url_tail = links[pos];	
			if (url_tail != "") {
				ok = true;
			}
			if (url_tail == "-") { url_tail = ""; }
		}		
		if (ok) {			
			document.location = base_url + url_tail;
		} else { 
			alert("link para '"+ str_uri + "' ainda não foi definido");
		}
	} else {
		alert("link para '"+ str_uri + "' não foi encontrado");
	}
	
}

js_erro = "";

fAtribuiEvento(window,"load",fIni);

function fIni() {
	if (typeof AlbumDeUsuario != "undefined") {
		AlbumDeUsuario.initialize();
	}
	return;
	MM_preloadImages(asset_path+'imgs/load2.gif');
	if (js_erro != "") {
		eval(js_erro);
	}
	//nifty_corners();
	//sifr_setup();
}
