/*
============================
WePad - 2015
Weslei R. C. Ramos
============================
*/
var adicionaSN = false;
var Identificou = false;
var IDEN = "Identificar botões";
var MAAU = "Manual";
var automatico = true;
var largura = "190px";

var musica = "FireHive";
var sequencias = {"FireHive":"A1-A2-A3-A4-B1-B2-B3-A3-B4-A3-A2-A3-A4-B1<Br>B2-B3-A3-B4-C1-A1-C2-C3-C4-D1-D2-D1-D2-D3<br>D4-C2...",
				  "Bangarang":"B4-C1-B4-C2-B4-C1-B4-C2-C3-(A1-A2-A3-A4-B1<br>B2-A1-A2-A3-A4-B3-B1)2x-B4-C1-B4-C2-B4-C1<br>B4-C2-C3-C4-D1-D2-D3-C4-D1-D4..",
				  "Kyoto":"A2-C1-D1-C1-D1-C1-(manual)D1-(automático)D2<br>C2-C3-C4-D3-D4-B4-B3-B2-C2-C3-C4-D3-D4-B4<br>B3-A2...",
				  "Cinema":"D4-A1-A2-A3-A4-A1-A2-B2-D1-B3-A1-A2-A3-A4<br>D2-D3-C1-C2-C3-C4-A1-A2-A3-A4-A1-A2-B2-B1<br>B3-A1-A2-B4"};
var identificacao = {1:"A1", 2:"A2", 3:"A3", 4:"A4", 5:"B1", 6:"B2", 7:"B3", 8:"B4", 9:"C1", 10:"C2", 11:"C3", 12:"C4", 13:"D1", 14:"D2", 15:"D3", 16:"D4"};

function mudasom(x){
	if(x==1){
		musica = "FireHive";
	}else if(x == 2){
		musica = "Bangarang";
	}else if(x == 3){
		musica = "Kyoto";
	}else{
		musica = "Cinema";
	}
	for(var x = 1; x <= 16; x++){
		var id = "som"+x.toString();
		var som = document.getElementById(id);
		som.src = "./sons/"+musica+"/"+x+".mp3";
	}
}
function opcoes(){
	var botoes = '<table id="tabela"><td><button id="identifica" class="opcoes">'+IDEN+'</button></td><td><button id="tocaAutomatico" class="opcoes">'+MAAU+'</button></td><tr><td colspan="2"><button id="sequencia" class="opcoes" style="width:'+largura+';position: static;">Sequência da música</button></td></tr></table>';
	if(adicionaSN){
		adicionaSN = false;
		$(".ajconf").animate({height:"-=50"}, 500);
		$("#identifica, #tocaAutomatico, #sequencia, #mostrasequencia, #tabela").remove();
	}else{
		adicionaSN = true;
		$(".ajconf").animate({height:"+=50"}, 500);
		$(".ajconf").append(botoes);
	}
}
$(document).ready(function(){
	$(".WePad").dblclick(function(){
		opcoes();
	});
	$(".buttons").click(function(){
		if(automatico){
			var som = document.getElementById("som"+$(this).attr("id").replace("btn", ""));
			som.currentTime = 0;
			som.play();
		}
	});
	$(".buttons").bind("touchstart", function(){
		if(!(automatico)){
			var som = document.getElementById("som"+$(this).attr("id").replace("btn", ""));
			som.currentTime = 0;
			som.play();
		}
	}).bind("touchend", function(){
		if(!(automatico)){
			var som = document.getElementById("som"+$(this).attr("id").replace("btn", ""));
			som.currentTime = 0;
			som.pause();
		}
	});
	$(".slots").click(function(){
		var numero = parseInt($(this).attr("id"));
		mudasom(numero);
	});
});
function larguraBotao(){
	if(IDEN=="Identificar botões"){
		if(MAAU=="Automático"){
			largura = "213px";
		}else{
			largura = "190px";
		}
	}else if(IDEN=="Remover identificação"){
		if(MAAU=="Automático"){
			largura = "248px";
		}else{
			largura = "225px";
		}
	}
}
$(document).on("click", "#identifica", function(){
	if(Identificou){
		Identificou = false;
		for(var x = 1; x <= 16; x++){
		   $("#btn"+x+"").text("  ");
		}
 		IDEN = "Identificar botões";
	}else{
		Identificou = true;
    	for(var x = 1; x <= 16; x++){
		   $("#btn"+x+"").text(identificacao[""+x+""]);
		}
		IDEN = "Remover identificação";
	}
	larguraBotao();
	$("#identifica").text(IDEN);
	$("#sequencia").css("width", largura);
});
$(document).on("click", "#tocaAutomatico", function(){
	if(automatico){
		automatico = false;
		MAAU = "Automático";
	}else{
		automatico = true;
		MAAU = "Manual";
	}
	larguraBotao();
	$("#tocaAutomatico").text(MAAU);
	$("#sequencia").css("width", largura);
});

$(document).on("click", "#sequencia", function(){
	$("#identifica, #tocaAutomatico, #sequencia, #tabela").remove();
	window.setTimeout("BurriceMinhaHUE()", 900);
	$(".ajconf").animate({height:"-=50"}, 500);
	$(".ajconf").animate({height:"+=50"}, 500);
});
function BurriceMinhaHUE(){
	var seq = sequencias[""+musica+""];
	$(".ajconf").append("<font size='2'><p id='mostrasequencia'>"+seq+"</p></font>");
}
$(document).on("click", "#sobreee", function(){
	var autor = "WePad - 2015\nCriado por Weslei R. C. Ramos\n\n";
	var musicas = "Musicas:\nFire Hive - Knife Party\nBangarang - Skrillex\nKyoto - Skrillex ft. Sirah\nCinema - Skrillex";
	alert(autor+musicas);
});