$(document).ready(function() {
	
    $("#twitter").tweet({
		username: ["nathanmoomaw"],
        join_text: false,
        avatar_size: null,
        count: 1
    });
	
	$("#twitterNews").tweet({
		username: ["nathanmoomaw"],
		count: 10
	});
	
	$("#moomawTweet").tweet({
		username: ["nathanmoomaw"],
		count: 1
	});
	
	$('a[href^="http://"]')
	  .attr({
	    target: "_blank"
	});
	
	$(function(){
		var spt = $('span.mailme');
		var at = / at /;
		var dot = / dot /g;
		var addr = $(spt).text().replace(at,"@").replace(dot,".");
		$(spt).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
		.hover(function(){window.status="Send a letter";}, function(){window.status="";});
		$(spt).remove();
	});

	
});
	
function secretCode(release) {
	var secret = $('#secret_code').val();
	var releaseName = release;
	
	$.post("../../inc/secret_code.php",
	   { releaseName: releaseName, secret: secret },
	   	function(data){
			dls = parseInt(data);
			if (dls > 0) {
				$('#secret_download_downloads').val(dls);
				$('#secret_download').submit();
			} else if (dls == 0) {
				$('#secret_result').html("You have reached the maximum downloads for this code.  Please feel free to download the album again by donating below");
				$('#secret_result').show("slow");
			} else {
				$('#secret_result').html("That secret code didn't seem to work.  Please try again.  If you still have trouble <a href=\"../../about/\">contact us</a> or consider donating below.");
				$('#secret_result').show("slow");
			}
		}
	);
}

function roundNumber(num, dec) {
	var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
	return result;
}
