_prev_parent = [];
function initMenu() {
	$('#menu_accor ul').hide();
	$('#menu_accor input').each(function() {
		tA = $(this).parent();

		$(this).click(function(e) {
			toogleAccItem($(this).parent("a").attr('id'));
			e.stopPropagation();
			return false;
		});
	});
	
//	$('#menu_accor > li > a > input').each(function() {
//		$(this).css('display', 'none');
//	});
	
//	$('#menu_accor > li > a:has(input)').each(function() {
//		$(this).bind( "mouseover",
//			function(e) {
//				if($("#ul_" + e.target.id).is(":hidden"))
//					toogleAccItem(e.target.id);
//			}
//		);
//	});

	function toogleAccItem(id) {
		obj = $("#ul_" + id);
		if(obj.is(":hidden")) {
			obj.slideDown('slow');
			$("#ar_" + id).attr("src", "images/arrow_u.gif");
			//close previous accitem
			if(_prev_parent.length > 0) {
				_new_parent = [];
				_new_parent = $.makeArray(obj.parents("ul").map(function() {return this.id;}).get());
				_new_parent.unshift(obj.attr('id'));
				_new_parent.pop();
				$(_prev_parent).each(function() {
					if($.inArray(this + "", _new_parent) == -1) {
						$("#" + this).slideUp("slow");
						$("#ar_" + this.toString().substr(3)).attr("src", "images/arrow_d.gif");
					}
				});
				_prev_parent = _new_parent;
			}
			else {
				_prev_parent = $.makeArray(obj.parents("ul").map(function() {return this.id}).get());
				_prev_parent.unshift(obj.attr('id'));
				_prev_parent.pop();
			}
		}
		else {
			obj.slideUp('slow')
			$("#ar_" + id).attr("src", "images/arrow_d.gif");
			while(_prev_parent.length > 0) {
				objid = _prev_parent.shift();
				$("#" + objid).slideUp('slow');
				$("#ar_" + objid.toString().substr(3)).attr("src", "images/arrow_d.gif");
				if(objid == obj.attr('id'))
					break;
			}
		}
	}
	
	_tmp = [];
	_tmp = $.makeArray($('#menu_accor a.selected').parents("ul").map(function() {return this.id}).get());
	if(_tmp.length > 0) {
		_tmp = _tmp.reverse();
		$(_tmp).each(function() {
			if(this != 'menu_accor')
				toogleAccItem(this.toString().substr(3));
		});
	}
	else {
		toogleAccItem($('#menu_accor a:first').attr('id'));
	}
}
$(document).ready(function() {initMenu();});