var menues = new Array();
var files = new Array();
var effects = new Array();
var dimmer = overlay = show_form = null;

// if this gets set to true, a human clicked the "Comments" link to show the form
var comment_human = false;

function initialize()
{
	if (document.getElementById('comment')) setup_comments();
	document.getElementById('overlay').style.display = 'none';
}

function setup_comments()
{
	overlay = new Spry.Effect.Fade('overlay', {duration: 0, from:'0%', to:'100%', toggle: true, setup: function() {
		overlay.element.style.display = 'block';
	},
	finish: function() {
		if (overlay.element.style.opacity == 0) overlay.element.style.display = 'none';
	}});

	show_form = new Spry.Effect.Fade('comment', {duration: 750, from:'0%', to:'100%', toggle: true});
	dimmer = new Spry.Effect.Blind('dimmer', {duration: 750, from:'0%', to:'100%', toggle: true});
	
	overlay.addNextEffect(show_form);
	dimmer.addNextEffect(overlay);
	
	if (window.location.toString().indexOf("#comments") != -1)
	{
		toggle_file(document.getElementById('comments_wrapper'));
	}
}

function toggle_menu(submenu, link)
{
	// Define in theme js
}

function toggle_file(info_div)
{
	if (!files[info_div.parentNode.id]) {
		files[info_div.parentNode.id] = new Spry.Effect.Blind(info_div, {duration: 750, from:'0%', to:'100%', toggle: true,
		setup: function () {
		
		},
		finish: function () {
		
		}});
	}
	
	files[info_div.parentNode.id].start();
	return false;
}

function is_human()
{
	return comment_human;
}

function show_comment_form(comment_id)
{
	var comment_form = document.getElementById('comment');
	comment_form.action = "/post/comment/"+comment_id;
	comment_human = true;
	dimmer.start();
}

function runEffect(effectName, element, options, finish)
{
	if (!effects[element.id])
	{
		options['finish'] = finish;
		effects[element.id] = new Spry.Effect[effectName](element, options);
	}
	effects[element.id].start();
	return false;
}

Object.prototype.inspect = function ()
{
	var innerdata = "";
	if (this) for (var property in this) innerdata += property+": "+this[property]+"\n";
	return innerdata;
}