<link rel="stylesheet" href="/js/jquery-ui/jquery-ui.css" />
<link rel="stylesheet" href="/css/wysiwyg/jquery.wysiwyg.css" type="text/css" />
<link rel="stylesheet" href="/css/files/wysiwyg.fileManager.css" type="text/css" />
<script type="text/javascript" src="/js/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/wysiwyg/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="/js/wysiwyg/controls/wysiwyg.image2.js"></script>
<script type="text/javascript" src="/js/wysiwyg/controls/wysiwyg.link2.js"></script>
<script type="text/javascript" src="/js/wysiwyg/controls/wysiwyg.table.js"></script>
<script type="text/javascript" src="/js/wysiwyg/plugins/wysiwyg.fileManager.js"></script>
<script type="text/javascript" src="/js/jquery.quickpager.js"></script>
<script type="text/javascript" src="/js/wysiwyg/plugins/wysiwyg.embed.js"></script>
<script type="text/javascript" src="/js/wysiwyg/plugins/wysiwyg.i18n.js"></script>
<?php if (file_exists ('js/wysiwyg/i18n/lang.' . $GLOBALS['i18n']->language . '.js')) { ?>
<script type="text/javascript" src="/js/wysiwyg/i18n/lang.{{i18n.language|none}}.js"></script>
<?php } ?>
<script type="text/javascript">
$(function () {
	$('#webpage-body').wysiwyg ({
		initialContent: '<p><br /></p>',
<?php if (file_exists ('js/wysiwyg/i18n/lang.' . $GLOBALS['i18n']->language . '.js')) { ?>
		plugins: {
			i18n: { lang: '{{i18n.language|none}}' }
		},
<?php } ?>
		controls: {
			strikeThrough	:{visible:false},
			justifyFull		:{visible:false},
			paragraph		:{visible:true},
			removeFormat	:{visible:true},
			html			:{visible:true},
			'fileManager': {
				visible: true,
				groupIndex: 12,
				tooltip: '{"File Manager"}',
				exec: function () {
					$.wysiwyg.fileManager.init (function (file) {
						if (file.match (/\.(jpg|png|gif)$/i)) {
							$('#webpage-body').wysiwyg ('insertImage', file);
						} else if (file.match (/\.swf$/i)) {
							$('#webpage-body').wysiwyg ('insertHtml', '<p><span class="embedded">{' + '! filemanager/swf?file=' + file + ' !}</span></p>');
							$('#webpage-body').wysiwyg ('insertHtml', '<p><br /></p>');
						} else if (file.match (/\.mp4$/i)) {
							$('#webpage-body').wysiwyg ('insertHtml', '<p><span class="embedded">{' + '! filemanager/video?file=' + file + ' !}</span></p>');
							$('#webpage-body').wysiwyg ('insertHtml', '<p><br /></p>');
						} else if (file.match (/\.mp3$/i)) {
							$('#webpage-body').wysiwyg ('insertHtml', '<p><span class="embedded">{' + '! filemanager/audio?file=' + file + ' !}</span></p>');
							$('#webpage-body').wysiwyg ('insertHtml', '<p><br /></p>');
						} else {
							$('#webpage-body').wysiwyg ('createLink', file);
						}
					});
				}
			},
			'dynamic': {
				visible: true,
				tooltip: '{"Dynamic Objects"}',
				tags: ['span'],
				exec: function () {
					$.wysiwyg.embed.init (this, function (existing, embed_code) {
						if (! existing) {
							$('#webpage-body').wysiwyg ('insertHtml', '<p><span class="embedded">{' + '! ' + embed_code + ' !}</span></p>');
							$('#webpage-body').wysiwyg ('insertHtml', '<p><br /></p>');
						} else {
							$(existing).replaceWith ('<span class="embedded">{' + '! ' + embed_code + ' !}</span>');
						}
					});
				}
			}
		},
		//dialog:'jqueryui',
		css: '/css/wysiwyg/default.css',
		'events': {
			click: function () {
				try {
					$('form').autosave ();
				} catch (e) {}
			}
		}
	});
	$.wysiwyg.fileManager.setAjaxHandler ('http://{{ $_SERVER.HTTP_HOST }}/filemanager/embed');
});
</script>
