window.addEvent( 'load', function() {
	message();
});

function login() {
	var table = $('loginTable');
	if( table.getStyle('visibility') == 'hidden' ) {
		var btnCoords = $('login').getCoordinates();
		var tblCoords = $('loginTable').getCoordinates();
		table.position({
			x: btnCoords.right - tblCoords.width,
			y: btnCoords.top + btnCoords.height
		});
		table.setStyles({'visibility':'visible', 'z-index':'2'});
		table.getElement('input').focus();
	} else {
		table.setStyle('visibility', 'hidden');
	}
}

function logout() {
	$('logoutForm').submit();
}

function message(txt, fade) {
	if( $('message') == null )
		return;
	if( txt ) {
		if( txt.indexOf('|') == -1 )
			txt = 'black|'+txt;
		i = txt.indexOf('|');
		$('message').style.color = txt.substring(0,i);
		$('message').set('text', txt.substring(i+1) );
	}
	$('message').set({'opacity':1});
	if( !(fade === false) ) {
		var messageFade = new Fx.Morph('message',{duration:'long'});
		messageFade.start.delay(3000, messageFade, {'opacity': 0 });
	}
}


