/**
 * Flex HTMLEditor Preview
 * @author OtakiToshiya
 * ckeditor前提です
 */
var FlexPreviewAdaptor = Class.create();
FlexPreviewAdaptor.prototype = {
	_container: null,
	
	/**
	 * Initialize
	 */
	initialize: function () {
	},
	
	create: function () {
		this._container = this._createContainer();
	},
	
	updateContent: function (html) {
		try {
			this._container.innerHTML = html;
			$A(this._container.getElementsByTagName('a')).each(function(link) {
				link.href = 'javascript:void(0)';
			});
		} catch (e) {
		
		}
	},
	
	/**
	 * 位置調整を行います。
	 * @param left
	 * @param top
	 */
	updateBounds: function(left, top, width, height) {
		if (this._container) {
			this._container.style.top = top + "px";
			this._container.style.left = left + "px";
			//this._container.style.width = width + "px";
			this._container.style.height = height + "px";
		}
	},
	
	/**
	 * 表示／非表示を切り替えます。
	 * @param value
	 */
	setVisible: function (value) {
		if (this._container) {
			if (value) {
				this._container.style.display = "block";
			} else {
				this._container.style.display = "none";
			}
		}
	},
	
	remove: function () {
		Element.remove(this._container);
	},
	
	/**
	 * 背景色を変更します
	 * @param color
	 */
	changeBgcolor: function(color) {
		if (color) {
			try {
				this._container.style.backgroundColor = "#" + color;
			} catch (e) {
				// for IE
				this._container.style.backgroundColor = '#' + color;
			}
		}
	},
	
	/**
	 * テキスト色を変更します
	 * @param color
	 */
	changeTextcolor: function(color) {
		document.body.text = '#' + color;
	},
	
	/**
	 * リンク色を変更します
	 * @param color
	 */
	changeLinkcolor: function(color) {
		if (color) {
			try {
				document.body.link = '#' + color;
			} catch (e) {
				// for IE
				document.body.link = '#' + color;
			}
		}
	},
	
	/**
	 * 選択色を変更します
	 * @param color
	 */
	changeAlinkcolor: function(color) {
		if (color) {
			try {
				document.body.aLink = '#' + color;
			} catch (e) {
				// for IE
				document.body.aLink = '#' + color;
			}
		}
	},
	
	/**
	 * 訪問済み色を変更します
	 * @param color
	 */
	changeVlinkcolor: function(color) {
		if (color) {
			try {
				document.body.vLink = '#' + color;
			} catch (e) {
				// for IE
				document.body.vLink = '#' + color;
			}
		}
	},
	
	/**
	 * プレビュー領域を作成します。
	 * @private
	 */
	_createContainer: function () {
		var bbody = document.getElementsByTagName("body").item(0);
		var element = document.createElement("div");
		element.setAttribute("id", "fxeditor_preview");
		element.style.position = "absolute";
		element.style.display = "block";
		element.style.overflow = "auto";
		element.style.width = "240px";
		element.style.zIndex = 101;
		bbody.appendChild(element);
		return element;
	}
};
