//The Saturno Lightbox JS class addes lightbox type function to webpages. 
//functions: 
//		updateSize: used to re-position the lightbox on the page and redraw size. (Called when windows is resized.)
//		show: shows lightbox
//		hide: hides lightbox
//		setLinks: Adds on click function to .SaturnoCloseLightBox and .SaturnoOpenLightBox
//CSS:
//		#SaturnoOverlay{position: absolute;top:0;left:0;z-index:-1; background-color:Transparent;}
//		#SaturnoLightboxTarget{background-color:White;}
//Author: Ronald Eddy
//Beta release: 11 Nov 2008
//Copyright 2008 Saturno Design LLC. All rights reserved.

window.addEvent('domready', function() {

		SaturnoLightBox=new SaturnoLightboxClass;


})


var SaturnoLightboxClass = new Class({

	initialize: function(){
	
	var objBody = $$('body')[0];
	objBody.appendChild(new Element('div', {id:'SaturnoOverlay', 'style': 'display:none'}));
	var box = new Element('div',{id:'SaturnoLightBox'})
	box.appendChild(new Element('div',{id:'SaturnoLightboxTarget'}));
	objBody.appendChild(box);

	window.addEvent('resize', function(){SaturnoLightBox.updateSize()});

	this.setLinks();
	
	},
	
	updateSize: function(){
		var pageSize = getSize();
		var targetSize = $('SaturnoLightboxTarget').getSize();
		//alert("The element is "+pageSize.x+" pixels wide and "+pageSize.y+"pixels high.");
			if ($('SaturnoOverlay'))
			{
				$('SaturnoOverlay').set('styles', {
					'height': getScrollHeight() + 'px',
					'width': getScrollWidth() + 'px'
				});
			}
			if ($('SaturnoLightboxTarget'))
			{	
				if (pageSize.y<targetSize.y)
				{
					$('SaturnoLightboxTarget').set('styles', {
						'top': '5px'
					});
				}
				else
				{
					$('SaturnoLightboxTarget').set('styles', {
						'top': (pageSize.y /2)-(targetSize.y/2) + getScrollTop()
					});
				}
				
				if (pageSize.x<targetSize.x)
				{
					$('SaturnoLightboxTarget').set('styles', {
						'left': '5px'
					});
				}
				else
				{
					$('SaturnoLightboxTarget').set('styles', {
						'left': (pageSize.x/2)-(targetSize.x/2)
					});
				}
				
				
				$('SaturnoLightboxTarget').set('styles', {
					'position': 'absolute',
					'z-index': '1002'
				});
			}			
	},

	show: function(){
			this.updateSize();
			$('SaturnoOverlay').set('styles', {
				'z-index': '1000',
				'background-color' : 'Black',
				'visibility' : 'hidden',
				'display': 'block'
				});
				
			$('SaturnoOverlay').fade(0, 0.7);


			
			$('SaturnoLightBox').set('styles', {
				'z-index': '1001',
				'visibility' : 'visible'
			});

			//alert("The element is "+targetSize.x+" pixels wide and "+targetSize.y+"pixels high.");
			
			$('SaturnoOverlay').addEvent('click', function(){
				SaturnoLightBox.hide();
			});

	},
	
	hide: function(){
			
			$('SaturnoOverlay').fade(0.7, 0);
			setTimeout( $('SaturnoOverlay').set('styles', {'display': 'none'}), 1000);
			
			$('SaturnoOverlay').set('styles', {
				'z-index': '-1',
				'background-color' : 'transparent',
				'visibility' : 'hidden'
			});
				
			$('SaturnoLightBox').set('styles', {
				'visibility' : 'hidden'
			});

	},
	setLinks: function(){
		$$('.SaturnoCloseLightBox').addEvent('click', function(event) {
			//prevent the page from changing
			event.stop();
			SaturnoLightBox.hide();
		})
		$$('.SaturnoOpenLightBox').addEvent('click', function(event) {
			//prevent the page from changing
			event.stop();
			SaturnoLightBox.show();
		})
	}
	



})


//on dom ready...
window.addEvent('domready', function() {
	/* ajax replace element text */
	$$('.SaturnoLightboxTarget').addEvent('click', function(event) {
			//prevent the page from changing
			event.stop();
			//make the ajax call, replace text
			
			var req = new Request.HTML({
				method: 'get',
				url: this.get('href'),
				onRequest: function() {  },
				update: $('SaturnoLightboxTarget'),
				onComplete: function(response) { SaturnoLightBox.show(); SaturnoLightBox.updateSize();SaturnoLightBox.setLinks(); }
			}).send();
		});	
		$$('.SaturnoLightboxTarget').setStyle('visibility', 'visible');
});    
    
    



    
    
    