function centeredMenu()
{
	var axisY = ($(window).height() / 2) - ($('#menu').height() / 2);
	$('#menu').css('top', axisY);
}

function centeredContent()
{
	var axisX = ($(window).width() / 2) - ($('#content').width() / 2);
	$('#content-bg, .jScrollPaneContainer').css('left', axisX);
}

function bottomFooter()
{
	var axisY = $(window).height() - $('#footer').height();
	$('#footer').css('top', axisY - 20);
	
	
	var axisYF = $(window).height() - $('#fakt').height();
	var axisXF = $(window).width() - $('#fakt').width();
	$('#fakt').css('top', axisYF - 20).css('left', axisXF - 20);
}

function x80729595274(to)
{
	document.write('<a'+' href='+'"mai'+'lto:'+to+'@'+'confood'+'.ru">'+to+'@con'+'foo'+'d.ru<'+'/a>');
}

function getUrl(v)
{
	var url = location.href.split('#')[1];
	return (url == undefined) ? false : url.split('/')[v];
}

function setTitle(t)
{
	document.title = t != undefined ? t : 'Convenience Food Technology';
}

function checkTitle()
{
	$('.list-menu > ul > li > a').each(function()
	{
		if($(this).attr('load') == getUrl(0)) { setTitle($(this).attr('runame')); }
	});
}

function goTo(u)
{
	window.location.href = u;
	return false;
}

function showSite()
{
	$('#loading').hide();
	$('#menu, #footer, #fakt').show();
	$(document).pngFix();
}

function selectPage()
{
	$('.page-' + getUrl(0)).css('color', '#e5240b');

	if(getUrl(0))
	{
		$('#menu').animate({'top': 20}, 1000, function()
		{
			loadContent(getUrl(0));
		});
	}
}

function loadContent(load)
{
	var axisX = ($(window).width() / 2) - ($('#content').width() / 2);
	var speed = 300;

	$('#loading').show();
	$('#content, #content-bg, .jScrollPaneContainer').show().animate({'left': -2000}, speed, function()
	{
		$.ajax({
			url: "index.php?i=" + load,
			cache: false,
			async: false,
			success: function(html)
			{
				$('#loading').hide();
				$('#content').html(html);
			}
		});

		$('#content, #content-bg').show();
		$('#content-bg').animate({'left': axisX}, speed);
		$('#content').animate({'left': 15}, speed);
		$('.jScrollPaneContainer').animate({'left': axisX}, speed);
		$('.scroll').jScrollPane({scrollbarWidth:11, scrollbarMargin:0, showArrows:true, maintainPosition:false});
		$(document).pngFix();
	});
	return false;
}

function setContentHeight()
{
	var hSep = 70;
	var cHeight = $(window).height() - 115 - $('#footer').height() - hSep;
	$('#content-bg, #content').css('height', cHeight);
	$('.jScrollPaneContainer').css('height', cHeight - 30);
	$('.scroll').jScrollPane({scrollbarWidth:11, scrollbarMargin:0, showArrows:true});
}

$(function()
{
	$.imgzoom();
	$('.scroll').jScrollPane({scrollbarWidth:11, scrollbarMargin:0, showArrows:true});

	$(window).bind('load', function()
	{
		showSite();
		$('.logo-tech').effect('pulsate', { times: 1000 }, 2000);
		if($.browser.msie || $.browser.opera) { $('.logo-tech').css('top', 43).css('left', -22); }
		if($.browser.msie) { $('#content-bg').css('width', $('#content').width()+60); }
		checkTitle();
		centeredMenu();
		bottomFooter();
		selectPage();
		setContentHeight();
	});

	$(window).bind('resize', function()
	{
		if($('#menu').css('top') != '20px')
		{
			centeredMenu();
		}
		centeredContent();
		bottomFooter();
		setContentHeight();
	});

	/* menu */
	$('.list-menu > ul > li > a').click(function()
	{
		goTo('#' + $(this).attr('load'));
		setTitle($(this).attr('runame'));

		if($('#menu').css('top') == '20px')
		{
			loadContent($(this).attr('load'));
		}
		else
		{
			$('#menu').animate({'top': 20}, 1000, function()
			{
				loadContent(getUrl(0));
			});
		}

		$('.list-menu > ul > li > a').each(function()
		{
			$(this).css('color', '#ffffff');
		});
		$(this).css('color', '#e5240b');

		return false;
	});
});
