

var lightbox = Class.create();
lightbox.prototype = {
	
	initialize: function() {
		$('lightbox_bg').setStyle({ opacity: 0.7 });
		$('lightbox_close').onclick = function() {
			page_lightbox.stop();
			return false;
		};
	},
	
	view: function(options) {
	
		var page = options.page;
		var params = options.params;
		var width = options.width;
		var content = options.content;
	
		$('lightbox_html').update('');
		
		if( content ) {
			$('lightbox_html').update(content);
		} else {
			new Ajax.Request( page, {
				parameters: params,
				onComplete: function(t) {
				  var result = t.responseText;
				  $('lightbox_html').update(result);
				  if( page == '/ord/basket_personalise.html' ) {
      		  var basket_embossing = new embossingCheck('update_button');
      		}
				}
			});
		}
		
		this.realign(width,options.top);
		$('lightbox_bg').show();
		new Effect.Grow('lightbox_view', {duration: 0.3});
		
	},
	
	stop: function() {
		$('lightbox_bg').hide();
		$('lightbox_view').hide();
	},
	
	realign: function(newWidth,newTop) {
	
		if( newWidth ) {
			Element.setWidth('lightbox_content',newWidth);
			var newWidthBox = newWidth-20;
			Element.setWidth('lightbox_box',newWidth);
		} else {
			Element.setWidth('lightbox_content',780);
			Element.setWidth('lightbox_box',780);
		}
		
		//stretch the overlay across the page
		var arrayPageSize = getPageSize();
		Element.setWidth('lightbox_bg',arrayPageSize[0]);
		Element.setHeight('lightbox_bg',arrayPageSize[1]);
		
		//center the image in the current document view
		var arrayPageScroll = getPageScroll();
		if( newTop ) {
			var view_top = newTop;
		} else {
			var view_top = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		}	
		var view_left = arrayPageScroll[0];
		$('lightbox_view').setStyle({ top: view_top+'px' });
		
	}	
	
};

function initLightbox() { page_lightbox = new lightbox(); }
document.observe('dom:loaded', initLightbox);