function getBlock ( id, options ) {
	if ( arguments.callee.ids === undefined ) {
		arguments.callee.ids = [];
	}
	if ( arguments.callee.legends === undefined ) {
		arguments.callee.legends = {};
	}

	var block = document.getElementById(id);
	if ( block ) return block;

	options = options || {};
	block = document.createElement('fieldset');
	block.id = id;
	block.className = "block";
	if ( options['class'] ) block.className += " " + options['class'];

	var legendId = options.legend + ( options.legendModifier ? "_" + options.legendModifier : '' );
	block.legend = legendId;
	if ( options.legend && !arguments.callee.legends[legendId] ) {
		var legend = document.createElement('legend');
		legend.innerHTML = "<span><span>" + options.legend + "</span></span>";
		block.appendChild ( legend );
	}
	
	var children = options.children || [];
	
	for ( var i = 0, child; child = children[i]; i ++ ) {
		var child_children = child.children;
		delete child.children;
		child.parent = block;
		var childNode = StS.utils.DOM.create ( "div", child );
		for ( var c = 0; c < child_children.length; c ++ ) {
			block[child_children[c]] = StS.utils.DOM.create ( "div", {
				"class" : child_children[c],
				parent : childNode
			} );
		}
	}
	
	arguments.callee.ids.push(id);
	arguments.callee.ids.sort();
	
	var nextBlock = null;
	for ( var i = arguments.callee.ids.length - 1; i >= 0; i -- ) {
		if ( arguments.callee.ids[i] == id ) {
			if ( i + 1 < arguments.callee.ids.length ) {
				nextBlock = document.getElementById(arguments.callee.ids[i+1]);
			}
			break;
		}
	}
	
	var parentBlock = options.container
		|| document.getElementById(options.containerId)
		|| document.getElementById('container')
		|| document.body;
	if ( nextBlock == null ) {
		parentBlock.appendChild ( block );
	} else {
		parentBlock.insertBefore ( block, nextBlock );
	}

	if ( block.previousSibling ) {
		var p = block.previousSibling.legend;
		var c = block.legend; //options.legend;
		if ( p == c ) {
			StS.utils.DOM.addClass ( block.previousSibling, "parent" );
			StS.utils.DOM.addClass ( block, "child" );
		} else {
			StS.utils.DOM.removeClass ( block.previousSibling, "parent" );
		}
	}
	if ( block.nextSibling ) {
		var n = block.nextSibling.legend;
		var c = block.legend; //options.legend;
		if ( n != c ) {
			StS.utils.DOM.removeClass ( block.nextSibling, "child" );
		} else {
			StS.utils.DOM.addClass ( block, "parent" );
			var n_el = block.nextSibling.getElementsByTagName('legend')[0];
			var c_el = block.getElementsByTagName('legend')[0];
			if ( n_el && !c_el ) {
				block.insertBefore ( n_el, block.childNodes[0] );
			}
		}
	}
	arguments.callee.legends[legendId] = block;

	return block;
}
function getContainer ( sw, ts ) {
	var now = (ts || new Date()).copy();
	var seconds = parseInt ( now.getTime() / 1000 );
	var id = now.toString("%Y%m%dT%H%i") + (""+Math.floor(now.getSeconds()/20)*20).lpad(2,"0");
	
	var f = function ( ) {
		return document.getElementById('content').getElementsByTagName('div')[0];
	}
	
	var time = Date.now();
	
	if ( sw.author == "announce" ) {
		//var legend = now.toString("%g.%i%a");
		var block = getBlock( id + "_announce_" + time, {
			container : f(),
			'class' : 'announcement',
			legend : null,
			legendModifier : time,
			ignorePrevious : true,
			children : [
				{ children : [ 'announce' ] }
			]
		} )[sw.author];
	} else {
		now.setMinutes(Math.floor(now.getMinutes()/5)*5);
		var legend = now.toString("%g.%i%a");
		var block = getBlock( id, {
			container : f(),
			legend : legend,
			children : [
				{ children : [ 'terry', 'laurence' ], "class" : "story_elements" }
			]
		} )[sw.author];
		block.parentNode.className += " active";
	}
	return block;
}
