$(function() {
	/* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself
	 * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp
	 */

	CKEDITOR.timestamp = '';
	CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
	
	CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');	
	CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/');
	CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/');

	$('textarea#post_excerpt,textarea#post_content').ckeditor({
		extraPlugins: 'entrylink,dclink,media,justify',
		entities: false,
		allowedContent: true,
		toolbar: [
			{
				name: 'basicstyles',
				items: ['Bold','Italic','Underline','Strike','Blockquote',
					'NumberedList', 'BulletedList','RemoveFormat']
			},
			{
				name: 'paragraph',
				items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
			},
			{
				name: 'custom',
				items: ['EntryLink','dcLink','Media','-','Source', 'Maximize'] 
			}
		]
	});

	CKEDITOR.on('instanceReady', function(e) {
		if ($('label[for="post_excerpt"] a img').attr('src')==dotclear.img_minus_src) {
			$('#cke_post_excerpt').removeClass('hide');
		} else {
			$('#cke_post_excerpt').addClass('hide');
		}
		
		$('#excerpt-area label').click(function() {
			$('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
		});
	});
});
