
Effect.ReSize = Class.create(Effect.Base, {
  initialize: function(element) {
    this.element = $(element);
    if (!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      width:    0,
      height:   0,
      mode: 'relative'
    }, arguments[1] || { });
    this.start(options);
  },
  setup: function() {
    this.element.makePositioned();
    this.originalWidth		= parseFloat(this.element.getStyle('width') || '0');
    this.originalHeight		= parseFloat(this.element.getStyle('height')  || '0');
    if (this.options.mode == 'absolute') {
      this.options.width = this.options.width - this.originalWidth;
      this.options.height = this.options.height - this.originalHeight;
    }
  },
  update: function(position) {
    this.element.setStyle({
      width: (this.options.width  * position + this.originalWidth).round() + 'px',
      height:  (this.options.height  * position + this.originalHeight).round()  + 'px'
    });
  }
});
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 },	getDrawer:function(A)					{ return this.drawers[A] || 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.isiPhone()){
			this.transitionDuration=0;
      E="click"
    }
    Element.addClassName(this.contentElement,"last");
      
    var A=function(G){
			if(AC.Detector.isiPhone() && (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.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.SlidingBureau=Class.create();
Object.extend(Object.extend(AC.SlidingBureau.prototype,AC.Bureau.prototype),{	currentDrawer:null,
	superContainer:null,	drawerDuration:0.5,
	addDrawer:function(B) {
		B.isOpen = false;		B.openedHeight = B.getHeight();
		B.closedHeight = B.getHeight();
		this.drawers.push(B);
	},	getWidth:function()						{ return Element.getWidth(this.container) },	getHeight:function()					{ return Element.getHeight(this.container) },	resizeDrawer:function(C,A,D)	{ var B=new Effect.ReSize(C,{ width:A,height:D,mode:"absolute",transition:Effect.Transitions.sinoidal,duration:this.drawerDuration})},	setSuperContainer:function(A)	{ this.superContainer = A },	closeCurrent:function()				{ if (this.currentDrawer !== null) this.currentDrawer.close();}
});
AC.SlidingDrawer=Class.create();
Object.extend(Object.extend(AC.SlidingDrawer.prototype,AC.Drawer.prototype),{
	openedHeight:0,	closedHeight:0,
	subMenu:null,	trigger:function()	{ if(!this.isOpen) { this.open(true); }	},	toggle:function()		{ if(!this.isOpen) { this.open(true); }	else { this.close() }},	open:function(A){
		var variaz = 0.0;		if(this.isOpen&&!A){ return }		if(this.bureau.currentDrawer == A){ return }//		if(this.closedHeight == this.openedHeight){ return }
		if(this.bureau.currentDrawer!==null )	{			variaz -= this.bureau.currentDrawer.openedHeight - this.bureau.currentDrawer.closedHeight;
			this.bureau.currentDrawer.close();		}
		this.isOpen=true;		this.bureau.currentDrawer = this;
		variaz += this.bureau.currentDrawer.openedHeight - this.bureau.currentDrawer.closedHeight;
		this.bureau.resizeDrawer(this.contentElement,this.getWidth(),this.openedHeight)
		if (this.bureau.superContainer!==null) { this.bureau.resizeDrawer(this.bureau.superContainer,this.bureau.superContainer.getWidth(),this.bureau.superContainer.getHeight() + variaz) }
	},	close:function(A){
		if(!this.isOpen){ return }
		this.bureau.resizeDrawer(this.contentElement,this.getWidth(),this.closedHeight);		if(this.subMenu !== null) this.subMenu.closeCurrent();		this.isOpen=false
		if (this.bureau.currentDrawer == this) this.bureau.currentDrawer = null;
	},	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) },	setSubMenu:function(A) { 
		this.subMenu = A;		this.openedHeight = this.getHeight() + A.getHeight();	}
});
