var excludeButtons = [
	'ed_li'
	,'ed_ins'
	,'ed_del'
];

var existingButtons = [];

var MarkdownButtons = {
	ed_strong: {
		display: 'strong',
		tagStart:	'**',
		tagEnd:	'**',
	},
	ed_em: {
		display: 'em',
		tagStart:	'_',
		tagEnd:	'_',
	},
	// ed_link is special case
	// ed_img is special case
	ed_block: {
		display: 'blockquote',
		tagStart:	'\n>\t',
		tagEnd:	'\n\n',  
	},
	ed_h2: {
		display: 'h2',
		tagStart:	'## ',
		tagEnd:	' ##\n\n',
	},
	ed_h3: {
		display: 'h3',
		tagStart:	'### ',
		tagEnd:	' ###\n\n',
	}, 
	ed_h4: {
		display: 'h4',
		tagStart:	'#### ',
		tagEnd:	' ####\n\n',
	}, 
	ed_code: {
		display: 'code',
		tagStart:	'`',
		tagEnd:	'`',
	}, 
	ed_ol: {
		display: '1. List', 
		tagStart:	'\n1.\t',
		tagEnd:	'',
		open: -1,
	},
	ed_ul: {
		display: '• List', 
		tagStart:	'\n-\t',
		tagEnd:	'',
		open: -1,
	},
}

//	Extend existing buttons
jQuery.each(edButtons, function(i, button) {
	jQuery.extend( button, MarkdownButtons[button.id] );
	existingButtons.push(button.id);
});

//	Remove some
edButtons = jQuery.grep(edButtons, function(button) {
	return -1 == jQuery.inArray( button.id, excludeButtons );
});

//	Add some
jQuery.each( MarkdownButtons, function(id, button) {
		(-1 == jQuery.inArray(id, existingButtons)) && edButtons.push(new edButton(
			id, button.display, button.tagStart, button.tagEnd, button.access, button.open
		));
	}
);

//	Redefine handlers

function edInsertLink(myField) {
var myValue = prompt('Enter the Link text', '');
	if (myValue) {
		myValue = '[' 
				+ myValue 
				+ '](' + prompt('Enter a URL', 'http://') 
				+ ')';
		edInsertContent(myField, myValue);
	}
}

function edInsertImage(myField) {
	var myValue = prompt('Image description:', '');
	if (myValue) {
		myValue = '![' 
				+ myValue 
				+ '](' + prompt('Image URL:', 'http://') 
				+ ')';
		edInsertContent(myField, myValue);
	}
}