var FTrotate = {
	timer: null,
	last_rubric_index: 0,
	total_rubrics: 0,
	in_process: false,
	start: function(container, follow) {
        if (! container) {
            container = '#menu';
        }
        follow = 0 !== follow;
		links = $(container + ' img');
		this.total_rubrics = links.length;
		if (! this.timer) this.timer = setInterval(function(){
			toShow = FTrotate.last_rubric_index == (FTrotate.total_rubrics - 1) ? 0 : FTrotate.last_rubric_index + 1;
			FTrotate.in_process = true;
			$('#lead' + FTrotate.last_rubric_index + ', #leadlink' + FTrotate.last_rubric_index).fadeOut(1000, function(){
                if (follow) {
				    links.removeClass('hovered');
				    links.eq(toShow).addClass('hovered');
                }
				$('#lead' + toShow + ', #leadlink' + toShow).fadeIn(1000, function(){
					FTrotate.in_process = false;
				});
			});
			FTrotate.last_rubric_index = toShow;
		}, 5000);
	},
	activate: function(index) {
		if (FTrotate.in_process) return;
		$('#menu img').removeClass('hovered');
        $('#menu img:eq(' + index + ')').addClass('hovered');
		$('#leading_wrapper > div.start_main_articles_wrap:visible').find('h2').andSelf().hide();
		$('#lead' + index + ', #leadlink' + index).show();
		FTrotate.last_rubric_index = index;
	},
    stop: function(){
        if (this.timer) clearInterval(this.timer); this.timer = null;
    },
	pause: function(){
        this.stop();
        setInterval(function(){FTrotate.start()}, 5000);
	}
};