$(document).ready(function(){
	var eOn = function(){
		$(this).css({backgroundColor:"#888", color:"#fff"});
	};
	var eOff = function(){
		$(this).css({backgroundColor:"#fff", color:"#000"});
	};
	
	var mostraInfo = function(element){
		var song_id = element.children('div').attr('id').split('_')[1];
		$.ajax({
			url: 'js/ajax/get_song.php',
			type: 'post',
			data: {'song_id': song_id},
			dataType: 'text',
			success: function(data){
				$(data).insertAfter(element);
				$('.mp3', element.next('.parole')).jmp3();
			}
		});
	};
	
	var actionLi = function(){
		var $this = $(this);
		$this
			.unbind()
			.css({backgroundColor:"#888", color:"#fff"})
			.click(function(){
				$this
					.unbind()
					.click(actionLi)
					.hover(eOn, eOff)
					.next('.parole').remove();
			});
		mostraInfo($this);
	};
	
	$("#descrizione p").each(function(){
		var thisPar = $(this);
		var testo = thisPar.html();
		var firstLetter = testo.substring(0,1);
		testo = testo.substring(1);
		firstLetter = '<span class="firstletter">' + firstLetter + '</span>';
		testo = firstLetter + testo;
		thisPar.html(testo);
	});
	$("#descrizione img:odd").css({
		float:"right",
		marginLeft:"5px",
		marginRight:0
	});
	$(".parole:last").css("border-bottom", "none");
	$("#canzoni div[class^=song]")
		.hover(eOn, eOff)
		.click(actionLi);
});