
/**
 * turn a textarea into a basic wysiwyg editor
 * @param name the fieldname to convert
 * @return void
 */


function doeditor(name, type, baseurl)
{
	var ta = $('textarea[name="'+name+'"]')
	width = ta.width() -10 ; //allow for padding (unless disabled in theme)
	height = ta.height();
	var css = ['/resources/css/core.css'];


	// TODO Dan: clean
	type = 'new';

	switch(type)
	{
		case 'article':
			css.push('/resources/css/public.css');
			break; 
		case 'topblock':
			css.push('/resources/css/editor/topblock.css');
			break; 
			
		case 'email':
			css.push('/resources/css/editor/email.css'); 
			break; 
	}
	
	var editor = CKEDITOR.replace(name, {
			toolbar : type,
			bodyClass : 'pseudobody',
			contentsCss: css,
			uiColor : '#f2faff', 
			skin : 'kama', 
			width : width, 
			resize_minWidth : width, 
			resize_maxWidth : width, 
			height: height, 
			filebrowserBrowseUrl : '/resources/ckfinder/ckfinder.html?baseurl='+baseurl,
	        filebrowserImageBrowseUrl : '/resources/ckfinder/ckfinder.html?Type=Images&baseurl='+baseurl,
	        filebrowserFlashBrowseUrl : '/resources/ckfinder/ckfinder.html?Type=Flash&baseurl='+baseurl,
	        filebrowserUploadUrl : '/resources/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&baseurl='+baseurl,
	        filebrowserImageUploadUrl : '/resources/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&baseurl='+baseurl,
	        filebrowserFlashUploadUrl : '/resources/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash&baseurl='+baseurl
	    });
	    

editor.addStylesSet( 'my_styles',
[
    // Block Styles
    { name : 'Blue Title', element : 'h2', styles : { 'color' : 'Blue' } },
    { name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },

    // Inline Styles
    { name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
    { name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
]);	
		
editor.config.stylesCombo_stylesSet = 'my_styles';



	// Custom limit of styles
	editor.config.format_tags = 'h2;h3;h4;h5;h6';
	
	// TODO Dan: doesn't seem to work. Perhaps we could use allowable tags and then replace them later?  'p;h1;h2;h3;h4;h5;h6;pre;address;div'
	// editor.config.fontSize_sizes = 'normal/normal;small/small;big/big';
	




	

/*	    
editor.addStylesSet( 'my_styles',
[
    // Block Styles
    { name : 'Blue Title', element : 'h2', styles : { 'color' : 'Blue' } },
    { name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },

    // Inline Styles
    { name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
    { name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
]);

config.stylesCombo_stylesSet = 'my_styles';
*/


	    
	//CKFinder.SetupCKEditor( editor, { BasePath : '/resources/ckfinder/', BaseUrl : baseurl} );
}



function make_identifier(val)
{
	
	return val.replace(/\s/gi, '_').replace(/\W/gi, '').toLowerCase(); 
	
	
}
