var loggedIn = false;

SlidePane = new Class({
    initialize: function(options) {
		// public options
		this.edge = "top"; // edge to slide behind ("top","bottom","left","right");
		this.url;
		this.contents; // this property is a mootools Element
		
		// private
		this.container;
		this.loading_cnt;
		this.initTop; // these will be extracted from CSS
		this.initLeft;
		this.initBottom;
		this.initRight;
		this._contents;
		this.shown = true;
		
        Utilities.update(this, options);
		SlidePane.instances.push(this);
		this.setup();
    },
	setup: function(){
		this.container = new Element('div');
		this.container.setProperty('id','SlidePane_container');
		this.container.setStyle("position","absolute");
		this.initTop = parseInt(this.container.getStyle('top'));
		this.initTop = (isNaN())?0:this.initTop;
		this.initLeft = parseInt(this.container.getStyle('left'));
		this.initLeft = (isNaN())?0:this.initLeft;
		this.initBottom = parseInt(this.container.getStyle('bottom'));
		this.initBottom = (isNaN())?0:this.initBottom;
		this.initRight = parseInt(this.container.getStyle('right'));
		this.initRight = (isNaN())?0:this.initRight;
		this.container.injectInside($E('body'));
		
		this.hide(false);
		this.draw();
	},
	setContents: function(to){
		if(this.contents!=to){
			this.contents = to.clone();
			this.draw();
		}
	},
	draw: function(){
		if(this._contents!=this.contents){
			if(this.shown){
				this.hide(true);
			}else{
				if(this._contents)this._contents.remove();
				this._contents = this.contents;
				this._contents.injectInside(this.container);
				this.show(true);
				Extensions.divsChanged();
			}
		}
		if(this._contents){
			this.container.setStyle("width","100%");
			this.container.setStyle("height","100%");
			var metrics = this._contents.getCoordinates();
			this.container.setStyle("width",metrics.width+"px");
			this.container.setStyle("height",metrics.height+"px");
		}
	},
	show: function(tween){
		if(!this.shown)this.move(true,tween);
	},
	hide: function(tween){
		if(this.shown)this.move(false,tween);
	},
	move: function(show, tween){
		this.shown = show;
		var dest;
		var prop;
		var height = parseInt(this.container.getStyle("height"));
		var width = parseInt(this.container.getStyle("width"));
		if(this.edge=="top"){
			if(show)dest = this.initTop;
			else dest = -height;
		}else if(this.edge=="bottom"){
			if(show)dest = this.initBottom;
			else dest = window.getHeight()+height;
		}else if(this.edge=="left"){
			if(show)dest = this.initLeft;
			else dest = -width;
		}else if(this.edge=="right"){
			if(show)dest = this.initRight;
			else dest = window.getWidth()+width;
		}
		if(tween){
			var myThis = this;
			var myTween = new Fx.Style(this.container, this.edge, {duration:300,onComplete:function() {myThis.draw();}});
			myTween.start(dest);
		}else{
			this.container.setStyle(this.edge,dest+"px");
		}
	}
});

// static members
SlidePane.instances = [];