$(document).ready
(
	function()
	{
		//Alinha weblinks a esquerda dos itens do menu que est‹o alinhados a direita
		var menu = $('#header ul.menu');
		var menuWidth = $(menu).width();
		var links = $('#header ul.weblinks');
		var headerWidth = $('#header').width();
		var linksPosX = headerWidth - menuWidth - 10;
		$(links).css('left', linksPosX + 'px');	
		
		//Comportamento do Login
		var inputUserName = $('#login div.login form input:first');
		inputUserName.val('Username');
		inputUserName.focus( function() { if ($(this).val() == 'Username') { $(this).val(''); } else { $(this).select(); } } );
		inputUserName.blur( function() { if ($(this).val() == '') { $(this).val('Username'); }; } );
		
		var inputPassword = $('#login div.login form input:last');
		inputPassword.css("display", "none");
		inputPassword.focus( function() { $(this).select(); } )
		inputPassword.blur( function() { if ($(this).val() == '') { $(this).css("display", "none"); inputPasswordText.css("display", "inline"); } } )
		
		var fieldset = $('#content #login div.login form fieldset');
		fieldset.append('<input type="text" value="Password" class="password text" />');
		
		var inputPasswordText = $('#login div.login form input.password.text');
		inputPasswordText.focus( function() { $(this).css("display", "none"); inputPassword.css("display", "inline"); inputPassword.select(); } );
		
		//Comportamento da caixa de busca por posts
		var inputSearch = $('#content #posts form#search-post input:first');
		inputSearch.focus( function() { if($(this).val() == 'Pesquisar em posts') { $(this).val(''); $(this).select(); } else { $(this).select(); } } );
		inputSearch.blur( function() { if($(this).val() == '') { $(this).val('Pesquisar em posts'); } } );
	}
);

function scrollTo( id )
{
	$(window).scrollTo(id, 1000);
}

function showLayer( element )
{
	var scrollTop = $(window).scrollTop();
	
	//Ajusta tamanho do fundo
	var background = $(element).children('span.background:first');
	$(background).css("width", $(window).width() + 'px').css("height", $(document.body).height() + scrollTop + 105 + 'px')
	
	//Mostra layer
	//$(element).css("display", "block");
	$(element).fadeIn(500);
	
	//Verifica se da para esconder a rolagem
	/*
	var bookHeight = $(element).children('div.book').height() + 100;
	var windowHeight = $(window).height();
	if (bookHeight <= windowHeight)
	{
		$(document.body).css("overflow-y", "hidden");
	}
	
	var bookWidth = $(element).children('div.book').width();
	var windowWidth = $(window).width();
	if (bookWidth <= windowWidth)
	{
		$(document.body).css("overflow-x", "hidden");
	}
	*/
	
	//Define posicao do livro
	var bookPosX = ($(window).width() / 2) - ($(element).children('div.book').width() / 2) - 25;
	bookPosX = bookPosX < 0 ? 0 : bookPosX;

	var bookPosY = ($(window).height() / 2) - ($(element).children('div.book').height() / 2) - 35;
	bookPosY = bookPosY < 45 ? 45 : bookPosY;
	bookPosY += scrollTop;
	
	$(element).children('div.book').css('left', bookPosX + 'px').css('top', bookPosY + 'px');
	
	//Fechar layer
	var closeButton = $(element).children('.book .content a.close:first');
	$(closeButton).click(function() 
	{
		hideLayer(element);
	});
	
	$(background).click(function() 
	{
		hideLayer(element);
	});
}

function hideLayer( element ) 
{
	//Mostra rolagens
	//$(document.body).css("overflow-y", "auto");
	
	//Esconde layer
	//$(element).css("display", "none");
	$(element).fadeOut(250);
}