$(document).ready(function() {

	/* tooltip */

	$('a').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: ' - ',
		fade: 0
	});
	
	/* input */

	$('input:not(:submit)').focus(function() {
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input:not(:submit)').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('textarea').focus(function() {
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('textarea').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});

	$(".comment").hover(function(){
		$(this).find(".bt-comment").fadeTo("fast", 1.0);
	},function(){
		$(this).find(".bt-comment").fadeTo("fast", 0.0);
	});

	$.getJSON("http://twitter.com/statuses/user_timeline/thiagoreisbh.json?callback=?", function(data) {
		 $("#twitter").html(data[0].text);
	});	
	
	$("#bt-fechar-comentario").click(function(){
		$('#comentario').slideUp(600,'easeInOutCubic',function(){
			$('.overlay').fadeOut(600);
		});
	});

	$('.shareaudio').click(function(){
		window.open($(this).attr('href'),'share','width=650,height=400,left='+(screen.availWidth/2-225)+',top='+(screen.availHeight/2-100)+'');
		return false;
	});


});

function comment(id) {
	var hr = $('#'+id).attr('href');
	$('#comentario #comentario-comments').hide();
	$('#comentario #comentario-loading').show();
	$('.overlay').fadeIn(400,function(){
		$('#comentario').slideDown(600,'easeInOutCubic',function(){
			$("html,body").animate({scrollTop: $("#wr").offset().top}, 600, 'easeInOutCubic');
			$.get(hr, function(data){
				$('#comentario #comentario-comments').html(data);
				$('#comentario #comentario-comments').show();
				$('#comentario #comentario-loading').hide();
			});
		});
	});
	return false;
}
function comentar(id) {
	var hr = $('#'+id).attr('action');
	$('#comentario #comentario-comments').hide();
	$('#comentario #comentario-loading').show();
	$.post(hr, $('#'+id+' input, #'+id+' textarea').serialize(), function(data){
		$('#comentario #comentario-comments').html(data);
		$('#comentario #comentario-comments').show();
		$('#comentario #comentario-loading').hide();
	});
	return false;
}

