function Centra(){
	/*
    var hf = $(document).height();
	var div = $('#search').height();
	
	if(hf>div){
		var top = (hf - div)/6;
	}else{
		var top = 50;
	}
	
	document.getElementById("search").style.marginTop=top+"px";
	*/
    
    document.getElementById("cerca").focus();
}

function Fondo(){
	var h = $('#bottom').height();
	document.getElementById("bottom").style.top=0+"px";
	document.getElementById("bottom").style.display="none";
	
	var hf = $('#principale').height();
	
	if(hf+h+50<=$(window).height()){
		document.getElementById("bottom").style.top=($(document).height()-h-20)+"px";
	}else{
		document.getElementById("bottom").style.top=(hf+100)+"px";
	}
	
	document.getElementById("bottom").style.display="block";
}

function Ricerca(){
	var campo = trim(document.form_dbmusica.cerca.value);
	if(campo.length==0){
		$("#dialog_e").dialog("open");
		return;
	}
}

function Cerca(){
	var campo = trim(document.form_dbmusica.cerca.value);
	var tipo = null;
    var radio = document.getElementsByName('radio');
    for(i=0; i<radio.length; i++){
        if(radio[i].checked==true){
            tipo = radio[i].value;
        }
    }

	if(campo.length<3){
		
		return false;
	}
	var parametri = $('#form_dbmusica').serialize();

	parametri = "cerca="+escape(campo)+"&radio="+escape(tipo)+"";
	//alert(parametri);
	
	$.ajax({
		type: "GET",
		cache: false,
		url: "core/dbmusica.php",
		data: ""+parametri+"",
		success: function(msg){
			document.getElementById('dbmusica').innerHTML=msg;
			//Fondo();
			document.form_dbmusica.diretto.value='0';
		}
	});
}

function Entra(str){
	document.form_dbmusica.diretto.value='1';
	document.form_dbmusica.cerca.value=str;
	
	var parametri = "artista="+escape(str);
	
	StartAttesa();
	
	$.ajax({
		type: "GET",
		cache: false,
		url: "core/artista.php",
		data: ""+parametri+"",
		success: function(msg){
				document.getElementById('dbmusica').innerHTML=""+msg+"";
				StopAttesa();
				
				$("#partecipa").button();
				$( "#dialog_p" ).dialog({
					autoOpen: false,				
					show: "blind",
					hide: "fade"
				});
				$( "#partecipa" ).click(function() {
					$( "#dialog_p" ).dialog( "open" );
					return false;
				});
				
				//Fondo();
				document.form_dbmusica.diretto.value='0';
		}
	});
}

function Artista(nome){
	var parametri = "artista="+escape(nome);
	
	StartAttesa();
	
	$.ajax({
		type: "GET",
		cache: false,
		url: "core/artista.php",
		data: ""+parametri+"",
		success: function(msg){
				document.getElementById('dbmusica').innerHTML=""+msg+"";
				StopAttesa();
				
				$("#partecipa").button();
				$( "#dialog_p" ).dialog({
					autoOpen: false,				
					show: "blind",
					hide: "fade"
				});
				$( "#partecipa" ).click(function() {
					$( "#dialog_p" ).dialog( "open" );
					return false;
				});
				
				//Fondo();
				document.form_dbmusica.diretto.value='0';
		}
	});
}

function Album(nome,titolo,anno){
	StartAttesa();
	jQuery.ajax({
		type: "GET",
		cache: false,
		url: "core/album.php",
		data: "artista="+escape(nome)+"&album="+escape(titolo)+"&anno="+escape(anno),
		success: function(msg){
			e = document.getElementById("dbmusica");
			e.innerHTML = msg;
			//Fondo();
			StopAttesa();
		}
	});	
}

function GoImmagini(indice){
	if($('#foto_'+indice)==null){
        $("#bottom").fadeIn();
        $("#dbmusica_status").fadeIn();
        $("#dbmusica_credits").fadeIn();
		return;
	}
	if(parseInt(indice)==15){
		$('#cerca').removeAttr("disabled");
		$("#progress").fadeOut(function(){
            $("#dbmusica_status").fadeIn();    
        });
		$('#cerca').focus();
        $("#bottom").fadeIn();
		$("#dbmusica_credits").fadeIn();
        return;
	}
	$('#foto_'+indice).fadeIn(400, function(){
		GoImmagini(parseInt(indice)+1);
		var p = (indice*7);
		if(indice==14){
			p=100;
		}
		
		$("#progress").progressbar({
				value: p
		});
	});
}

function StartAttesa(){
	$('#dbmusica').fadeOut();
	$("#progressbar").show();
}

function StopAttesa(){
	$( "#progressbar" ).hide();
	$('#dbmusica').fadeIn();
}

function trim(str){
    return str.replace(/^\s+|\s+$/g,"");
}
