/**
 * MarkItUp! extended settings for Seditio
 */

var mySettings = {
	previewParserVar: 'text',
	previewPosition: 'before',
	previewAutoRefresh: false,
	onEnter: {keepDefault: false, replaceWith: '\n'},
	markupSet: [
		{name: L.bold, className:'mBold', key:'B', openWith:'[b]', closeWith:'[/b]'},
		{name: L.italic, className:'mItalic', key:'I', openWith:'[i]', closeWith:'[/i]'},
		{name: L.underline, className: 'mUnderline', key:'U', openWith:'[u]', closeWith:'[/u]'},
		{name: L.strike, className: 'mStrike', key:'S', openWith:'[s]', closeWith: '[/s]'},
		{separator:'---------------' },
		{name: L.align, className: 'mAlign',
		dropMenu: [
			{name: L.center, className: 'mCenter', openWith: '[center]', closeWith: '[/center]'},
			{name: L.justify, className: 'mJustify', openWith: '[justify]', closeWith: '[/justify]'},
			{name: L.left, className: 'mLeft', openWith: '[left]', closeWith: '[/left]'},
			{name: L.right, className: 'mRight', openWith: '[right]', closeWith: '[/right]'}
		]},
		{name: L.font, className: 'mFonts', key:'F',
		dropMenu :[
			{name: L.size, className: 'mFonts', openWith:'[size=[![' + L.size_pt +']!]]', closeWith:'[/size]' },
			{name: L.h1, className: 'mH1', openWith:'[h1]', closeWith:'[/h1]' },
			{name: L.h2, className: 'mH2', openWith:'[h2]', closeWith:'[/h2]' },
			{name: L.h3, className: 'mH3', openWith:'[h3]', closeWith:'[/h3]' },
			{name: L.h4, className: 'mH4', openWith:'[h4]', closeWith:'[/h4]' },
			{name: L.h5, className: 'mH5', openWith:'[h5]', closeWith:'[/h5]' },
			{name: L.h6, className: 'mH6', openWith:'[h6]', closeWith:'[/h6]' }
		]},
		{name: L.color, className:'palette', dropMenu: [
			{name: L.green,	openWith:'[color=#AED136]', closeWith: '[/color]', 	className:"col1-1" }
				
		
		]},
		{separator:'---------------' },
		{name: L.picture, className: 'mPicture', key:'P', replaceWith:'[img][![' + L.picture_url + ':!:http://]!][/img]'},
		{name: L.link, className: 'mLink', key:'L', openWith:'[url=[![URL:!:http://]!]]', closeWith:'[/url]', placeHolder: L.link_text},
		{name: L.email, className: 'mEmail', openWith:'[email=[![' + L.email_addr + ':!:john@doe.com]!]]', closeWith:'[/email]', placeHolder: L.email_text},
		{separator:'---------------' },
		{name: L.ul, className: 'mUl', openWith:'[list]\n', closeWith:'\n[/list]'},
		{name: L.ol, className: 'mOl', openWith:'[list=1]\n', closeWith:'\n[/list]'}, 
		{name: L.li, className: 'mLi', openWith:'[li]', key: 'M', closeWith: '[/li]'},
		{name: L.table, openWith:'[table]\n', closeWith:'\n[/table]', placeHolder:"[tr][(!(td|!|th)!)][/(!(td|!|th)!)][/tr]", className:'mtable' },
		{name: L.table_row, openWith:'[tr]', closeWith:'[/tr]', placeHolder:"[(!(td|!|th)!)][/(!(td|!|th)!)]", className:'mtable-row' },
		{name: L.table_cell, openWith:'[(!(td|!|th)!)]', closeWith:'[/(!(td|!|th)!)]', className:'mtable-col' },
		{separator:'---------------' },
		{name: L.quote, className:'mQuote', dropMenu: [
			{name: L.quote, className: 'mQuote', openWith:'[quote=[![' + L.quote_from + ']!]]', closeWith:'[/quote]'},
			{name: L.pre, className: 'mPre', openWith:'[pre]', closeWith:'[/pre]'},
			{name: L.spoiler, className: 'mSpoiler', openWith:'[spoiler=[![' + L.spoiler_text + ']!]]', closeWith:'[/spoiler]'}
		]},
		{name: L.code, className: 'mCode', openWith:'[code]', closeWith:'[/code]'},
		{name: L.hide, className: 'mHide', openWith:'[hide]', closeWith:'[/hide]'}, 
		{name: L.smilies, className: "mSmilies", replaceWith: function(markitup) { showSmilies(markitup) } },
		{separator:'---------------' },
		{name: L.clean, className:"mClean", replaceWith:function(markitup) { return markitup.selection.replace(/\[(.*?)\]/g, "") } },
		{name: L.preview, className:"mPreview", call:'preview' }
	]
}

// Mini editor
var mini = {
		previewParserVar: 'text',
		previewPosition: 'before',
		previewAutoRefresh: false,
		onEnter: {keepDefault: false, replaceWith: '\n'},
		markupSet: [
		{name: L.bold, className:'mBold', key:'B', openWith:'[b]', closeWith:'[/b]'},
		{name: L.italic, className:'mItalic', key:'I', openWith:'[i]', closeWith:'[/i]'},
		{name: L.link, className: 'mLink', key:'L', openWith:'[url=[![URL:!:http://]!]]', closeWith:'[/url]', placeHolder: L.link_text},
		{name: L.picture, className: 'mPicture', key:'P', replaceWith:'[img][![' + L.picture_url + ':!:http://]!][/img]'},
		{name: L.quote, className: 'mQuote', openWith:'[quote=[![' + L.quote_from + ']!]]', closeWith:'[/quote]'},
		{name: L.smilies, className: "mSmilies", replaceWith: function(markitup) { showSmilies(markitup) } },
		{name: L.preview, className:"mPreview", call:'preview' }
		]
}

// Renders and displays smilies dialog
function showSmilies(markitup) {
	var perRow = smileBox.perRow;
	if($('#smilies').length != 1) {
		var smileHtml = '<table class="cells" cellpadding="0" style="width:160px">';
		var code;
		for(var i = 0; i < smileSet.length; i++) {
			if(i % perRow == 0) {
				if(i != 0) smileHtml += '</tr>';
				smileHtml += '<tr>';
			}
			code = smileSet[i].code;
			code = code.replace(/</g, '&lt;');
			code = code.replace(/>/g, '&gt;');
			code = code.replace('/"/g', '&quot;');
			smileHtml += '<td><a href="#" name="'+code+'" title="'+smileSet[i].lang+'"><img src="./images/smilies/'+smileSet[i].file+'" alt="'+code+'" /></a></td>';
		}
		if(i % perRow > 0) {
			for(var j = i % perRow; j < perRow; j++) {
				smileHtml += '<td>&nbsp;</td>';
			}
		}
		smileHtml += '</tr></table>';
		$('body').append('<div id="smilies">' + smileHtml + '</div>');
		$('#smilies').dialog({
			title: L.smilies,
			height: smileBox.height,
			width: smileBox.width
		});
		$('#smilies a').click(function() {
			emoticon = $(this).attr("name");
			$.markItUp( { replaceWith: ' ' + emoticon + ' ' } );
			return false;
		});
	}
	$('#smilies').dialog('open');
}