///*** LINKS EXTERNOS ***///
function createExternalLinks() {
	$("a[rel='externo']").attr("target","_blank");
	$("a[rel='externo']").attr("title",function () {
				this.title += " (abrirá em nova janela)";
			});
}

///*** GERAIS ***///
function decodeText(txt) {
	txt = txt.replace(/\+/g," ");
	return unescape(txt);
}

/*****CONTATO*****/
function addContatoEvent() {
	$("#frm_contato").submit(function () {
		submitContato();
		return false;
	});
	$("a.bt_mapa").lightBox({alt:[alt_mapa]});
}
function submitContato() {
	$("#frm_contato fieldset .msg_sucesso").remove();
	$("#frm_contato fieldset .msg_erro").remove();
	$("#frm_contato fieldset").append("<p class=\"c_loading\">enviando...</p>");
	$("#frm_contato input.bt_enviar").attr("disabled","disabled");
	$("#frm_contato input.bt_enviar").addClass("disabled");
	var params = $('#frm_contato').serialize();
	$.getJSON(URL_CONTATO,
				params,
				function(retorno) {
					if (retorno.err_nome)
						$("#err_nome").html(decodeText(retorno.err_nome));
					else
						$('#err_nome').html("");
					if (retorno.err_email)
						$('#err_email').html(decodeText(retorno.err_email));
					else
						$('#err_email').html("");
					if (retorno.err_fone)
						$('#err_fone').html(decodeText(retorno.err_fone));
					else
						$('#err_fone').html("");
					if (retorno.err_assunto)
						$('#err_assunto').html(decodeText(retorno.err_assunto));
					else
						$('#err_assunto').html("");
					if (retorno.err_msg)
						$('#err_msg').html(decodeText(retorno.err_msg));
					else
						$('#err_msg').html("");
						
					if (retorno.msg_erro)
						$("#frm_contato fieldset").append('<div class="msg_erro">' + decodeText(retorno.msg_erro) + '</div>');
					else
						$("#frm_contato fieldset .msg_erro").remove();
					if (retorno.msg_sucesso) {
						$("#nome").val("");
						$("#email").val("");
						$("#fone").val("");
						$("#assunto").val("");
						$("#mensagem").val("");
						$("#frm_contato fieldset").append('<div class="msg_sucesso">' + decodeText(retorno.msg_sucesso) + '</div>');
						$("#frm_contato fieldset .msg_sucesso").click(function() {
							$(this).remove();
						});
					}
					else {
						$("#frm_contato fieldset .msg_sucesso").remove();
					}
					$("#frm_contato fieldset p.c_loading").remove();
					$("#frm_contato input.bt_enviar").removeAttr("disabled");
					$("#frm_contato input.bt_enviar").removeClass("disabled");
					$("#frm_contato input.bt_enviar").focus();
				});
}

/*****FIM CONTATO*****/

function addProdutosEvent() {
	$("#entry ul>li").each(function() {
		$(this).find("a[class!='cat']").lightBox();
	});
}

function init() {
	createExternalLinks();
	if ($(".bt_mapa").length > 0)
		addContatoEvent();
}

$(document).ready(function() {
	init();
});
///*** FIM LINKS EXTERNOS ***///
