var autohide_timeout=10000;

var grpCount;

var anim = function() {
	var j = Math.floor(Math.random(grpCount)*grpCount);
	$('.hotoffer').eq(j).map(function() {
		if($(this).children().size() > 1) {
			$(this).children(".main").children("a").animate({'color': "#ffffff"}, 200, 'linear', function() {
				var grp = $(this).parent().parent();
				var idx = grp.children('.active').prevAll().size();
				var i;
				do {
					i = Math.floor(Math.random()*(grp.children().size()-1))+1;
				} while(grp.children().size() > 2 && i == idx)
				grp.children('.active').removeClass('active');
				grp.children('.main').html(grp.children().eq(i).html());
				grp.children().eq(i).addClass('active');
				grp.children('.main').children('a').css('color', '#ffffff');
				grp.children('.main').children('a').animate({'color': "#03486c"}, 1000, 'linear');
			});
		}
	});
	$('.hotoffer .main a').css('color', "#03486c");
	setTimeout(anim, Math.floor(Math.random(propSpeedRand))+propSpeedConst);
}

function domenuhide() {
	$('#lc-menu .lvl3').css('display', 'none');
}

var lcmenuhide;

$(document).ready(function() {
	grpCount = $('.hotoffer').size(); 
	setTimeout(anim, 1000);

	$('#lc-menu li').hover(function() {
		$(this).children('div').children('a').addClass('hover');
		$('#lc-menu .lvl3').not($(this)).not($(this).parentsUntil('#lc-menu'))
			.not($(this).find('.lvl3')).css('display', 'none');
		$(this).children('.lvl3').css('display', 'block');
	}, function() {
		$(this).children('div').children('a').removeClass('hover');
	});
	
	$('#lc-menu').hover(function() {
		clearTimeout(lcmenuhide);
	}, function() {
		lcmenuhide = setTimeout('domenuhide()', autohide_timeout);
	});
	
	$('.content-descr .scroll').before('<div class="maximize"><a href="#"><img alt="⟀" ' +
				'title="Maximize" src="' + baseUrl + '/res/norvica/img/zoom-in-small.png" width="32" height="32" /></a></div>');
	$('.maximize a').click(function() {
		 $.fancybox({
             'content' : '<div class="maximize-wrapper">' + $(this).parent('.maximize').next('.scroll').html() + '</div>'
         });
		 return false;
	});
	
	$('.content-descr h3 + table').prev().css('text-align', 'center');
});
