
/**
 * Método que atualiza a informação da imagem
 */
 function mergeInfo(obj){
 	if( $(obj).val() != "" ){
	 	$.ajax({
	 		type: "POST",
	 		url: "mergeDescPhoto.php",
	 		data: "id="+obj.name+"&desc="+$(obj).val(),
	 		success: function(){
	 		}
	 	});
 	}
 }
 
 $(function(){
 	$("#formulario ul li p").click(function(){
 		if( imgsel == null ){ imgsel = $(this); }
 		imgsel.css("opacity", "0.4", "filter", "alpha(opacity=40)");
 		$(this).css("opacity", "1", "filter", "alpha(opacity=100)");
 		imgsel = $(this);
 		var id = $(this).find(":hidden").val();
 		setThumbGalery(id, galery);
 	});
 });
 
 
 /**
 *	Seta a capa da galeria
 */
 function setThumbGalery(id, galery){
 	$.ajax({
 		type: "POST",
 		url: "setThumbGalery.php",
 		data: "id="+id+"&galery="+galery,
 		success: function(){
 		}
 	}); 	
 }
 
 /**
 * Método que remove uma foto do album
 */
 function removePhoto(obj){
 	var conf = confirm("Deseja realmente remover?");
 	if(conf){
	 	$.ajax({
	 		type: "POST",
	 		url: "removePhoto.php",
	 		data: "ID="+obj.name,
	 		success: function(){
	 			$(obj).parent("li").remove();
	 		}
	 	});
 	}
 }
 
 /**
 * Método para remover uma galeria
 */
 function removeGalery(obj, id){
 	var conf = confirm("Deseja realmente remover?");
 	if(conf){
	 	 $.ajax({
	 		type: "GET",
	 		url: "removeGalery.php?ID="+id,
	 		success: function(){
	 			$(obj).parent("li").remove();
	 		}
	 	});
 	}
 }
 
 
 /**
 * Método que seta um input text para o usuário 
 * digitar uma descrição para a foto
 */
 var selection = null;
 function getInput(obj, idPhoto){
 	if(selection == null){
	 	var html = "<input id="+idPhoto+" name="+idPhoto+" onblur='check(this);' />";
	 	$(obj).html(html);
	 	$(obj).find("input").focus();
	 	selection = $(obj);
 	}
 }
 
 /**
  * Checa se a descrição não está em branco para poder salvar
  */
 function check(obj){
 	if($(obj).val() != ""){
 		mergeInfo(obj);
 		selection = null;
 	}else{
 		$(obj).parent("div").html("<em>Clique para adicionar uma descri&ccedil;&auml;o</em>");
 		selection = null;
 	}
 }
 
 
