	var apSelect='';
	var imagen='';
	var objBtnSel='';
	var time;
	var time2;
	var mtitle;
	var encimade='';
	var idAp='';
	
function ordenCirc(){

	var elementos=$('#colegas .amigo').length;	
	var radio=155;
	var angulo=360/elementos;
	var iniciar=angulo*2;

		$('#colegas .amigo').each(function(i){
		
			var top=Math.sin(((i*angulo)-iniciar)*((2*Math.PI)/360))*radio;
			var left=Math.cos(((i*angulo)-iniciar)*((2*Math.PI)/360))*radio;
			left2=Math.round(left);
			top2=Math.round(top);
			
			$(this).css({'position':'absolute'});
			$(this).css({ 'top':top2, 'left':left2, cursor:'pointer'});
			//alert(i+this.id+top2+left2);
			
		});
		

	objBtnSel=$('.amigo:first'); 
	
	 
	$('#amigoSelect').hover(function(){
		
				clearInterval(time);
				
	},function(){
		
		clearInterval(time2);
		$("#infoAp").fadeOut();
		
		
		//$("#amigoSelect").fadeOut()
					
		time=setTimeout(function(){
				$("#amigoSelect").fadeIn();
				$("#amigoSelect").animate({ 'top': parseInt($(objBtnSel).css("top"))-3, 'left':parseInt($(objBtnSel).css("left"))+1}, 200,function(){
					$("#amigoSelect").css({'z-index':5});
					$("#infoAp").fadeIn();
					mtitle=$(objBtnSel).attr("title");
					$("#infoAp").html(mtitle);
					});
				
		}, 1000);
				
		
		});


	$('.amigo').hover(function(){

		clearInterval(time);

		
		$("#infoAp").fadeOut();
		mtitle=this.title;
		encimade=this;
		time2=setTimeout(function(){
				
					
			$("#amigoSelect").fadeIn();
			$("#amigoSelect").animate({ 'top': parseInt($(encimade).css("top"))-3, 'left':parseInt($(encimade).css("left"))+1}, 200,function(){
					$("#infoAp").html(mtitle);
					$("#infoAp").fadeIn();
					
					
				});
				
		}, 400);
		
		
	},function(){
		clearInterval(time2);
		$("#infoAp").fadeOut();
		
		
		//$("#amigoSelect").fadeOut()
					
		time=setTimeout(function(){
				$("#amigoSelect").fadeIn();
				$("#amigoSelect").animate({ 'top': parseInt($(objBtnSel).css("top"))-3, 'left':parseInt($(objBtnSel).css("left"))+1}, 500,function(){
					$("#infoAp").fadeIn();
					mtitle=$(objBtnSel).attr("title");
					$("#infoAp").html(mtitle);
					});
				
		}, 1500);
		

		});
	
		$("#amigoSelect").animate({ 'top': parseInt($('.amigo:first').css("top"))-3+'px', 'left':parseInt($('.amigo:first').css("left"))+1+'px'}, 500,function(){
			$("#amigoSelect").fadeIn();
					$("#infoAp").fadeIn();
					mtitle=$(objBtnSel).attr("title");
					$("#infoAp").html(mtitle);
		});

		
		
}





function showap(){
		$("#colegas").load("librerias/apConect.php", {action: 'showap'}, function(){
			//alert('vaca');
			$("#cuadroUpload").css({'display': 'none'});
			
				ordenCirc();
				$('.amigo:first').click();
				objBtnSel=$('.amigo:first');
				$.modal.close();
				makerizar();
			});	
	}

function delAp(){
		if(confirm(textJ165)){
		$("#preCarga").load("librerias/apConect.php", {action: 'eliminar',  id: apSelect}, function(){
			$("#cuadroUpload").css({'display': 'none'});
			
			alert(textJ163);

	
			$("#apNameVal").val('Nueva Apariencia');
			imagen='';
			apSelect='';	
			showap();
			});
			
		}	
	}
	

file='';
function selAp(idUser, idAp, file , nameF,obj){

	imagen=file;
	objBtnSel=$(obj);
	//alert(obj.src);
	//alert('sel'+apSelect+' '+idAp);
	
	$("#apNameVal").val(nameF);
	apSelect=idAp;
	var file=file.replace(rutaE,'').split('.')[0]+'.'+file.split('.')[1];
	$("#mascAp").fadeIn(500);
	$("#previewAp").attr({src:'files/'+idUser+'/aps/'+file});
	var file=file.replace(rutaE,'').split('.')[0]+'_mini.'+file.split('.')[1];
	//alert(file);
	//alert('files/'+idUser+'/aps/'+file+' '+nameF);
	//$("#previewAp").attr({src:'files/'+idUser+'/aps/'+nameF});	
	//$("#previewAp").attr{{src:file});
	$("#mascaraG").fadeIn(500);

	}


function newAp(){

	if($('.real').length>4){
		
		alert(textJ164);
		
		}else{
			$("#apNameVal").val('Nueva Apariencia');
			if($('.real').length==0){
				$("#previewAp").attr({src:'img/jepetoG.png'});
				$("#mascAp").css({'display': 'none'});
				}
			
			
			imagen='';
			apSelect='';	
			//	alert('new'+apSelect+' '+idAp+' '+$("#apNameVal").val() );
				
			$('#cargaEdit').load("librerias/imgResize.php", {idniv:apSelect, nombreap: $("#apNameVal").val(), fichero: imagen},function(){
				
				$('#cargaEdit').modal({
						overlay:60,
						overlayCss: ({backgroundColor:"#000", height:'500px',width:'500px'}),
						containerCss: ({backgroundColor:"rgb(255,255, 255)",'overflow': 'hidden'}),
						//Cuando se cierra el model, se repliega.
						onClose: function (dialog) {
		
							dialog.container.slideUp('slow', function () {
								
									$.modal.close(); 
								
							});
						}
					});			
				});


		}
	}



function saveAp(){

	
							$("#preCarga").load("librerias/apConect.php", {action: 'insertar',  id: apSelect, name: $("#apNameVal2").val()}, function(){	
							showap();
							
							});	
	}




	
