Sonata.mapdrawer = function(options) {
	//see TEST/drawer.html for test code
	var defopts ={
		direction: Sonata.mapdrawer.RIGHT	//hide the drawer on the RIGHT
		,removedrawer: false
		,div: null
		,divWidth: 0
		,divHeight: 0
		,duration: 500
		,dx: 2	//adjust width for a 1px border
		,dy: 2	//adjust height for a 1px border
		,zIndex: 10
	};
	var opts;
	opts = $.extend({},defopts,options);
	var w = opts.divWidth ? opts.divWidth : opts.div.outerWidth();
	var h = opts.divHeight ? opts.divHeight : opts.div.outerHeight();
	opts.divWidth = w;
	opts.divHeight = h;
	var drawer = $("<div>").css({position:'absolute',left:0,top:0,width:w,height:h,'background-color':'transparent',overflow:'hidden','z-index':opts.zIndex});
	drawer.append(opts.div);
	var dir = opts.direction;
	var div = opts.div;
	if(div == null) {
		div = $("#not_a_valid_id",drawer);
	}
	div.css("position","relative");
	if(Sonata.isIE) {
		opts.dx -= 2;
		opts.dy -= 2;
	}
	//div.width(w-opts.dx);
	//div.height(h-opts.dy);
	var thisptr = this;
	this.options = opts;
	this.visible = false;
	this.drawer = drawer;
	this.div = div;

	this.setDirection(dir);
	//document.body.removeChild(this.drawer[0]);
	//this.removeDrawer();
}
Sonata.mapdrawer.RIGHT = 0;
Sonata.mapdrawer.LEFT = 1;
Sonata.mapdrawer.TOP = 2;
Sonata.mapdrawer.BOTTOM = 3;
Sonata.mapdrawer.prototype.removeDrawer = function()
{
	try {
		//$(document.body).remove(this.drawer);
		document.body.removeChild(this.drawer[0]);
	}
	catch(e) {
	}
}
Sonata.mapdrawer.prototype.setDirection = function(dir) {
	var show_css = {};
	var hide_css = {};
	var div = this.div;
	var w = this.options.divWidth;//this.drawer.width();
	var h = this.options.divHeight;//drawer.height();
	div.hide();
	switch(dir) {
		case Sonata.mapdrawer.RIGHT:
			div.css("left",w+"px");
			show_css = {left:0+"px"};
			hide_css = {left:w+"px"};
			//mprint("setting RIGHT");
			break;
		case Sonata.mapdrawer.LEFT:
			div.css("left",(-w)+"px");
			show_css = {left:0+"px"};
			hide_css = {left:(-w)+"px"};
			break;
		case Sonata.mapdrawer.TOP:
			div.css("top",(-h)+"px");
			show_css = {top:0+"px"};
			hide_css = {top:(-h)+"px"};
			break;
		case Sonata.mapdrawer.BOTTOM:
			div.css("top",h+"px");
			show_css = {top:0+"px"};
			hide_css = {top:h+"px"};
			break;
	}
	this.show_css = show_css;
	this.hide_css = hide_css;
	//mprint("dir="+dir);
	//Sonata.prObject("show_css",this.show_css);
	//Sonata.prObject("hide_css",this.hide_css);
	//the div is positioned outside the drawer
	//we can turn on the visibility flag
	div.css("visibility","visible");
	//div.show();
}
Sonata.mapdrawer.prototype.show = function() {
	if(this.visible) return;
	this.visible = true;
	$("body").append(this.drawer);
	this.drawer.show();this.drawer.attr("visibility","visible");
	this.div.show();this.div.attr("visibility","visible");
	//mprint("drawer.show");
	//Sonata.prObject("show_css",this.show_css);
	this.div.animate(this.show_css,{queue:false,duration:this.options.duration});
}
Sonata.mapdrawer.prototype.hide  = function() {
	if(this.visible==false) return;
	var thisptr = this;
	this.visible = false;
	this.div.animate(this.hide_css,{queue:false,duration:this.options.duration,complete:ondone});
	function ondone() {
		//$('body').remove(thisptr.drawer);
		if(thisptr.options.removedrawer) {
			thisptr.removeDrawer();
			//document.body.removeChild(thisptr.drawer[0]);
		}
	}
}
Sonata.mapdrawer.prototype.isVisible  = function() {
	return this.visible;
}