var heightFix =
{
	footer: function()
	{
		// Calculate absolute position for footer if necessary
		var documentHeight = $(document).height();
		var windowHeight = $(window).height();
		// Default style for footer is N/A
		var footerStyle = {
			'position' : 'static',
			'top' : '',
			'left' : '',
			'right' : ''
		};
		if (windowHeight >= documentHeight)
		{
			// Document fit in window so footer is wrongly positioned
			var footerTop = windowHeight - 425;
			footerStyle = {
				'position' : 'absolute',
				'top' : footerTop + 'px',
				'left' : '0',
				'right' : '0'
			};
		}
		$('#footer').css(footerStyle);
	}
}

$(document).ready(function()
{
	// Fix footer position if necessary
	heightFix.footer();
	// Trigger this event also on window resize
	$(window).resize(heightFix.footer);

	// Open correct menu
	$('#fact_sidemenu_container ul li').each(function()
	{
		if ($(this).children('.current-page-item').length > 0 || $(this).hasClass('current-page-item'))
		{
			$(this).parent('ul').show();
			$(this).children('ul').show();
		}
	});

	// Convert tell_us_about_event
	if ($('a.contact_us').length > 0)
	{
		var domain = 'helsinkibusinesshub.fi';
		$('a.contact_us').each(function()
		{
			var receiver = $(this).attr('jsdata');
			$(this).attr('href', 'mailto:' + receiver + '@' + domain);
		});
	}
});
