jQuery(function(d){var e=null;var a=null;var c=1;var b=d("<button/>").addClass("btn btn-danger").attr("type","button").html('<i class="icon-trash"></i> '+Joomla.JText._("COM_KUNENA_GEN_REMOVE_AVATAR")).on("click",function(){var i=d(this),h=i.data();if(h.files!=undefined){var f=h.files.userid;var g=h.files.filename;}else{var f=h.userid;var g=h.filename;}e=e-1;d.ajax({url:Joomla.getOptions("com_kunena.avatar_remove_url")+"&userid="+f+"&avatar="+g,type:"POST",success:function(j){i.parent().remove();}});});d("#fileupload").fileupload({url:"index.php?option=com_kunena&view=user&task=upload&format=json",dataType:"json",autoUpload:true,disableImageResize:/Android(?!.*Chrome)|Opera/.test(window.navigator.userAgent),previewMaxWidth:100,previewMaxHeight:100,previewCrop:true}).bind("fileuploadsubmit",function(g,f){var h={};d.each(f.files,function(i,j){h={userid:d("#kunena_userid").val(),filename:j.name,size:j.size,mime:j.type};});f.formData=h;}).bind("fileuploaddrop",function(h,g){var f=Object.keys(g.files).length+e;e=Object.keys(g.files).length+e;}).bind("fileuploadchange",function(h,g){var f=Object.keys(g.files).length+e;e=Object.keys(g.files).length+e;}).on("fileuploadadd",function(g,f){d("#progress .bar").css("width","0%");d("#files").empty();f.context=d("<div/>").appendTo("#files");d.each(f.files,function(h,i){var j=d("<p/>").append(d("<span/>").text(i.name));if(!h){j.append("<br>");}j.appendTo(f.context);});}).on("fileuploadprocessalways",function(j,i){var f=i.index,g=i.files[f],h=d(i.context.children()[f]);if(g.preview){h.prepend("<br>").prepend(g.preview);}if(g.error){h.append("<br>").append(d('<span class="text-danger"/>').text(g.error));}if(f+1===i.files.length){i.context.find("button.btn-primary").text("COM_KUNENA_UPLOADED_LABEL_UPLOAD_BUTTON").prop("disabled",!!i.files.error);}}).on("fileuploaddone",function(i,h){var g=d("<a>").attr("target","_blank").prop("href",h.result.location);h.context.find("span").wrap(g);if(h.result.success==true){d("#form_submit_button").prop("disabled",false);d("#kattach-list").append('<input id="kattachs-'+h.result.data.id+'" type="hidden" name="attachments['+h.result.data.id+']" value="1" />');d("#kattach-list").append('<input id="kattach-'+h.result.data.id+'" placeholder="'+h.result.data.filename+'" type="hidden" name="attachment['+h.result.data.id+']" value="1" />');h.uploaded=true;if(h.context.find("button").hasClass("btn-danger")){h.context.find("button.btn-danger").remove();}h.context.append(b.clone(true).data(h));}else{if(h.result.message){d("#form_submit_button").prop("disabled",false);h.uploaded=false;h.context.append(b.clone(true).data(h));var f=null;d.each(h.result.data.exceptions,function(k,j){j=d('<div class="alert alert-error"/>').text(j.message);h.context.find("span").append("<br>").append(j);});}}}).on("fileuploadfail",function(g,f){d.each(f.files,function(i,j){var h=d('<span class="text-danger"/>').text("File upload failed.");d(f.context.children()[i]).append("<br>").append(h);});}).prop("disabled",!d.support.fileInput).parent().addClass(d.support.fileInput?undefined:"disabled");if(d("#kunena_userid").val()>0){d.ajax({type:"POST",url:Joomla.getOptions("com_kunena.avatar_preload_url"),async:false,dataType:"json",data:{userid:d("#kunena_userid").val()},success:function(h){if(d.isEmptyObject(h)==false){e=1;if(h.name!=undefined){var g=h.name;}else{var g="";}var f=d('<div><p><img src="'+h.path+'" width="100" height="100" /><br /><span>'+g+"</span><br /></p></div>");h.uploaded=true;h.result=false;h.userid=d("#kunena_userid").val();h.filename=h.name;f.append(b.clone(true).data(h));f.appendTo("#files");}}});}});