/**
 * @author sovnarkom, Enykey
 */

function toggle(item, behavior)
{
	if (behavior == 0) {
		$(item).find('ul:first').toggle(500)
		$(item).toggleClass('opened');
	}
	else {
		$(item).find('ul:first').toggle(0);
		$(item).toggleClass('opened');
	}
};

function subtoggle(item, behavior)
{
	var list = $(item).find('ul:first');
	if (list.length != 0) {
		if (behavior == 0) list.toggle(500)
		else list.toggle(0);
		$(item).toggleClass('opened');
		return false;
	}
	else {
		return true;
	}
};

$(document).ready(function()
{
	$('.menu h3 a.link').click(function()
	{
		toggle(this.parentNode.parentNode, 0);
		return false;
	});
	
	$('.menu>li li a').click(function()
	{
		return subtoggle(this.parentNode, 0);
	});
	
	$('.menu li[class*=opened]').each(function()
	{
		toggle(this, 1);
	})
	
	$('.benefit div').animate({opacity: 0}, function()
	{
		$(this).css({visibility: 'visible'})
	});

	$('.benefit').hover(function()
	{
		$(this).find('h2, h2 a, .var-links b, .var-links a').animate({color: '#fff8db'}, {queue: false, duration: 250});
		$(this).find('div').animate({opacity: 1}, {queue: false, duration: 250});
	},
	function()
	{
		$(this).find('h2, h2 a, .var-links b, .var-links a').animate({color: '#37546f'}, {queue: false, duration: 250});
		$(this).find('div').animate({opacity: 0}, {queue: false, duration: 250});
	});
	
	$('.menu>li').each(function()
		{
			var act = $(this).find('.active');
			if (act.length != 0) {
				
				act.parents('li').each(function(){
					toggle(this,1);
				})
			};
			
		})
});
