var Rbox = {
	duration: 0.2,
	
	currentId: 0,
	
	show: function(id) {
		this.currentId = id;
		
		this.showOverlay();
		if (!$(id).hasClassName('rbox_window')) {
			$(id).addClassName('rbox_window')
		}
		
		this.setWindowPosition(id)
		new Effect.Appear(id, {duration: this.duration, queue: 'end'})
		Element.scrollTo(id);
	},
	
	showOverlay: function() {
		if (!$('rbox_overlay')) {
			new Insertion.Bottom(document.body, '<div id="rbox_overlay" style="display: none;"></div>');
		}
		this.setOverlaySize();
	    this.hideSelectBoxes();
	    new Effect.Appear('rbox_overlay', {duration: this.duration, to: 0.6, queue: 'end'});
	},
	
	close: function(id) {
		obj_id = id ? id : this.currentId;
		new Effect.Fade(obj_id, {duration: 0.4});
		new Effect.Fade('rbox_overlay', {duration: this.duration});
		this.showSelectBoxes();
	},
	
	
	
	/*----------------------------------------------------------
	------------------------------------------------------------
	----------------------------------------------------------*/
	setOverlaySize: function() {
	   if (window.innerHeight && window.scrollMaxY) {
	     yScroll = window.innerHeight + window.scrollMaxY;
	   } else if (document.body.scrollHeight > document.body.offsetHeight) {
	     // all but Explorer Mac
	     yScroll = document.body.scrollHeight;
	   } else {
	     // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	     yScroll = document.body.offsetHeight;
	   }
	   $("rbox_overlay").style['height'] = yScroll +"px";
	 },
	
	 setWindowPosition: function(id)
	 {
	 	obj_id = id ? id : this.currentId;
	 	
	   var pagesize = this.getPageSize();  
	 
	   $(obj_id).style['width'] = 'auto';
	   $(obj_id).style['height'] = 'auto';
	
	   var dimensions = Element.getDimensions($(obj_id));
	   var width = dimensions.width;
	   var height = dimensions.height;        
	   
	   $(obj_id).style['left'] = ((pagesize[0] - width)/2) + "px";
	   $(obj_id).style['top'] = ((pagesize[1] - height)/2) + "px";
	 },
	
	
	 getPageSize: function() {
	   var de = document.documentElement;
	   var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	   var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	 
	   arrayPageSize = new Array(w,h) 
	   return arrayPageSize;
	 },
	 
	 hideSelectBoxes: function()
	 {
	 	selects = document.getElementsByTagName("select");
	 	for (i = 0; i != selects.length; i++) {
	 		selects[i].style.visibility = "hidden";
	 	}
	 },
	
	 showSelectBoxes: function()
	 {
	 	selects = document.getElementsByTagName("select");
	 	for (i = 0; i != selects.length; i++) {
	 		selects[i].style.visibility = "visible";
	 	}
	 }
}