/* Hide All Lyrics */
function hideAll(){
	$('.lyrics').fadeOut("slow");
}
	var currentID;
	var currentAudio;
/* Show Lyric, Stop all other Songs, Set Current Audio, Play it and set playing state to true */
function playSong(songNumber){
	$('#audio'+songNumber).click($('#lyric'+songNumber).fadeIn('slow'));
	$('audio').audivid('stop');
	currentAudio='#audio'+songNumber;
	$(currentAudio).audivid('play');
}
$(function(){
	var isPlaying = $(currentAudio).audivid("isplaying");
	$("#about > ul:nth-child(2) li a").click(function(evt){
		if(currentID!=evt.target.id) {
			currentID=evt.target.id;
			$('#about > ul:nth-child(2) li a').removeClass('playing');
			$(this).addClass('playing');
			hideAll();
			if(currentID=='song01'){
				playSong('01'); isPlaying=true;
			} else if(currentID=='song02'){
				playSong('02'); isPlaying=true;
			} else if(currentID=='song03'){
				playSong('03'); isPlaying=true;
			} else if(currentID=='song04'){
				playSong('04'); isPlaying=true;
			} else if(currentID=='song05'){
				playSong('05'); isPlaying=true;
			} else if(currentID=='song06'){
				playSong('06'); isPlaying=true;
			} else if(currentID=='song07'){
				playSong('07'); isPlaying=true;
			} else if(currentID=='song08'){
				playSong('08'); isPlaying=true;
			} else if(currentID=='song09'){
				playSong('09'); isPlaying=true;
			} else if(currentID=='song10'){
				playSong('10'); isPlaying=true;
			} else if(currentID=='song11'){
				playSong('11'); isPlaying=true;
			} 
		} else {
			if(isPlaying){
				isPlaying=false;
				$(currentAudio).audivid('stop');
			} else {
				isPlaying=true;
				$(currentAudio).audivid('play');
			}
		}
	});

	//BIO COLORBOX
	$("a[rel='bioJo']").colorbox();
	$("a[rel='bioTuco']").colorbox();

	//FOTOS COLORBOX
	$("a[rel='fotos']").colorbox();

	//WHERE2BUY POPUP
	$('#about').each(function(){
		var distance = 10;
		var time = 250;
		var hideDelay = 1000;
		var hideDelayTimer = null;
		var beingShown = false;
		var visible = false;
		var trigger = $('.trigger', this);
		var popup = $('.popup',this);
		
		$([trigger.get(0), popup.get(0)]).mouseover(function(){
			var leftPosition = $(this).position().left - 10;
			//console.log('mouseover');
			if(hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || visible){
				return;
			} else {
				beingShown = true;
				popup.css({
					display: 'block',
					top: 205,
					left: leftPosition
				}).animate({
					opacity: 1,
					top: '-=' + distance + 'px'
				}, '', function(){
					beingShown = false;
					visible = true;
				});
			}
		}).mouseout(function(){
			if(hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function(){
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, '', function(){
					visible = false;
					$(this).css('display','none');
				});				
			}, hideDelay);
		});
	});	
});
