$(document).ready(function()
{
	// Close message animation (session variable 'message<kpmid>' is also set when clicking the close button)
	$('.message .close').click(function()
	{
		var self = this;
		$(this).closest('.message').animate(
		{
			height: '0px',
			marginBottom: '0px',
			paddingTop: '0px',
			opacity: 0.0
		},
		400, 'linear', function()
		{
			$(self).closest('.message').css('display', 'none');
		})
	});
	
	// Initialize the input replacer
	$('.replace, .kpgenerated :text, .kpgenerated textarea').inputReplacer();
	
	// Initialize Cufón
	if(Cufon)
	{
		Cufon.replace('.message h1, .follow-the-parties h2, .tweets h2, .event-calendar h2, #submit-q a strong, #lightbox-container-content .content h1, .global-search h2, .cat-overview h2, .contributors-small h2, #contributor h1, #add-comment .error, .popular-entries h2, .vote-wrap h2, #article-search-results h1, #article-search-results .error, #main-col .kpgenerated ul li.error', { fontFamily: 'DINPro-Bold' });
		Cufon.replace('.follow-the-parties h3, .global-search h3, .cat-overview h3, .contributors-small h3, .popular-entries h3, .vote-wrap h3', { fontFamily: 'DINPro-Regular' });
		Cufon.now();
	}
	
	// Search results: Give last article hit a class of 'last'
	if($('.article-hits').size() > 0)
		$('.article-hits .article:last').addClass('last');
		
	// If search error: Automagically bring focus to search field again
	if($('#article-search-results .error').size() > 0)
	{
		if($('.global-search').size() > 0)
		{
			$('.global-search :text').eq(0).focus();
		}
	}
});
