
$(function(){if($('#fileupload').length==0){return;}
$('.button.add').click(function(e){$('#upfile').click();e.preventDefault();});$('.button.cancel','#fileupload').click(function(e){$('.button.cancel, .button.start','#fileupload .fileupload-buttonbar').hide();});$('.button.clean','#fileupload').click(function(e){$('.fileupload-ctrl .files .template-download','#fileupload').slideUp(500,function(){$(this).remove();});$(this).hide();e.preventDefault();});$('#fileupload').fileupload({url:$('#fileupload').attr('action'),autoUpload:false,sequentialUploads:true,disabled:true}).bind('fileuploadadd',function(e,data){$('.button.cancel, .button.start','#fileupload .fileupload-buttonbar').show();}).bind('fileuploaddone',function(e,data){if(data.result.files[0].html!==undefined){$('.media-list p.clear').before(data.result.files[0].html);}
$('.button.clean','#fileupload').show();}).bind('fileuploadalways',function(e,data){if($('.fileupload-ctrl .files .template-upload','#fileupload').length==0){$('.button.start, .button.cancel','#fileupload .fileupload-buttonbar').hide();}});var $container=$('#add-file-f').parent().parent();var $msg,label;if($container.hasClass('enhanced_uploader')){$msg=dotclear.msg.enhanced_uploader_disable;label=dotclear.jsUpload.msg.choose_files;$('#fileupload').fileupload({disabled:false});}else{$msg=dotclear.msg.enhanced_uploader_activate;label=dotclear.jsUpload.msg.choose_file;}
$('<p class="clear"><a class="enhanced-toggle" href="#">'+$msg+'</a></p>').click(function(){if($container.hasClass('enhanced_uploader')){$msg=dotclear.msg.enhanced_uploader_activate;label=dotclear.jsUpload.msg.choose_file;$('#upfile').attr('multiple',false);$('.files .upload-file','#fileupload').remove();$('.button.cancel, .button.start','#fileupload .fileupload-buttonbar').hide();$('.button.start','#fileupload').show();$('#fileupload').fileupload({disabled:true});}else{$msg=dotclear.msg.enhanced_uploader_disable;label=dotclear.jsUpload.msg.choose_files;$('#upfile').attr('multiple',true);$('.button.start','#fileupload').hide();$('#fileupload').fileupload({disabled:false});}
$(this).find('a').text($msg);$('.add-label','#fileupload').text(label);$container.toggleClass('enhanced_uploader');}).appendTo($('#add-file-f'));fileRemoveAct();function fileRemoveAct(){$('a.media-remove').live('click',function(){var m_name=$(this).parents('ul').find('li:first>a').text();if(window.confirm(dotclear.msg.confirm_delete_media.replace('%s',m_name))){var f=$('#media-remove-hide').get(0);f.elements['remove'].value=this.href.replace(/^(.*)&remove=(.*?)(&|$)/,'$2');this.href='';f.submit();}
return false;});}});