var LighterboxUpdater = Class.create({
	
	initialize: function (options) {
		this.options = Object.extend({
			openButton: null,
			data: {},
			contentDiv: null,
			divHeight: 615,
			divWidth: 800,
			printButton: true,
			showNow: true,
			url: ''
		}, options || {});
	
		this.objLighterbox = null;

		if ( !this.options.contentDiv ) {
			this.options.contentDiv = generateGuid();
		}
		
		this._buildLB();
	},
	_buildLB: function () {
		$(document.body).fillin({
			template: templatefactory.get('lighterbox-updater'),
			position: 'bottom',
			object: { ID: this.options.contentDiv, HEIGHT: this.options.divHeight, WIDTH: this.options.divWidth },
			callback: this._loadLB.bind(this)
		})	
	},
	_loadLB: function (elm) {
		var lb = new Lighterbox({
			openButton: $(this.options.openButton),
			lightWindow: $(this.options.contentDiv + '-lighter-window'),
			closeButton: $(this.options.contentDiv + '-lighter-window').down('.lighterwindow_close_link')
		});		
		var lw = lb.options.lightWindow;
		var lwc = lw.down('.lb-content');
		var lwprint = lw.down('.lb-content');
		
		this.objLighterbox = lb;

		if ( this.options.printButton ) {
			new PrintButton ( $(this.options.contentDiv + '-lighter-window').down('.lighterwindow_print_link'),
								{ divToPrint: lwprint } );
		} else {
			$(this.options.contentDiv + '-lighter-window').down('.lighterwindow_print_link').hide();
		}
		
		this.ifShowNow();
		
		new Ajax.Updater ( lwc, this.options.url, { 
							evalScripts: false,
							onComplete: this.ifShowNow.bind(this)
							} );
	},
	ifShowNow: function() {
		if ( this.options.showNow ) {
			this.show();
		}
	},
	show: function () {
		this.objLighterbox.show();
	},
	hide: function () {
		this.objLighterbox.hide();
	}
});
