var Upload = Class.create();
Upload.extend({
	attach:[],
	start:function(){
		var tAction = $('form_publish').get('action');
		$('form_publish').set('action','/attach/upload/').set('target','frame_upload').submit();
		$('form_publish').set('action',tAction);
	},
	success:function(path,name,id,type){
		this.attach.push({id:id,path:path,name:name});
		var img50	= new Element('img',{src:'/'+path+'pre_50_'+name,width:50,height:50});
		var newEle 	= new Element('div',{id:'attach'+id,'class':'attachItem'});
		var a1 		= new Element('a',{href:'javascript:Upload.insert('+id+')',html:'插入'});
		var a2 		= new Element('a',{href:'javascript:Upload.del('+id+')',html:'删除'});
		var div 	= new Element('div');
		var input 	= new Element('input',{type:'hidden',name:'aid[]',value:id});
		(type == 1)?div.adopt([a1,a2]):div.adopt(a2);
		newEle.adopt([img50,div,input]);
		$('attachBox').adopt(newEle);
	},
	insert:function(id){
		var curAttach = null;
		for(i=0;i<this.attach.length;i++){
			if(this.attach[i].id == id)
				curAttach = this.attach[i];
		}
		var img500='<img src="/'+curAttach.path+'pre_500_'+curAttach.name+'" />';
		var oEditor = FCKeditorAPI.GetInstance('form_content') ;
		if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
		{
			oEditor.InsertHtml(img500) ;
		}
	},
	del:function(id){
		$('attach'+id).destroy();
		$.post('/attach/del/',{aid:id});
	}
});