$(document).ready(function(){
	$('ul.accordion').each(function(){
		var _list = $(this).children();
		var _a = _list.index(_list.filter('.opened:eq(0)'));
		
		_list.each(function(_i){
			if(!$(this).hasClass("just_link")){
				var _el = $(this);
				_el.removeClass('opened');
				this._btn = _el.children('a:first');
				this._box = _el.children('.slide').hide();
				if(_i == _a){
					this._box.show();
					_el.addClass('opened');
				}
				this._btn.click(function(){
					if(_a != -1){
						_list.eq(_a).removeClass('opened');
						_list.get(_a)._box.stop().animate({height: 0}, 400, function(){
							$(this).css({display: 'none', height: 'auto'});
						});
					}
					if(_a != _i){
						_list.get(_i)._box.css({height: 'auto', display: 'block'});
						_list.eq(_i).addClass('opened');
						if(!_list.get(_i)._box.is(':animated')){
							_list.get(_i)._h = _list.get(_i)._box.height();
							_list.get(_i)._box.css({height: 0, display:'block'});
						}
						_list.get(_i)._box.stop().animate({ height: _list.get(_i)._h}, 400, function(){
							$(this).height('auto');
						});
						_a = _i;
					}
					else{
						_a = -1;
					}
					return false;
				});
					
					
		} else {
			
		//	return false;
		}
			
		});
	});
});