var note = {circle_count: 0};
var note_interval, note_busy = false;
$(function(){
	note_toggle();
	note_interval = window.setInterval("note_circle()", note_timeout*1000);
});

function note_change(dir, robot){
	if(note_busy) return;
	note_busy = true;
	if(robot==undefined) window.clearInterval(note_interval);
	with($("#note")){
		var pos = position();
		if(dir==-1){
			if(pos.top==0) {
				animate({top: "+="+note_height/4}, function(){
					animate({top: "-="+note_height/4}, "fast",
							function(){ note_busy = false; });
				});
			}
			else animate({top: "+="+note_height}, function(){ note_busy = false; });
		} else {
			if(pos.top-note_height<=-height()) {
				animate({top: "-="+note_height/4}, function(){
					animate({top: "+="+note_height/4}, "fast",
							function(){ note_busy = false; });
				});
			} else animate({top: "-="+note_height}, function(){ note_busy = false; });
		}
	}
}

function note_circle(){
	with($("#note")){
		var pos = position();
		if(pos.top-note_height<=-height()) {
			animate({top: "0"}, "fast");
			if(++note.circle_count>=2 && $(".note_hover").size()>0) note_toggle();
		} else note_change(+1, true);
	}
}

function note_toggle(){
	var note = $(".note");
	if(note.size()==0) $(".note_hover").removeClass("note_hover").addClass("note");
	else note.removeClass("note").addClass("note_hover");
	
}

function note_filter(group){
	var all = $(".note_note1");
	var group = $(".note_"+group);
	// Если все элементы видны, то выполняем фильтрацию.
	// Иначе, если все элементы фильтра видны, то фильтрация не нужна
	if(group.is(":visible") && !all.is(":visible")) return;
	all.hide();
	group.show();
	$("#note").animate({top: "0"});
}

function note_select_button(btn){
	$(".note_btn1").removeClass("note_btn1_hover");
	if($(btn).parents("note_hover").size()>0) $(btn).addClass("note_btn1_hover");
}
