hitTest = function(o, l){
	function getOffset(o){
		for(var r = {l: o.offsetLeft, t: o.offsetTop, r: o.offsetWidth, b: o.offsetHeight};
			o = o.offsetParent; r.l += o.offsetLeft, r.t += o.offsetTop);
		return r.r += r.l, r.b += r.t, r;
	}
	for(var b, s, r = [], a = getOffset(o), j = isNaN(l.length), i = (j ? l = [l] : l).length; i;
		b = getOffset(l[--i]), (a.l == b.l || (a.l > b.l ? a.l <= b.r : b.l <= a.r))
		&& (a.t == b.t || (a.t > b.t ? a.t <= b.b : b.t <= a.b)) && (r[r.length] = l[i]));
	return j ? !!r.length : r;
};


var Message = Class.create();
Object.extend( Message.prototype, {
	_container: null,

	initialize: function()
	{
		$('header').insert( '<div id="growl"></div>' );
		this._container = $('growl');
		this._container.hide();
		this._container.onclick = function(){ this.hide() };
	},

	show: function( type, message )
	{
		this._container.hide();
		this._container.innerHTML = message;
		this._container.removeClassName( 'error' );
		this._container.addClassName( type );

		new Effect.Appear( this._container, { afterFinish: function() { new Effect.Fade( $('growl'), { delay: 5 } ); } } );
	},
	hide: function() {
		this._container.hide();
	}

});


var actions = {
	'sfGuardAuth_signin': function()
	{
		$('username').focus();
	},

	'sfGuardAuth_passwordReset': function()
	{
		rp = $('reset_password');
		if( rp ) {
			rp.focus();
		}
	},

	'universe_index': function()
	{
		i = 0;
  	$$('.mega').each( function(m)
		{
    	m.hide();
    	new Effect.Appear( m, { delay: i++/20, duration: 1.5 } );
		} );
	},
	
	'main_faq': function() {
		$$('.answer').each( function( e ) {
			e.hide();
		} );

		$$('.question').each( function( e ) {
			Event.observe( e, 'click', function() {
				$$('.answer').each( function( a ) {
					a.hide();
				} );
				
				new Effect.toggle( e.next() );
			});
		});
	}
};

var message = null;
document.observe( 'dom:loaded', function() {
	message = new Message();
	if( actions[document.body.id]) {
		actions[document.body.id]();
	}

	xindicator = $('indicator');
	if( xindicator ) {
		xindicator.hide();
	}

	search = $('searchstring');
	if( search ) {
		search.focus();
	}

	query = $('query');
	if( query ) {
		query.focus();
	}


});

try {
	document.execCommand("BackgroundImageCache",false,true);	
} catch( e ) {}

