/*
	Lightbox - Carl Whittaker 11/01/2007
	"open" generates a lightbox that disables all functions of the page and brings focus to its contents, call "close" to close.

	*htmlCollection can be raw html or a collection of html created with DOM methods

	**Requires Scriptaculous
*/

if(typeof(error) !== "function"){ var error = function(v){ alert(v); } }

var Lightbox = {
	el: null,
	hiddenScrolls: [],
	fitToViewport: true,
	open: function(htmlCollection, className){
		try{
			if(this.el == null){
				var Lightbox = '<div id="lightbox-container"><div id="lightbox-overlay"></div><div id="lightbox-drop-shadow" style="display:none;"><div id="lightbox"><span id="lightbox-links"><a href="javascript:void(0);" onclick="Lightbox.close();" class="close-link">Close</a></span><div id="lightbox-inner"></div><span style="clear:both;"></span></div></div>';

				new Insertion.Bottom(document.body, Lightbox);

				this.el = $("lightbox");
				this.elContainer = $("lightbox-container");
				this.elOverlay = $("lightbox-overlay");
				this.elInner = $("lightbox-inner");
				this.elOuter = $("lightbox-drop-shadow");

			}

			/* Hide those pesky select fields! */
			$(document.body).getElementsBySelector("select").each(
				function(el){
					el.style.visibility = "hidden";
				}
			);

			/* Hide Embedded Object's */
			$(document.body).getElementsBySelector("object").each(
				function(el){
					el.style.visibility = "hidden";
				}
			);

			this.elContainer.className = className;
			this.elContainer.style.display="block";

			if(typeof(htmlCollection) == "object"){
				this.elInner.appendChild(htmlCollection);
			}else{
				this.elInner.innerHTML = htmlCollection;
			}
			
			this.elOuter.style.display = "block";
			this.elOverlay.style.filter="alpha(opacity=80)";
			this.elOverlay.style.display="block";
			this.elOverlay.style.height = document.body.scrollHeight+"px";

			if($("content-body")){ /* hack to get rid of that odd render bug in firefox lightboxes */
				$("content-body").style.overflow = "hidden";
			}

		}catch(e){
			error("Error creating lightbox ",e);
		}
	},
	close: function(){
		try{
			if(this.el != null){
				this.elOuter.style.display = "none";
				var finish = function(){

					/* Materialise those pesky select fields! */
					$(document.body).getElementsBySelector("select").each(
						function(el){
							el.style.visibility = "visible";
						}
					);

					/* Materialise Embedded Object's */
					$(document.body).getElementsBySelector("object").each(
						function(el){
							el.style.visibility = "visible";
						}
					);

					Lightbox.elContainer.style.display="none";
					Lightbox.elInner.innerHTML = "";

					if(document.qt_player){
						try{
							document.qt_player.SetAutoPlay(false);
							document.qt_player.SetQTNEXTUrl(1, null);
							document.qt_player.SetURL("/images/beamtv/site/logo_beamtv.gif");
							document.qt_player.Stop();
						}catch(e){

						}
					}

					Lightbox.elInner.innerHTML = "";
				}

				new Effect.Fade(Lightbox.elOverlay, {duration: 0.5, from: 0.8, to: 0.0, afterFinish:finish});
			}
		}catch(e){
			error("Error destroying lightbox ",e);
		}
	}
}
