var oldID="";
var oldTitle="";

jQuery(document).ready(function(){
	jQuery("#attachment_delete_flv").click(function(){
	  attachmentDeleteFLV();
	});
	jQuery("#undo_delete_flv").click(function(){
    undoDeleteAttachment();
	});
	jQuery("#add_attachment").click(function(){
	   jQuery("#undo_delete_flv").css("display","none");
	});

});

function undoDeleteAttachment(){
  jQuery("#_hid_attachment_flv_id").val(oldID);
  jQuery("#txt_attachment_flv").html(oldTitle);
  jQuery("#embedFLV").toggle("slow");
  jQuery("#screenshot_flv").toggle();
  jQuery("#undo_delete_flv").css("display","none");
  jQuery("#attachment_delete_flv").click(function(){
    attachmentDeleteFLV();
  });
}

function attachmentDeleteFLV(){
	  oldID=jQuery("#_hid_attachment_flv_id").val();
	  oldTitle=jQuery("#txt_attachment_flv").html();
	  jQuery("#embedFLV").toggle("slow");
	  jQuery("#txt_attachment_flv").html("<strong>No flv video attached.</strong>");
	  jQuery("#_hid_attachment_flv_id").val("");
	  jQuery("#screenshot_flv").toggle();
	  jQuery("#undo_delete_flv").css("display","block");
}

function deleteAttachment(id){
  if (confirm("Segur?")){
    jQuery("#box_attachment_"+id).remove();
    if (jQuery("span.attachFile_presence").length==1){
      window.parent.jQuery("#files_attachments p:first").css("display","block");
    }
  }
}

function attachToPost(id,title,type,imgHTML){
  if (type==1){
    window.parent.jQuery("#_hid_attachment_flv_id").val(id);
    window.parent.jQuery("#txt_attachment_flv").html("<strong>" + title + "</strong>");
  }else{
    if (window.parent.jQuery("#box_attachment_"+id).length==0){//No existe
	    htmlNewFile=window.parent.jQuery("div.attach_file_template").html().replace(/\[ID\]/g,id).replace(/\[TITLE_ATTACHMENT\]/g,title).replace(/\[IMAGE\]/g,imgHTML);
	    window.parent.jQuery("#files_attachments p:first").css("display","none");
	    window.parent.jQuery("#files_attachments div.inside").append(htmlNewFile);
	  }else{
	    alert("Ja te aquest recurs associat");
	  }
  }
}


