/**
 * Função anti-spam para endereços de e-mail
 * 
 * @author Frederico Machado <fredi at caiac dot com dot br>
 * @copyright 2008 (c) Caiac Soluções Para Internet Ltda.
 * 
 * Exemplo:
 * 
 * HTML:
 * <span class="email">email _em_ servidor _ponto_ com _ponto_ br</span>
 * 
 * JAVASCRIPT:
 * $("span.email").antispam();
 * 
 * RESULTADO:
 * <span class="email"><a href="mailto:email@servidor.com.br">email@servidor.com.br</a></span>
 */
jQuery.fn.antispam = function() {
	return this.each(function(){
		var email = $(this).text().toLowerCase().replace(/\s_em_/g,'@').replace(/\s_ponto_/g,'.').replace(/\s+/g,'');
		var assunto = $(this).attr("rel");
		var link = "mailto:" + email;
		if (assunto) link += "?subject=" + assunto;
		$(this).html($("<a></a>").attr("href", link).text(email));
	});
};

function Flash(swf, w, h, id) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="'+id+'" width="'+w+'" height="'+h+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">');
	document.write('<param name="movie" value="'+swf+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="menu" value="false">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+swf+'" name="'+id+'" width="'+w+'" height="'+h+'" menu="false" wmode="transparent" quality="high" swliveconnect="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
	document.write('</object>');
}

function Imagem(img, tit) {
	var $img = $("<a />").attr({href: img, title: tit});
	$img.slimbox().click();
}

function abreJanela(url, id, w, h) {
	window.open(url, id, "width="+w+",height="+h+",status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0");
}

$(function() {
	function enquete() {
		$("div.bt_votar a").click(function() {
			$.ajax({
				type: "POST",
				url: "../_funcoes/index.php",
				data: "__funcao=enquete_votar&"+$("#frmEnquete").serialize(),
				cache: false,
				success: function(r) {
					$("div.enquete").html(r);
					var votos = $("div.opcoes_enquete").attr("rel");
					$("div.enquete div.barra").each(function() {
						porcent = Math.round((parseInt($(this).attr("rel")) / parseInt(votos)) * 100);
						$(this).css({width: "0%"}).animate({width: porcent+"%"}, 'slow');
					});
				}
			});
		});
	}

	function pecaMusica() {
		$("#frmMusica input[title]").each(function(i) {
			$(this).val($(this).attr("title"));
		}).focus(function() {
			if ($(this).val() == $(this).attr("title"))
				$(this).val('');
		}).blur(function() {
			if (!$(this).val().length)
				$(this).val($(this).attr("title"));
		});

		$("#frmMusica").validaForm({
			success: function(){
				$.ajax({
					type: "POST",
					url: "../_funcoes/index.php",
					data: "__funcao=pedido_enviar&"+$(this).serialize(),
					cache: false,
					success: function(r) {
						alert(r);
						if (r.indexOf("verifique") == -1)
							window.location.href = '../home/';
					}
				});
				return false;
			}
		});
		$("div.peca_musica div.bt_enviar_musica a").click(function() {
			$("#frmMusica").submit();
		});
	}

	if ($("#frmEnquete").length > 0)
		enquete();

	if ($("#frmMusica").length > 0)
		pecaMusica();

	$("div.banners_esq").banners(10000, "../_funcoes/index.php", "__funcao=banners");

	$("body").ajaxStart(function() {
		$(this).ajaxLoader({ texto: "Carregando..." });
	});
});

jQuery.extend(jQuery.easing,
{
	easeInQuart: function (x, t, b, c, d) {
		return c * (t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	}
});
