jQuery.fn.extend({
	shelfAcc:function(opt){
		this.find('dd').css({display:'block'})
		var dfl={
			callback:false,
			duration:'slow',
			easing:'',
			active:'.active',
			holdActive:false,
			navLinks:'a[rel=shelfNav]'
		}
		opt=$.extend(dfl,opt)
		var keeper=this,
			accHideAll=function(){
				var tmp=this.innerHTML,d=document.createElement('div')
				d.innerHTML=tmp
				d.className='shelfInner'
				d.style.visibility='hidden'
				this.style.overflow='hidden'
				this.innerHTML=''
				this.appendChild(d)
				d.style.marginTop='-'+this.offsetHeight+'px'
			},
			accHideAllAnimated=function(){
				keeper.find('.shelfInner').each(function(){
					if(parseInt($(this).css('margin-top'))==0)
						$(this).animate({marginTop:'-'+this.offsetHeight+'px'},opt.duration,opt.easing,function(){this.style.visibility='hidden'})
				})
			},showItem=function(el){
				
				if(el.find('.shelfInner').css('visibility')=='hidden'){
					accHideAllAnimated()
					el.find('.shelfInner').css({visibility:'visible'}).animate({marginTop:0},opt.duration,opt.easing,opt.callback)
				}else{
					hideItem()
				}
			},hideItem=function(){
				accHideAllAnimated()
				keeper.find('dt').removeClass(opt.active.slice(1)).removeClass('hover')
			}
			
		
			$(this).find('dd').each(function(){accHideAll.call(this)})
		
			$(this).delegate('dt:not('+opt.active+')>a','click',function(){
				var th=$(this).parent()
				if(th[0].parentNode.id!=='content')return false
				keeper.find('dt').removeClass(opt.active.slice(1)).removeClass('hover')
				th.addClass(opt.active.slice(1))
				showItem(th.next())
				return false
			})
			if(!opt.holdActive)
				$(this).delegate('dt'+opt.active,'click',function(){
					$(this).removeClass('active')
					Cufon.refresh()
					hideItem($(this).next())
					return false
				})
			else
				$(this).delegate('dt'+opt.active,'click',function(){
					return false
				})
				
			$(opt.navLinks).live('click',function(){
				if(this.parentNode.className.indexOf(opt.active.slice(1))<0){
					var curr=$(this.href.slice(this.href.lastIndexOf('#')))
					showItem(curr)
					keeper.find('dt').removeClass(opt.active.slice(1)).removeClass('hover')
					curr.prev().addClass(opt.active.slice(1))
					$(this.parentNode).addClass(opt.active.slice(1)).siblings().removeClass(opt.active.slice(1))
				}
				return false
			})
			var idx,tmp
			if((idx=document.location.toString().indexOf('#'))>=0){
				showItem(tmp=$(document.location.toString().slice(idx)))
				tmp.parent().find('dt').removeClass(opt.active.slice(1))
				tmp.prev().addClass(opt.active.slice(1))
				$(opt.navLinks).each(function(){
					if(this.href.toString().indexOf(document.location.toString().slice(idx))>=0)
						$(this.parentNode).addClass(opt.active.slice(1))
				})
			}
		}
})
