function blindDownFadeTransition(blind, fade) {
	new Effect.Fade(fade, {duration: 0.4, fps: 50,
		afterFinish: function() {new Effect.BlindDown(blind, {duration: 0.6, fps: 50})}});
}

function appearBlindUpTransition(appear, blind) {
	new Effect.BlindUp(blind, {duration: 0.4, fps: 50,
		afterFinish: function() {new Effect.Appear(appear, {duration: 0.4, fps: 50})}});
}

function editInPlace(editID, url, options) {
	var failure = false;
	var editedValue = null;
	var editor = new Ajax.InPlaceEditor(editID, url, options);

	editor.options.onFailure = function() {
		displayFailure('unknown error occured');
		failure = true;
	}

	editor.options.onLoading = function() {
		editedValue = editor.editField.value;
	}

	editor.options.onCancel = function() {
		editedValue = null;
	}

	editor.options.onLoadedExternalText = function(response) {
		if (response) {
			response.responseText.evalScripts();
		}
	}

	editor.options.onComplete = function(response) {
		if (response) {
			if (isFailure(response)) {
				enterEditMode();
			}
			response.responseText.evalScripts();
		}
	}

	editor.onLeaveEditMode = function() {
		if (failure) {
			enterEditMode();
		}
	}

	function enterEditMode() {
		var loadTextURL = editor.options.loadTextURL;
		editor.options.loadTextURL = null;

		editor.enterEditMode('click');
		editor.editField.value = editedValue;

		failure = false;
		editor.options.loadTextURL = loadTextURL;
	}
}

function showPopup(message) {
	var m = new Control.Modal(false, {
		containerClassName: 'error roundCorners',
		overlayClassName: 'error',
		width: 300,
		contents: message,
		fade: true,
		overlayCloseOnClick: false,
		position: 'absolute'
	});
	m.open();
}

function displayFailure(reason) {
	showPopup(reason);
}

function isFailure(response) {
	return (response.responseText.indexOf("displayFailure(") != -1);
}

function displayInfo(infoDivID, message, timeout) {
	if (!timeout) {
		timeout = 2;
	}
	infoDivID = $(infoDivID)
	new Effect.Opacity(infoDivID,
	{ queue : {scope: 'infoscope', position: 'end'}, duration:0.5, from:0.0, to:1.0,
		beforeStart: function() {
			infoDivID.setOpacity(0.0);
			infoDivID.innerHTML = message;
		},
		afterFinish: function() {
			new Effect.Opacity(infoDivID,
			{ delay: timeout, duration:0.5, from:1.0, to:0.0,
				afterFinish: function() {
					infoDivID.innerHTML = '';
				}})
		}});
}

function equalColumns(columns) {
	var tallest = 0;
	var differentSizes = false;
	for (var i = 0; i < columns.length; i++) {
		if ($(columns[i])) {
			var size = parseInt($(columns[i]).getStyle('height'), 10);
			if (size > tallest) {
				tallest = size;
				differentSizes = true;
			}
		}
	}
	if (differentSizes) {
		for (var i = 0; i < columns.length; i++) {
			$(columns[i]).setStyle({
				'height' : tallest + 'px'
			});
		}
	}
}

function getEditor(editorID) {
	var editor = new FCKeditor(editorID);
	editor.BasePath = "../../js/fckeditor/";
	editor.Config["CustomConfigurationsPath"] = "../../customConfig.js";
	editor.ToolbarSet = "Comment";
	return editor;
}

function editPost(editorID, content) {
	var editor = getEditor(editorID + 'editor')
	if (content) {
		editor.Value = content;
		editor.oldContent = content;
	}
	$(editorID).update(editor.CreateHtml());
}

function renderEditor(editorID, titleID) {
	var editor = getEditor(editorID)
	if (titleID) {
		$(titleID).value = "";
	}
	$(editorID).update(editor.CreateHtml());
}