
// For our popup div forms
var BNoverDiv = new Class({

	Implements: Options,

	options: { 
		printDiv: null,
		oDivCSS: null,
		iDivCSS: null,
		grayout: false
	},

	initialize: function(options){

		this.setOptions(options) ;

		this.oDivCSS = this.options.oDivCSS ;
		this.iDivCSS = this.options.iDivCSS ;
		this.grayout = this.options.grayout ;
		this.grayoutDiv = null ;

		this.outerDiv = new Element('div').inject(document.body, 'top') ;
		this.innerDiv = new Element('div').inject(this.outerDiv, 'top') ;
		if (this.grayout) {
			this.grayoutDiv = new Element('div').inject(document.body, 'top').setStyles({
				display: 'none',
				position: 'absolute'
			}) ;
		}

		// bind events to this object
		this._mg_bound = this._maintain_grayout.bind(this) ;
		this._mc_bound = this._maintain_content.bind(this) ;
	}, 

	show: function(){
		this.outerDiv.setStyles(this.oDivCSS) ;
		this.innerDiv.setStyles(this.iDivCSS) ;
	},

	_maintain_content: function(){
		// this.innerDiv.setStyle('top', window.getScroll().y + 'px') ;
		this.innerDiv.scrollTo(0,0) ;
	},

	_maintain_grayout: function(){
		this.grayoutDiv.setStyles({ height: window.getScrollSize().y + 'px', width: window.getScrollSize().x + 'px' }) ;
	},

	activate: function(){
		window.addEvent('resize', this._mg_bound) ;
		window.addEvent('scroll', this._mg_bound) ;
		this.show() ;
		this._maintain_content() ;
		window.addEvent('resize', this._mc_bound) ;
		window.addEvent('scroll', this._mc_bound) ;

		this.displayDiv() ;

		if (this.grayout) {
			this.grayoutDiv.setStyles({
				overflow: 'hidden',
				top: '0px',
				bottom: '0px',
				left: '0px',
				right: '0px',
				height: window.getScrollSize().y + 'px',
				width: window.getScrollSize().x + 'px',
				backgroundColor: '#000000',
				opacity: .5,
				zIndex: 99,
				display: 'block'
			}) ;
		}
		this._maintain_grayout() ;
	},

	deactivate: function(refresh){
		if (this.grayout) {
			this.grayoutDiv.setStyles({
				height: '0px',
				width: '0px',
				backgroundColor: 'transparent', 
				opacity: 0,
				display: 'none'
			}) ;
		}
		window.removeEvent('resize', this._mg_bound) ;
		this.innerDiv.set('html', '') ;
		this.innerDiv.setStyles({ display: 'none' }) ;
		this.outerDiv.setStyles({ display: 'none' }) ;
		window.removeEvent('resize', this._mc_bound) ;
		window.removeEvent('scroll', this._mc_bound) ;
		if (refresh) { window.location.reload() ; }
	},

	deinitialize: function(){
		this.outerDiv.dispose() ;
	},

	displayDiv: function(){
		this.innerDiv.setStyle('opacity', 1) ;
		this.innerDiv.set('html', this.options.printDiv.get('html')) ;
	}
}) ;
