
jQuery(document).ready(function(){

	jQuery('a.quote-button').click(function() {
		
		//var content = jQuery(this.parentNode.parentNode).next().clone();
		var content = jQuery(this).parents('li').find('div.post');
		content.find('div.attachments').empty();
		content = content.html();
		
		var author = jQuery(this).parents('div.threadauthor').find('p strong').text();
		var anchor = jQuery(this).parents('li').attr('id');
		
		if(!tinyMCE.activeEditor.isHidden()) {
			var currentContent = tinyMCE.activeEditor.getContent();
			tinyMCE.activeEditor.setContent(
				currentContent + 
				'<blockquote><cite><a class="attribution" href="#'+anchor+'">' +
				author + ' schrieb:</a></cite>' + content + '</blockquote><p></p>');
   
			tinyMCE.activeEditor.focus();
		} else {
			var textArea = jQuery('#post_content');
			textArea.val(
				textArea.val() + 
				'<blockquote><cite><a class="attribution" href="#'+anchor+'">' +
				author + ' schrieb:</a></cite>' + content + '</blockquote><p></p>');

			textArea.focus();
		}

	});
	
	
	jQuery('#postform').submit(function(){
	var currentContent = tinyMCE.activeEditor.getContent();
		if(currentContent == "") {
			alert('You cannot submit an empty post');
			return false;
		}
	});
	
});

function acd_setUpEditor() {

	jQuery(document).ready(function() {
   
        var btns = jQuery('#mce-tabs a.mceControl');
   
        btns.click(function() {
            var id = 'post_content';
   
            if(!jQuery(this).hasClass('active')) {
                if (!tinyMCE.get(id)) {
                    tinyMCE.execCommand('mceAddControl', false, id);
                } else {
                    tinyMCE.execCommand('mceRemoveControl', false, id);
                    acd_cleanupTextarea(id);
                }
   
                btns.removeClass('active');
                jQuery(this).addClass('active');
            }
   
            return false;
        });
   
        jQuery('#postformprev').click(function() {
            tinyMCE.triggerSave();
   
            jQuery.post(BB_CORE_PLUGIN_URL + "/acd-superplugin/preview.php", jQuery('#postform').serialize(),
              function(data){
                 jQuery('#previewdiv').html(data);
                 tb_show('Post Preview', '#TB_inline?height=450&width=700&inlineId=previewdiv');
            }, "html");
        });
   
	});

}

function acd_cleanupTextarea(id) {
	var textarea = jQuery('#'+id);
	  var contents = textarea.val();
	  contents = contents.replace(/(<|&lt;)!.+?(>|&gt;)/gim, '');
	  contents = contents.replace(/(<|&lt;)(style|xml|script)(>|&gt;)[\s\S]+?(<|&lt;)\/(style|xml|script)(>|&gt;)/gim, '');
	  textarea.val(contents);
}
	
	/* ACD Attachment JS */
	
function acd_deleteAttachment(elem, id, filename) {
 	var num = jQuery(elem).parent().attr('id').replace(/aaid-/, '');
	 jQuery.ajax({
	   type: "POST",
	   url: acdAttachmentsUrl + "/delete.php",
	   data: "attachment_id="+id+"&filename="+filename,
	   success: function(msg){
	   	//	alert('Attachment deleted.');
	   		var currentContent = tinyMCE.activeEditor.getContent();
				
				tinyMCE.activeEditor.setContent(
					currentContent.replace(eval("/\\[attachment="+num+"\\]/gi"),'')
				);
				
	   		jQuery(elem).parent().fadeOut();
	    	
	    	if(typeof swfu != "undefined") {
	    		swfu.setFileUploadLimit(swfu.getStats().successful_uploads + 1);
	    	}
	   }
	 });
	
}





function ajaxPostDelete(one,two,three) {

}
