/**
 * $Id: editor_plugin_src.js 96 2006-10-10 21:29:54Z spocke $
 *
 * @author Moxiecode
 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
 */

/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('fullscreen');

var TinyMCE_FullScreenPlugin = {
	getInfo : function() {
		return {
			longname : 'Fullscreen',
			author : 'Moxiecode Systems',
			authorurl : 'http://tinymce.moxiecode.com',
			infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_fullscreen.html',
			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
		};
	},

	initInstance : function(inst) {
		if (!tinyMCE.settings['fullscreen_skip_plugin_css'])
			tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/fullscreen/css/content.css");
	},

	getControlHTML : function(cn) {
		switch (cn) {
			case "fullscreen":
				return tinyMCE.getButtonHTML(cn, 'lang_fullscreen_desc', '{$pluginurl}/images/fullscreen.gif', 'mceFullScreen');
		}

		return "";
	},

	execCommand : function(editor_id, element, command, user_interface, value) {
		// Handle commands
		switch (command) {
			case "mceFullScreen":
				this._toggleFullscreen(tinyMCE.getInstanceById(editor_id));
				return true;
		}

		// Pass to next handler in chain
		return false;
	},

	_toggleFullscreen : function(inst) {
		var ds = inst.getData('fullscreen'), editorContainer, tableElm, iframe, vp, cw, cd, re;

		cw = inst.getContainerWin();
		cd = cw.document;
		editorContainer = cd.getElementById(inst.editorId + '_parent');
		tableElm = editorContainer.firstChild;
		iframe = inst.iframeElement;
		re = cd.getElementById(inst.editorId + '_resize');

		if (!ds.enabled) {
			ds.oldOverflow = cd.body.style.overflow;
			cd.body.style.overflow = 'hidden';

			re.style.display = 'none';

			vp = tinyMCE.getViewPort(cw);

			tableElm.style.position = 'absolute';
			tableElm.style.zIndex = 1000;
			tableElm.style.left = tableElm.style.top = '0';

			tableElm.style.width = vp.width + 'px';
			tableElm.style.height = vp.height + 'px';

			ds.oldWidth = iframe.style.width;
			ds.oldHeight = iframe.style.height;

			var w = iframe.parentNode.clientWidth;
			var h = iframe.parentNode.clientHeight;

			iframe.style.width = w + "px";
			iframe.style.height = h + "px";

			tinyMCE.selectElements(cd, 'SELECT,INPUT,BUTTON,TEXTAREA', function (n) {
				tinyMCE.addCSSClass(n, 'mceItemFullScreenHidden');

				return false;
			});

			tinyMCE.switchClass(inst.editorId + '_fullscreen', 'mceButtonSelected');
			ds.enabled = true;
		} else {
			cd.body.style.overflow = ds.oldOverflow ? ds.oldOverflow : '';

			re.style.display = 'block';

			tableElm.style.position = 'static';
			tableElm.style.width = '';
			tableElm.style.height = '';

			iframe.style.width = ds.oldWidth ? ds.oldWidth : '';
			iframe.style.height = ds.oldHeight ? ds.oldHeight : '';

			tinyMCE.selectElements(cd, 'SELECT,INPUT,BUTTON,TEXTAREA', function (n) {
				tinyMCE.removeCSSClass(n, 'mceItemFullScreenHidden');

				return false;
			});

			tinyMCE.switchClass(inst.editorId + '_fullscreen', 'mceButtonNormal');
			ds.enabled = false;
		}
	}
};

tinyMCE.addPlugin("fullscreen", TinyMCE_FullScreenPlugin);
