tinyMCE.init({
	mode: 'textareas',
	editor_select: 'wysiwyg',
	
	plugins: 'inlinepopups,fullscreen,preview,advimage,advlink',
	
	theme: 'advanced',
	theme_advanced_toolbar_location : "top",
	theme_advanced_statusbar_location: "bottom",
	theme_advanced_resizing: true,
	theme_advanced_resize_horizontal: false,
	
	theme_advanced_buttons1: 'fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull',
	theme_advanced_buttons2: 'bullist,numlist,|,undo,redo,|,link,unlink,image,|,fullscreen,preview,resizing',
	theme_advanced_buttons3: '',

	/*
	theme_advanced_layout_manager: 'RowLayout',
	theme_advanced_containers: 'font,align,actions',
	theme_advanced_container_font: 'fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,bullist,numlist',
	theme_advanced_container_align: 'justifyleft,justifycenter,justifyright,justifyfull',
	theme_advanced_container_actions: 'cut,copy,paste,|,undo,redo,fullscreen,preview',
	*/
	
	/*
	theme_advanced_layout_manager: 'CustomLayout',
	theme_advanced_custom_layout: 'typeyToolbarLayout',
	*/
	
	gecko_spellcheck: true,
	
	button_tile_map: true,
	width: '90%',
	height: '400px',
	relative_urls: false,
	cleanup: false, // handled by HtmlPurifier
	entity_encoding: 'raw', // handled by HtmlPurifier
	verify_html : false, // handled by HtmlPurifier
	cleanup_serializer: 'xml', 

	
	file_browser_callback: 'typeyBrowser',
	init_instance_callback: 'setTabindex'
	
});


function typeyBrowser (field_name, url, type, win) {
	var browserUrl = '/admin/uploads/'+type+'?noLayout';
    tinyMCE.activeEditor.windowManager.open({
        file : browserUrl,
        title : 'File Browser',
        width : 500,  // Your dimensions may differ - toy around with them!
        height : 400,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
	return false;
}

function setTabindex (){
	$(function(){
		var wysiwyg = $('.wysiwyg');
		var tabindex = wysiwyg.attr('tabindex');
		var iframe = wysiwyg.next('span').find('iframe');
		iframe.attr('tabindex', tabindex);
	});
}