// Preload the background images:
 bg1 = new Image(); 
 bg1.src = "/fileadmin/templates/thoreau/images/lb_top.gif";
 
 bg2 = new Image(); 
 bg2.src = "/fileadmin/templates/thoreau/images/lb_middle.gif";
 
 bg3 = new Image(); 
 bg3.src = "/fileadmin/templates/thoreau/images/lb_bottom.gif";
 
 bg4 = new Image(); 
 bg4.src = "/fileadmin/templates/thoreau/images/lb_top.png";
 
 bg5 = new Image(); 
 bg5.src = "/fileadmin/templates/thoreau/images/lb_middle.png";
 
 bg6 = new Image(); 
 bg6.src = "/fileadmin/templates/thoreau/images/lb_bottom.png";

function isIe7(){
	if(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" && document.all){
		return true;
	}else{
		return false
	}
}

var lightBox = {
	overlayHtml: '<div id="lbOverlay" style="display: none; height: #{height}px;"></div>',
	pageHeight: 0,
	triggers: new Array(),
	visibleEl: false,
	showOverlay: function() {
		if(isIe7()){
			// ie7 only
			$('lbContentGroup').removeClassName('lbGif');
		}
		new Effect.Appear('lbOverlay', { duration: 0.2, from: 0.0, to: 0.7 });
	},
	hideOverlay: function() {
		if(isIe7()){
			// ie7 only
			$('lbContentGroup').addClassName('lbGif');
		}
		new Effect.Fade(lightBox.visibleEl);		
		new Effect.Fade('lbOverlay');
	},	
	init: function() {
		// constants
		lightBox.pageHeight = $('lightBox').getHeight();

		// setup overlay
		var snip = new Template(lightBox.overlayHtml);
		var markers = {height: lightBox.pageHeight};
		var overlay = snip.evaluate(markers);
		new Insertion.Top(document.body, overlay);
		//new Insertion.Top($('lbContentGroup'), overlay);
				
		// setup triggers
		lightBox.setupTriggers();
		lightBox.setupClosers();
	},
	setupClosers: function() {
		lightBox.closers = $('lightBox').getElementsByClassName('lbCloseContent');
		lightBox.closers.each(function(closer, index) {
			Event.observe(closer, 'click', function() {
				lightBox.hideOverlay();
			});
			closer.onclick = function(){return false};
		});
	},
	setupTriggers: function() {
		lightBox.triggers = $('lightBox').getElementsByClassName('lbTrigger');
		lightBox.triggers.each(function(trig, index) {
			Event.observe(trig, 'click', function() {
				lightBox.doTrigger(trig);
			});
			trig.onclick = function(){return false};
		});
	},
	doTrigger: function(trig) {
		lightBox.showOverlay();
		var contentEl = $(trig.id + 'content');
		lightBox.visibleEl = contentEl;
//		new Effect.Appear(contentEl, { duration: 0.2, from: 0.0, to: 1 });
		new Effect.BlindDown(contentEl, {duration: 1.0});
	}
};

Event.observe(window, 'load', function() {
  lightBox.init();
});