var win = null;
function NovaJanela(pagina,nome,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(pagina,'',settings);
}
$(document).ready(function() {
	show_form = function () {
		$("#contactArea").animate({height: "225px"}, 1700, 'easeOutBounce', function(){$("#contactArea form").fadeIn();});
    }
    hide_form = function () {
		$("#contactArea").animate({height: "0px"}, 1700, 'easeOutBounce', function(){$("#contactArea form").hide();});
	}
	$("a.contact").toggle(show_form, hide_form);

	$("a[rel='ouvir-a-105-fm']").click(function() {
		try{
			url = $(this).attr("href");
			NovaJanela(url,"",'325','80','no');
		}catch(e){
			alert("Erro tente mais tarde!");
		}
		return false;
	});
	$("a[rel='peca-sua-musica']").click(function() {
		try{
			url = $(this).attr("href");
			NovaJanela(url,"",'325','300','no');
		}catch(e){
			alert("Erro tente mais tarde!");
		}
		return false;
	});
	$("#form-contact").submit(function(){
		form = $(this);
		form.find("input[type=submit]").val('Enviando...');
		$.post("/2011/process/contact.php", form.serialize(), function(data) {
			if(parseInt(data) == 1){
				hide_form();
				form.find("input[type=submit]").val('Enviado!');
				setTimeout(function(){alert("Enviado com sucesso!");},1700);
			}else{
				alert("Algum erro ocorreu, você pode tentar novamente ou aguardar!");
			}
		});
		return false;
	});
	$.getJSON("http://twitter.com/statuses/user_timeline/click105.json?callback=?", function(data) {
		$("#last-tweet").html(data[0].text);
	});
});
