if(typeof (AC)=="undefined"){
	AC={}
}
AC.Bureau = Class.create();
Object.extend(AC.Bureau.prototype, Event.Listener);
Object.extend(AC.Bureau.prototype,{
	    drawers: null,
	    container:null,
	    triggerTimeout:null,
	    initialize:function(A){
		    this.drawers = [];
		    this.container = $(A)
	    },
	    addDrawer: function(A){},
	    getDrawerCount: function(){
		    return this.drawers.length
	    },
	    hasDrawers: function(){
		    return(this.drawers.length>0)
	    },
	    getFirstDrawer: function(){
		    return this.drawers[0]||null
	    },
	    getLastDrawer: function(){
		    return this.drawers[this.drawers.length-1]||null
	    },
	    scheduleTrigger: function(B,A){
		    this.triggerTimeout = setTimeout(B,A)
	    },
	    clearTrigger: function(){
		    clearTimeout(this.triggerTimeout)
	    }
    }
);

AC.Drawer=Class.create();
Object.extend(AC.Drawer.prototype, Event.Publisher);
Object.extend(AC.Drawer.prototype, {
	bureau:null,contentElement:null,handle:null,indicator:null,isOpen:true,beforeOpen:null,afterOpen:null,beforeClose:null,afterClose:null,transitionDuration:0.3,triggerDelay:0,
	initialize:function(F,D,B,C){
		this.contentElement=$(F);
		this.handle=$(D);
		this.bureau=B;
		var E="click";
		if(C!==null&&typeof (C)!="undefined"){
			this.beforeOpen=C.beforeOpen;
			this.afterOpen=C.afterOpen;
			this.beforeClose=C.beforeClose;
			this.afterClose=C.afterClose;
			if(typeof (C.triggerEvent)!="undefined"){
				E=C.triggerEvent
			}
			if(typeof (C.triggerDelay)!="undefined"){
				this.triggerDelay=C.triggerDelay
			}
			if(typeof (C.transitionDuration)!="undefined"){
				this.transitionDuration=C.transitionDuration
			}
		}
		if(AC.Detector.isException()){
			this.transitionDuration=0;
			E="click"
		}
		Element.addClassName(this.contentElement,"last");
		var A=function(G){
			if(AC.Detector.isException()&&(this.isOpen&&(this.isVisible===true))&&this.handle.tagName.match(/a/i)){
				return
			}
			Event.stop(G);
			if(this.triggerDelay>0){
				var H=this.trigger.bind(this);
				B.scheduleTrigger(H,this.triggerDelay)
			}
			else{
				this.trigger()
			}
		};
		Event.observe(this.handle,E,A.bind(this),false);
		Event.observe(this.handle,"mouseout",B.clearTrigger.bind(B),false)
	},
	toggle:function(){},
	open:function(){},
	close:function(){}
}
);
AC.SlidingBureau=Class.create();
Object.extend(AC.SlidingBureau.prototype,AC.Bureau.prototype);
Object.extend(AC.SlidingBureau.prototype,{
	isLocked:false,addDrawer:function(B){
		Element.addClassName(B.contentElement,"last");
		Element.addClassName(B.handle,"last");
		if(this.hasDrawers()){
			var A=this.getLastDrawer();
			A.setNextDrawer(B);
			B.setPreviousDrawer(A)
		}
		else{
			Element.addClassName(B.contentElement,"first");
			Element.addClassName(B.handle,"first")
		}
		this.listenForEvent(B,"beforeOpen",false,function(C){
			var D=C.event_data.data;
			this.open(D)
		}
		);
		this.listenForEvent(B,"afterOpen",false,function(C){
			var D=C.event_data.data;
			this.acknowledgeOpened(D)
		}
		);
		this.listenForEvent(B,"beforeClose",false,function(C){
			var D=C.event_data.data;
			this.close(D)
		}
		);
		this.listenForEvent(B,"afterClose",false,function(C){
			var D=C.event_data.data;
			this.acknowledgeClosed(D)
		}
		);
		if(!Element.hasClassName(B.contentElement,"open")){
			B.initiateClose()
		}
		else{
			this.currentDrawer=B
		}
		this.drawers.push(B)
	}
	,open:function(A){
	    if (!document.styleSheets.length) {
	        return;
	    }
		if(this.isLocked){
			return
		}
		this.isLocked=true;
		var C=0;
		if(Element.getStyle(this.container,"position")=="relative"){
			var B=Element.getDimensions(this.container);
			Element.setStyle(this.container,{
				height:B.height+"px"
			}
			);
			this.wedgeDrawersAfter(A);
			C=Element.getStyle(A.contentElement,"min-height");
			if(C){
				Element.setStyle(A.contentElement,{
					"min-height":"0px",height:C
				}
				)
			}
		}
		if(this.currentDrawer){
			this.currentDrawer.initiateClose()
		}
		A.open(C)
	}
	,acknowledgeOpened:function(A){
		this.currentDrawer=A;
		if(Element.getStyle(this.container,"position")=="relative"){
			if(!AC.Detector.isIEStrict()){
				Element.setStyle(this.container,{
					height:"auto"
				}
				)
			}
			this.unwedgeDrawers()
		}
		this.isLocked=false
	}
	,close:function(A){
		var B=0;
		if(Element.getStyle(this.container,"position")=="relative"){
			B=Element.getStyle(A.contentElement,"min-height");
			if(B){
				Element.setStyle(A.contentElement,{
					height:B,"min-height":"0px"
				}
				)
			}
		}
		A.close(B)
	}
	,acknowledgeClosed:function(A){
		if(A==this.currentDrawer){
			this.currentDrawer=null
		}
	}
	,wedgeDrawersAfter:function(D){
		var A=function(E,F){
			Element.setStyle(E.handle,{
				position:"absolute",bottom:F+"px"
			}
			)
		};
		var B=this.getLastDrawer();
		var C=0;
		while(B!=this.currentDrawer&&B!=D){
			A(B,C);
			C+=B.handle.getHeight();
			B=B.previousDrawer
		}
	}
	,unwedgeDrawers:function(){
		for(var A=this.drawers.length-1;A>=0;A--){
			Element.setStyle(this.drawers[A].handle,{
				position:"static"
			}
			)
		}
	}
}
);
AC.SlidingDrawer=Class.create();
Object.extend(AC.SlidingDrawer.prototype,AC.Drawer.prototype);
Object.extend(AC.SlidingDrawer.prototype,{
	isOpen:true,
	isTransitioning:false,
	setNextDrawer:function(A){
		this.nextDrawer=A;
		Element.removeClassName(this.contentElement,"last");
		Element.removeClassName(this.handle,"last")
	}
	,setPreviousDrawer:function(A){
		this.previousDrawer=A
	}
	,trigger:function(){
		this.toggle()
	}
	,toggle:function(){
		if(!this.isOpen){
			this.initiateOpen()
		}
	}
	,initiateOpen:function(){
		if(this.isTransitioning||this.isOpen){
			return
		}
		this.dispatchEvent("beforeOpen",this)
	}
	,open:function(C){
		this.isTransitioning=true;
		if(typeof (this.beforeOpen)=="function"){
			this.beforeOpen(this)
		}
		Element.addClassName(this.contentElement,"open");
		Element.addClassName(this.handle,"open");
		var B=function(){
			this.isOpen=true;
			if(C){
				Element.setStyle(this.contentElement,{
					"min-height":C
				}
				);
				if(!AC.Detector.isIEStrict()){
					Element.setStyle(this.contentElement,{
						"height":"auto"
					}
					)
				}
			}
			this.dispatchEvent("afterOpen",this);
			this.isTransitioning=false;
			if(typeof (this.afterOpen)=="function"){
				this.afterOpen(this)
			}
		}
		.bind(this);
		if(AC.Detector.isException()){
			this.contentElement.show();
			B()
		}
		else{
			var A=new Effect.BlindDown(this.contentElement,{
				duration:this.transitionDuration,afterFinish:B
			}
			)
		}
	}
	,initiateClose:function(A){
		if(this.isTransitioning||!this.isOpen){
			return
		}
		this.dispatchEvent("beforeClose",this)
	}
	,close:function(C){
		this.isTransitioning=true;
		if(typeof (this.beforeClose)=="function"){
			this.beforeClose(this)
		}
		var B=function(){
			this.isOpen=false;
			Element.removeClassName(this.contentElement,"open");
			Element.removeClassName(this.handle,"open");
			if(C){
				Element.setStyle(this.contentElement,{
					"min-height":C
				}
				);
				if(!AC.Detector.isIEStrict()){
					Element.setStyle(this.contentElement,{
						"height":"auto"
					}
					)
				}
			}
			this.dispatchEvent("afterClose",this);
			this.isTransitioning=false;
			if(typeof (this.afterClose)=="function"){
				this.afterClose(this)
			}
		}
		.bind(this);
		if(AC.Detector.isException()){
			this.contentElement.hide();
			B()
		}
		else{
			var A=new Effect.BlindUp(this.contentElement,{
				duration:this.transitionDuration,afterFinish:B
			}
			)
		}
	}
}
);
AC.ShingleBureau=Class.create();
Object.extend(Object.extend(AC.ShingleBureau.prototype,AC.Bureau.prototype),{
	drawerDuration:0.5,addDrawer:function(B){
		if(this.hasDrawers()){
			var A=this.getLastDrawer();
			A.setNextDrawer(B);
			B.setPreviousDrawer(A);
			B.closedOffset=A.closedOffset+A.getHandleHeight()-10
		}
		else{
			Element.addClassName(B.contentElement,"first");
			B.closedOffset=0-B.getHeight()+B.getHandleHeight()-10;
			B.indicateVisible()
		}
		this.drawers.push(B)
	}
	,getWidth:function(){
		return Element.getWidth(this.container)
	}
	,getHeight:function(){
		return Element.getHeight(this.container)
	}
	,moveDrawer:function(C,A,D){
		var B=new Effect.Move(C,{
			x:A,y:D,mode:"absolute",transition:Effect.Transitions.sinoidal,duration:this.drawerDuration
		}
		)
	}
}
);
AC.ShingleDrawer=Class.create();
Object.extend(Object.extend(AC.ShingleDrawer.prototype,AC.Drawer.prototype),{
	openedOffset:0,closedOffset:0,previousDrawer:null,nextDrawer:null,isVisible:false,trigger:function(){
		if(!this.isVisible){
			this.open(true);
			this.indicateVisible()
		}
	}
	,toggle:function(){
		if(!this.isOpen){
			this.open();
			this.indicateVisible()
		}
		else{
			this.close()
		}
	}
	,open:function(A){
		if(this.isOpen&&!A){
			return
		}
		if(this.previousDrawer!==null){
			this.previousDrawer.close();
			this.previousDrawer.indicateObscured()
		}
		if(this.nextDrawer!==null){
			this.nextDrawer.open();
			this.nextDrawer.indicateObscured()
		}
		this.indicateVisible();
		this.isOpen=true;
		this.bureau.moveDrawer(this.contentElement,0,this.openedOffset)
	}
	,close:function(A){
		if(!this.isOpen){
			return
		}
		if(this==this.bureau.getLastDrawer()){
			return
		}
		if(this.previousDrawer!==null){
			this.previousDrawer.close()
		}
		this.bureau.moveDrawer(this.contentElement,0,this.closedOffset);
		this.indicateObscured();
		this.isOpen=false
	}
	,setPreviousDrawer:function(A){
		this.previousDrawer=A;
		this.indicateObscured();
		this.openedOffset=this.previousDrawer.openedOffset+this.previousDrawer.getHandleHeight()-10;
		Element.setStyle(this.contentElement,{
			top:this.openedOffset+"px"
		}
		)
	}
	,setNextDrawer:function(A){
		this.nextDrawer=A;
		Element.removeClassName(this.contentElement,"last");
		if(this.previousDrawer!==null){
			this.previousDrawer.setNextDrawer(this)
		}
		zIndex=parseInt(Element.getStyle(this.contentElement,"zIndex"),10);
		    Element.setStyle(this.contentElement,{
			    "zIndex":zIndex+1
		    }
		)
	}
	,indicateObscured:function(){
		Element.addClassName(this.contentElement,"obscured");
		this.isVisible=false
	}
	,indicateVisible:function(){
		this.isVisible=true;
		Element.removeClassName(this.contentElement,"obscured")
	}
	,getHandleWidth:function(){
		return Element.getWidth(this.handle)
	}
	,getHandleHeight:function(){
		return Element.getHeight(this.handle)
	}
	,getWidth:function(){
		return Element.getWidth(this.contentElement)
	}
	,getHeight:function(){
		return Element.getHeight(this.contentElement)
	}
}
);
AC.SectionBureau=Class.create();
Object.extend(AC.SectionBureau.prototype,AC.Bureau.prototype);
Object.extend(AC.SectionBureau.prototype,{
	currentDrawer:null,locked:false,addDrawer:function(A){
		this.drawers.push(A);
		Element.addClassName(A.handle,"obscured");
		Element.hide(A.contentElement)
	}
	,openingDrawer:function(A){
		if(this.currentDrawer!==null){
			this.currentDrawer.close()
		}
		this.currentDrawer=A
	}
}
);
AC.SectionDrawer=Class.create();
Object.extend(AC.SectionDrawer.prototype,AC.Drawer.prototype);
Object.extend(AC.SectionDrawer.prototype,{
	isOpen:false,trigger:function(){
		this.toggle()
	}
	,toggle:function(){
		if(!this.isOpen){
			this.open()
		}
	}
	,open:function(){
		if(this.bureau.locked){
			return
		}
		var B=function(){
			Element.show(this.contentElement)
		}
		.bind(this);
		if(typeof (this.afterOpen)=="function"){
			this.bureau.locked=true;
			B=this.afterOpen.bind(this)
		}
		this.bureau.openingDrawer(this);
		if(typeof (this.beforeOpen)=="function"){
			this.beforeOpen()
		}
		this.isOpen=true;
		Element.removeClassName(this.handle,"obscured");
		var A=new Effect.Appear(this.contentElement,{
			afterFinish:B,duration:this.transitionDuration,queue:{
				scope:"sectionalscope"
			}
		}
		)
	}
	,close:function(){
		if(typeof (this.beforeClose)=="function"){
			this.beforeClose()
		}
		this.isOpen=false;
		Element.addClassName(this.handle,"obscured");
		var A=function(){
			if(typeof (this.afterClose)=="function"){
				this.afterClose()
			}
		}
		.bind(this);
		var B=new Effect.Fade(this.contentElement,{
			afterFinish:A,duration:this.transitionDuration,queue:{
				scope:"sectionalscope"
			}
		}
		)
	}
	,reportFinishedOpening:function(){
		this.bureau.locked=false
	}
}
)
