/*
	
	Booking Panel Class
	
*/
var Popup = Class.create({ 
	initialize: function( options )
 	{
    	this.options = {
			trigger		: false,
      		url			: '#',
			name		: 'popup',
      		width		: 300,
      		height		: 300,
			toolbar		: 0,
			scrollbars	: 0,
			location	: 0,
			statusbar	: 0,
			menubar		: 0,
			resizable	: 0,
			left 		: 0,
			top 		: 0
    	}
    	Object.extend(this.options, options || {});
    	
		this.w 		= this.options.width;
		this.h 		= this.options.height;
		this.left 	= this.options.left;
		this.top	= this.options.top;
		
		// width
		if (this.w.match("px"))
			this.w = this.w.replace('px', '');
			
		if (this.w.match("%")) {
			this.w = this.w.replace('%', '');
			this.w = this.getScreenWidth() * (this.w/100);
		}
		
		// height
		if (this.h.match("px"))
			this.h = this.h.replace('px', '');
			
		if (this.h.match("%")) {
			this.h = this.h.replace('%', '');
			this.h = this.getScreenHeight() * (this.h/100);
		}
		
		// positioning
		this.left = (this.getScreenWidth() / 2) - (this.w / 2);
		this.top = (this.getScreenHeight() / 2) - (this.h / 2);
		
		if (this.options.trigger) {
			Event.observe(this.options.trigger, 'click', this.launch.bindAsEventListener(this));
		}
 	},
	getScreenHeight : function () {
		var sh = 700
		if (navigator.userAgent.substring(0, 12) != "Mozilla/2.0") {
			if (screen.Height >= 0) {
				sh = screen.Height - 75; 
			}
			else if (screen.availHeight >= 0) {
				sh = screen.availHeight - 45;
			}
		}
		return sh;
	},
	getScreenWidth : function () {
		var sw = 500
		if (navigator.userAgent.substring(0, 12) != "Mozilla/2.0") {
			if ((screen.Width >= 0)) {
				sw = screen.Width - 10;
			} else if ((screen.availWidth >= 0)) {
				sw = screen.availWidth - 10;
			}
		}
		return sw;
	},
	launch : function (e) {
		if (e) {
			Event.stop(e);
		}
		// launch
		this.popup =	window.open(
							this.options.url, 
							this.options.name, 
							'width='+this.w+
							',height='+this.h+
							',toolbar='+this.options.toolbar+
							',scrollbars='+this.options.scrollbars+
							',location='+this.options.location+
							',statusbar='+this.options.statusbar+
							',resizable='+this.options.resizable+
							',left='+this.left+
							',top='+this.top
						)
	
		this.popup.focus();
		
	}
});
