var url = document.getElementsByTagName('script')[document.getElementsByTagName('script').length-1].getAttribute('src');
url = url.substring(0,url.length-3) + '/';
mceurl = url;

//addEvent(window, 'load', aaAddTiny);


var mce = {
//*
	Flash : {
		mode: "textareas",
		theme: "advanced",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,mylink,emotions,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,fullscreen,visualchars,nonbreaking,template",

		theme_advanced_buttons1 : "mybutton,save,newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,print,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,visualchars,nonbreaking,template,pagebreak",
		
		editor_selector : "mceFlash",
		editor_deselector : "mceNoEditor",

		content_css : mceurl+"content.css",
		theme_advanced_styles: "Yellow=yellow,Blue=blue,Gray=gray",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : false,
		convert_urls: false,
		//ask: true,
		cleanup_callback : "textAlignToAlign", // replaces style="text-align:center;" to align="center"
		paste_auto_cleanup_on_paste : true,
		//element_format : "xhtml",
		cleanup_on_startup : true,
		entity_encoding : "raw",
		encoding : "xml",
		/*valid_elements : ""
		+"a[href|target],"
		+"b/strong,"
		+"br,"
		+"font[color|face|size],"
		+"img[src|id|width|height|align|hspace|vspace],"
		+"i,"
		+"li,"
		+"p[align|class|style],"
		+"h1,"
		+"h2,"
		+"h3,"
		+"h4,"
		+"h5,"
		+"h6,"
		+"span[class],"
		+"textformat[blockindent|indent|leading|leftmargin|rightmargin|tabstops],"
		+"u",*/
		
		setup : function(ed) {
		  // Add a custom button
		  ed.addButton('mybutton', {
				title : 'My button',
				image : mceurl+'delimiter.gif',
				onclick : function() {
					//alert(tinyMCE.activeEditor)
					tinyMCE.activeEditor.selection.setContent('&para;');
				  // ed.selection.setContent('&para;');
				}
		  });
		}
		
	},
	
//*
	News : {
		mode: "textareas",
		theme: "advanced",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,mylink,emotions,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,fullscreen,visualchars,nonbreaking,template",

		theme_advanced_buttons1 : "mybutton,save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,print,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,visualchars,nonbreaking,template,pagebreak",

		editor_selector : "mceNews",
		editor_deselector : "mceNoEditor",

		content_css : mceurl+"content.css",
		theme_advanced_styles: "Yellow=yellow,Blue=blue,Gray=gray",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : false,
		convert_urls: false,
		//ask: true,
		cleanup_callback : "textAlignToAlign", // replaces style="text-align:center;" to align="center"
		paste_auto_cleanup_on_paste : true,
		//element_format : "xhtml",
		cleanup_on_startup : true,
		entity_encoding : "raw",
		encoding : "xml",
		///apply_source_formatting : true
		setup : function(ed) {
			// Add a custom button
			ed.addButton('mybutton', {
				title : 'My button',
				image : mceurl+'delimiter.gif',
				onclick : function() {
					//alert(tinyMCE.activeEditor)
					tinyMCE.activeEditor.selection.setContent('&para;');
				  // ed.selection.setContent('&para;');
				}
			});
		}
	},
	
//*
	Simple : {	
		mode: "textareas",
		theme: "advanced",
		
		plugins : "style,mylink,inlinepopups,paste,fullscreen,nonbreaking",

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist,|,styleselect,formatselect",
		theme_advanced_buttons2 : "pastetext,pasteword,|,mybutton,|,link,unlink,anchor,|,cleanup,|,justifyleft,justifycenter,justifyright,justifyfull,|,fullscreen,|,nonbreaking,code",
		theme_advanced_buttons3 : "",

		editor_selector : "mceSimple",
		editor_deselector : "mceNoEditor",

		content_css : mceurl+"content.css",
		theme_advanced_styles: "Yellow=yellow,Blue=blue,Gray=gray",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		convert_urls: false,
		//ask: true,
		cleanup_callback : "textAlignToAlign", // replaces style="text-align:center;" to align="center"
		paste_auto_cleanup_on_paste : true,
		//element_format : "xhtml",
		cleanup_on_startup : true,
		entity_encoding : "raw",
		encoding : "xml",
		///apply_source_formatting : true
		setup : function(ed) {
		  // Add a custom button
		  ed.addButton('mybutton', {
				title : 'My button',
				image : mceurl+'delimiter.gif',
				onclick : function() {
					//alert(tinyMCE.activeEditor)
					tinyMCE.activeEditor.selection.setContent('&para;');
				  // ed.selection.setContent('&para;');
				}
		  });
		}
	}
	
//*

}

function textAlignToAlign(type, value) {
	switch (type) {
		case "get_from_editor":
			// value = value.replace(/align=(['"])(\w+)(['"])/,"style=$1text-align: $2;$3");
			value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "insert_to_editor":
			//value = value.replace(/align=(['"])(\w+)(['"])/,"style=$1text-align: $2;$3");
			value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "submit_content":
			value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "get_from_editor_dom":
			//value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "insert_to_editor_dom":
			//value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "setup_content_dom":
			//value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
		case "submit_content_dom":
			//value = value.replace(/style=(['"])text-align:\s{0,}(\w+)\s{0,};(['"])/,"align=$1$2$3");
			break;
	}
	return value;
}

addEvent(window, 'load', function(){//alert('opa')
	var tinyTimeout = setTimeout(function(){
		for(i in mce){
			tinyMCE.init(eval('mce.'+i));
		}
		
		//tinyMCE.init(mce.Simple);
		//tinyMCE.init(mce.Flash);
		/*tinyMCE.init({
			mode : "textareas", 
			theme : "simple", 
			editor_selector : "mceNews" 
		});*/
		clearInterval(tinyTimeout);
	},300);
});



