﻿
var ResizableLightBox=new Class({

	Implements: Options,

	options: {
		currentBox: null,
		trigger: null,
		width: 0,
		height: 0,
		disableLeftAdjust: false,
		heightAdjust: 0,
		leftAdjust: 0,
		offsetContainer: $('aspnetForm'),
		clickbgclose: false,
		isGallery: false
	},
	//Constructor
	initialize: function(options) {
		this.setOptions(options);
		var boundShowBox=this.showBox.bind(this); //Changes the scope 'this'
		$$(this.options.trigger).addEvent('click',boundShowBox);
		$$(this.options.trigger).setStyle('cursor','pointer');
		this.visible=false;
	},
	//Public showBox
	showBox: function(e) {
		if ($$('div.AMH'))
			$$('div.AMH').setStyles({ 'z-index': '-100' });
		this.createElements();
		this.visible=true;
		if ($chk(e))
			e.stop();
	},
	//Public resizeBox
	resizeBox: function(options) {
		this.setOptions(options);
		this.whiteBox.setStyles({ 'display': 'block','height': this.options.height,'width': this.options.width });
		var windowHeight=window.getSize().y?window.getSize().y:window.getSize().Height;
		var topStyle=(((windowHeight-400-this.options.height.toInt())/2)+window.getScroll().y);
		if ((this.options.isGallery)==true) {
			if (parseInt(topStyle)< -180) {
				topStyle="-180";
			}
		}
		var leftStyle=((965-this.options.width.toInt())/2);
		this.whiteBox.setStyle('top',topStyle+'px');
		this.whiteBox.setStyle('left',leftStyle+'px');
	},
	//Public hideBox
	hideBox: function(e) {
		if (this.visible) {
			if (this.blackBackground)
				this.blackBackground.dispose();
			if ($$('div.AMH'))
				$$('div.AMH').setStyles({ 'z-index': '10000' });
			this.whiteBox.setStyle('display','none');
			this.visible=false;
		}
		if ($chk(e))
			e.stop();
	},
	//Protected
	createElements: function() {
		//Create main box elements
		if (this.options.offsetContainer.getElementById("blackBackground")!=null)
			this.blackBackground=this.options.offsetContainer.getElementById("blackBackground");
		else
		{
			this.blackBackground=new Element('div',{ id: 'blackBackground' });
			//Inject elements
			this.blackBackground.inject(this.options.offsetContainer,'');
		}
		this.whiteBox=this.options.currentBox;
		//Positioning fixes
		this.blackBackground.setStyles({
			'height': window.getScrollSize().y,
			'opacity': '.7'
		});
		this.resizeBox(this.options);
		//Bind close
		var boundHideBox=this.hideBox.bind(this); //Changes the scope 'this'
		this.whiteBox.getElement('.close').addEvent('click',boundHideBox);
		if ((this.options.clickbgclose)==true) {
			this.blackBackground.addEvent('click',boundHideBox);
		}
	} .protect()
});

