var scripts = document.getElementsByTagName("script");
var src = scripts[scripts.length - 1].src;
var scriptPath = src.substr(0,src.lastIndexOf('/')+1);

function filebrowser(field_name, url, type, win) {
	fileBrowserURL = scriptPath + '../../pdw_file_browser/index.php?filter=' + type;

	tinyMCE.activeEditor.windowManager.open({
		title: "PDW File Browser",
		url: fileBrowserURL,
		width: 950,
		height: 650,
		inline: 0,
		maximizable: 1,
		close_previous: 0
	},{
		window : win,
		input : field_name
	});
}

$(document).ready(function() {
	$('textarea.tinymce').tinymce({
		// Location of TinyMCE script
		script_url : scriptPath + '../tiny_mce/tiny_mce.js',

		// Use absolute urls
        remove_script_host : false,
        convert_urls : false,

		// General options
		theme : "advanced",
		plugins : "save,advimage,advlink",
		file_browser_callback: "filebrowser",

		// Theme options
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_buttons1 : "save,|,image,link,unlink,|,bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,cleanup,|,code",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : ""
	});
});

$(document).ready(function() {
	$('textarea.tinymce-advanced').tinymce({
		// Location of TinyMCE script
		script_url : scriptPath + '../tiny_mce/tiny_mce.js',

		// Use absolute urls
        remove_script_host : false,
        convert_urls : false,

		// General options
		theme : "advanced",
		plugins : "save,pagebreak,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,preview,media,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		file_browser_callback: "filebrowser",

		// Theme options
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_buttons1 : "save,|,image,link,unlink,|,bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,cleanup,|,code,|,template,|,media",
		theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,justifyfull,|,pagebreak,hr,|,sub,sup,|,formatselect,fontselect,fontsizeselect,|,search,replace",
		theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,|,forecolor,backcolor,|,visualaid,|,tablecontrols,|",
		theme_advanced_buttons4 : "",
		
		//theme_advanced_statusbar_location : "bottom",
		//theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		//content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js"

	});
});
