// -----------------------------------------------------------------------------------
//
//	Lightbox v2.04
//	by Lokesh Dhakar - http://www.lokeshdhakar.com
//	Last Modification: 2/9/08
//
//	For more information, visit:
//	http://lokeshdhakar.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//  	- Free for use in both personal and commercial projects
//		- Attribution requires leaving author name, author link, and the license info intact.
//	
//  Thanks: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets.
//  		Artemy Tregubenko (arty.name) for cleanup and help in updating to latest ver of proto-aculous.
//
// -----------------------------------------------------------------------------------
/*

    Table of Contents
    -----------------
    Configuration

    Lightbox Class Declaration
    - initialize()
    - updateImageList()
    - start()
    - changeImage()
    - resizeImageContainer()
    - showImage()
    - updateDetails()
    - updateNav()
    - enableKeyboardNav()
    - disableKeyboardNav()
    - keyboardAction()
    - preloadNeighborImages()
    - end()
    
    Function Calls
    - document.observe()
   
*/
// -----------------------------------------------------------------------------------


//
//  Configurationl
//
LightboxOptions = Object.extend({
    fileLoadingImage:        'DesktopModules/Fotoboek/images/loading.gif',     
    fileBottomNavCloseImage: 'DesktopModules/Fotoboek/images/closelabel.gif',

    overlayOpacity: 0.8,   // controls transparency of shadow overlay

    animate: true,         // toggles resizing animations
    resizeSpeed: 700,        // controls the speed of the image resizing animations (1=slowest and 10=fastest)

    borderSize: 10,         //if you adjust the padding in the CSS, you will need to update this variable

	// When grouping images this is used to write: Image # of #.
	// Change it for non-english localization
	labelImage: "Afbeelding",
	labelOf: "van"
}, window.LightboxOptions || {});

// -----------------------------------------------------------------------------------

//var Lightbox = Class.create();

var Lightbox = {
    imageArray: [],
    activeImage: undefined,
    
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
    
    hasInnerTextProperty : (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false,
    
   
    // initialize()
    // Constructor runs on completion of the DOM loading. Calls updateImageList and then
    // the function inserts html at the bottom of the page which is used to display the shadow 
    // overlay and the image container.
    //
    initialize : function() {
        
        this.updateImageList();
        
        this.keyboardAction = this.keyboardAction.bindAsEventListener(this);

        if (LightboxOptions.resizeSpeed > 1000) LightboxOptions.resizeSpeed = 1000;
        if (LightboxOptions.resizeSpeed < 1)  LightboxOptions.resizeSpeed = 1;

	    //this.resizeDuration = LightboxOptions.animate ? ((1001 - LightboxOptions.resizeSpeed) * 0.15) : 0;
	    this.resizeDuration = LightboxOptions.animate ? LightboxOptions.resizeSpeed : 0;
	    this.overlayDuration = LightboxOptions.animate ? 200 : 0;  // shadow fade in/out duration
	    
        // When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
        // If animations are turned off, it will be hidden as to prevent a flicker of a
        // white 250 by 250 box.
        var size = (LightboxOptions.animate ? 250 : 1) + 'px';
        

        // Code inserts html at the bottom of the page that looks similar to this:
        //
        //  <div id="overlay"></div>
        //  <div id="lightbox">
        //      <div id="outerImageContainer">
        //          <div id="imageContainer">
        //              <img id="lightboxImage">
        //              <div style="" id="hoverNav">
        //                  <a href="#" id="prevLink"></a>
        //                  <a href="#" id="nextLink"></a>
        //              </div>
        //              <div id="loading">
        //                  <a href="#" id="loadingLink">
        //                      <img src="images/loading.gif">
        //                  </a>
        //              </div>
        //          </div>
        //      </div>
        //      <div id="imageDataContainer">
        //          <div id="imageData">
        //              <div id="imageDetails">
        //                  <span id="caption"></span>
        //                  <span id="numberDisplay"></span>
        //              </div>
        //              <div id="bottomNav">
        //                  <a href="#" id="bottomNavClose">
        //                      <img src="images/close.gif">
        //                  </a>
        //              </div>
        //          </div>
        //      </div>
        //  </div>


        var objBody = $$('body')[0];
        
       
        var lbn =  document.createElement('div');
        lbn.id = 'lightbox';
        
        var vrl = document.createElement('div');
        vrl.id = 'overlay';

		objBody.appendChild(vrl);
		objBody.appendChild(lbn);
		
		lbn.innerHTML = "<div id=\"outerImageContainer\"> " +
						"        <div id=\"imageContainer\">" +
						"            <img id=\"lightboxImage\">" +
						"            <div style=\"\" id=\"hoverNav\">" +
						"                <a href=\"#\" id=\"prevLink\"></a>" +
						"                <a href=\"#\" id=\"nextLink\"></a>" +
						"            </div>" +
						"            <div id=\"loading\">" +
						"                <a href=\"#\" id=\"loadingLink\">" +
						"                    <img src=\"images/loading.gif\">" +
						"                </a>" +
						"            </div>" +
						"        </div>" +
						"    </div>" +
						"    <div id=\"imageDataContainer\">" +
						"        <div id=\"imageData\">" +
						"            <div id=\"imageDetails\">" +
						"                <span id=\"caption\"></span>" +
						"                <span id=\"numberDisplay\"></span>" +
						"            </div>" +
						"            <div id=\"bottomNav\">" +
						"                <a href=\"#\" id=\"bottomNavClose\">" +
						"                    <img src=\"images/close.gif\">" +
						"                </a>" +
						"            </div>" +
						"        </div>" +
						"    </div>";

		this.hideElement( $('overlay')).addEvent('click', (function() { this.end(); }).bind(this));
		this.hideElement($('lightbox')).addEvent('click', (function(event) { if (this.getEventElement(event).id == 'lightbox') this.end(); }).bind(this));
		
		$('outerImageContainer').style.width = size;
		$('outerImageContainer').style.height= size;
		
		$('prevLink').addEvent('click', (function(event) { this.stopEvent(event); this.changeImage(this.activeImage - 1); }).bindAsEventListener(this));
		$('nextLink').addEvent('click', (function(event) { this.stopEvent(event); this.changeImage(this.activeImage + 1); }).bindAsEventListener(this));
		$('loadingLink').addEvent('click', (function(event) { this.stopEvent(event); this.end(); }).bind(this));
		$('bottomNavClose').addEvent('click', (function(event) { this.stopEvent(event); this.end(); }).bind(this));
        
        var th = this;

        window.setTimeout(
        (function(){
            var ids = 
                'overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink ' + 
                'imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose';

					//$w(ids).each(function(id){ th[id] = $(id); }); })
					var idArray = ids.split(" ");
					
					for(var i =0; i<idArray.length; i++)
					{
						var id = idArray[i];

						th[id] = $(id);
					}
				})
				
				,
				10);
    },
    
    stopEvent : function(e)
    {
		if (window.event)
		{
			e.cancelBubble = true;
			e.returnValue = false;
		}
		else
		{
			e.stopPropagation();
			e.preventDefault();
		}
		
		e.stopped = true;
    },

    hideElement : function(e)
    {
		e.style.display = 'none';
		return e;
    },
    
    showElement: function(e)
    {
		e.style.display = '';
		return e;
    },
    
    makeElementInvisible : function(e)
    {
		e.style.visibility = 'hidden';
		return e;
    },
    
    makeElementVisible: function(e)
    {
		e.style.visibility = '';
		return e;
    },

    //
    // updateImageList()
    // Loops through anchor tags looking for 'lightbox' references and applies onclick
    // events to appropriate links. You can rerun after dynamically adding images w/ajax.
    //
    updateImageList : function() {   
        //this.updateImageList = Prototype.emptyFunction;
        this.updateImageList = null;
        
        
        document.addEvent('click', (function(event){
            this.handleOpenClick(event);
        }).bind(this));
    },
    
    handleOpenClick : function(event)
    {
		var target = this.findLightBoxElement(this.getEventElement(event)); //|| this.findElement(event, 'area[rel^=lightboximage]');

		if (target)
		{
			this.stopEvent(event);
			this.start(target);
		}
    },
    
    
    findLightBoxElement: function(element)
    {
		var parent = element['parentNode'];

		if(parent==null)
			return null;

		var parentRel = parent['rel'];

		if(parentRel==null)
			return this.findLightBoxElement(parent);

		parentRel = new String(parentRel);

		if(parentRel.indexOf('lightboximage[', 0)==0)
			return parent;
		else
			return this.findLightBoxElement(parent);
	},

    
    //
    //  start()
    //  Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
    //
    start: function(imageLink) {    

        $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });

        // stretch overlay to fill page and fade in
        var arrayPageSize = this.getPageSize();
        //$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
        
        $('overlay').style.width = arrayPageSize[0] + 'px';
        $('overlay').style.height = arrayPageSize[1] + 'px';
        
        this.overlay.style.visibility = 'hidden';
		this.overlay.style.display = '';

        //new Effect.Appear(this.overlay, { duration: this.overlayDuration, from: 0.0, to: LightboxOptions.overlayOpacity });
        this.overlay.style.display = '';
        var fxs = new Fx.Style(this.overlay, 'opacity', {duration:this.overlayDuration});       
        fxs.start(0.0001, LightboxOptions.overlayOpacity);

        this.imageArray = [];
        var imageNum = 0;       

        if ((imageLink.rel == 'lightboximage')){
            // if image is NOT part of a set, add single image to imageArray
            this.imageArray.push([imageLink.href, imageLink.title]);         
        }
        else
        {
			var relname = new String(imageLink.rel);

            // if image is part of a set..
			var imageArrayTemp = $$(imageLink.tagName + '[rel^=lightboximage\[]');

			this.imageArray = new Array();

			for(var i=0; i<imageArrayTemp.length; i++)
			{
				this.imageArray.push([imageArrayTemp[i].href, imageArrayTemp[i].title]);
			}

            while (this.imageArray[imageNum][0] != imageLink.href) { imageNum++; }
        }

        // calculate top and left offset for the lightbox 
        var arrayPageScroll = this.getWindowScrollOffsets();
        var lightboxTop = arrayPageScroll[1] + (this.getBrowserHeight() / 10);
        var lightboxLeft = arrayPageScroll[0];
        
        //this.lightbox.setStyle({ top: lightboxTop + 'px', left: lightboxLeft + 'px' }).show();
        this.lightbox.style.top = lightboxTop + 'px';
        this.lightbox.style.left = lightboxLeft + 'px';
        
        this.showElement(this.lightbox);

        this.changeImage(imageNum);
    },
    
	getWindowScrollOffsets: function()
	{
		var l = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
		var t = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;

		var result = [l, t];

		result.left = l;
		result.top = t;

		return result;
	},


    //
    //  changeImage()
    //  Hide most elements and preload image in preparation for resizing image container.
    //
    changeImage: function(imageNum) {   
        
        this.activeImage = imageNum; // update global var

        // hide elements during transition
        if (LightboxOptions.animate)
			this.showElement(this.loading);
			
        this.hideElement(this.lightboxImage);
        this.hideElement(this.hoverNav);
        this.hideElement(this.prevLink);
        this.hideElement(this.nextLink);
		// HACK: Opera9 does not currently support scriptaculous opacity and appear fx
        //this.imageDataContainer.setStyle(new String('opacity: .0001'));
        //this.imageDataContainer.style.opacity =  '.0001';
        
        //this.hideElement(this.numberDisplay);
        this.hideElement(this.imageDataContainer);
        
        var imgPreloader = new Image();
        
        var thisLightbox = this;

        // once image is preloaded, resize image container
        imgPreloader.onload = (function(){		
            thisLightbox.lightboxImage.src = thisLightbox.imageArray[thisLightbox.activeImage][0];
            thisLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height);
        }); //.bind(this);
        
        imgPreloader.src = this.imageArray[this.activeImage][0];
    },

    //
    //  resizeImageContainer()
    //
    resizeImageContainer: function(imgWidth, imgHeight) {

        // get current width and height
        var widthCurrent  = this.getElementWidth(this.outerImageContainer);
        var heightCurrent = this.getElementHeight(this.outerImageContainer);

        // get new width and height
        var widthNew  = (imgWidth  + LightboxOptions.borderSize * 2);
        var heightNew = (imgHeight + LightboxOptions.borderSize * 2);

        // scalars based on change from old to new
        var xScale = (widthNew  / widthCurrent)  * 100;
        var yScale = (heightNew / heightCurrent) * 100;     

        // calculate size difference between new and old image, and resize if necessary
        var wDiff = widthCurrent - widthNew;
        var hDiff = heightCurrent - heightNew;
        
        //if (hDiff != 0) new Effect.Scale(this.outerImageContainer, yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'}); 
        //if (wDiff != 0) new Effect.Scale(this.outerImageContainer, xScale, {scaleY: false, duration: this.resizeDuration, delay: this.resizeDuration}); 
        
        var thisLightbox = this;

        // if new and old image are same size and no scaling transition is necessary, 
        // do a quick pause to prevent image flicker.
        var timeout = 0;
        if ((hDiff == 0) && (wDiff == 0)){
            timeout = 100;
            
            if (this.IE) timeout = 250;
        }
        
        if (hDiff != 0)
        {
//			new Effect.Scale(this.outerImageContainer, yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'}); 
			var fxs = new Fx.Style(this.outerImageContainer, 'height',
					{
						duration:this.resizeDuration,
						onComplete: function()
						{
							if (wDiff != 0)
							{
								var fxsB = new Fx.Style(thisLightbox.outerImageContainer, 'width',
										{
											duration:thisLightbox.resizeDuration,
											onComplete: (function ()
														{

															(function()
															{
																thisLightbox.prevLink.style.height = imgHeight + 'px';
																thisLightbox.nextLink.style.height = imgHeight + 'px';
																thisLightbox.imageDataContainer.style.width = widthNew + 'px';

																thisLightbox.showImage();
															}).bind(this).delay(timeout / 1000);

														})
										});
								fxsB.start(widthCurrent, widthNew);
							}
							else
							{
								(function()
								{
									thisLightbox.prevLink.style.height = imgHeight + 'px';
									thisLightbox.nextLink.style.height = imgHeight + 'px';
									thisLightbox.imageDataContainer.style.width = widthNew + 'px';

									thisLightbox.showImage();
								}).bind(this).delay(timeout / 1000);
							}

						}
					}).start(heightCurrent, heightNew);
		}
		else if (wDiff != 0)
        {
//			new Effect.Scale(this.outerImageContainer, xScale, {scaleY: false, duration: this.resizeDuration, delay: this.resizeDuration}); 
			var fxs = new Fx.Style(this.outerImageContainer, 'width',
					{
						duration:this.resizeDuration,
						onComplete: (function ()
									{

										(function()
										{
											thisLightbox.prevLink.style.height = imgHeight + 'px';
											thisLightbox.nextLink.style.height = imgHeight + 'px';
											thisLightbox.imageDataContainer.style.width = widthNew + 'px';

											thisLightbox.showImage();
										}).bind(this).delay(timeout / 1000);

									})
					}).start(widthCurrent, widthNew);
		}
		else
		{
			(function()
			{
				this.showImage();
			}).bind(this).delay(timeout / 1000);
		}


//		var fxs = new Fx.Style($('overlay'), 'opacity', {duration:this.overlayDuration}).start(1);

/*
        (function(){
			this.prevLink.style.height = imgHeight + 'px';
            this.nextLink.style.height = imgHeight + 'px';
            this.imageDataContainer.style.width = widthNew + 'px';

            this.showImage();
        }).bind(this).delay(timeout / 1000);
*/
    },
    
    //
    //  showImage()
    //  Display image and begin preloading neighbors.
    //
    showImage: function(){
        this.hideElement(this.loading);
        
        /*new Effect.Appear(this.lightboxImage, { 
            duration: this.resizeDuration, 
            queue: 'end', 
            afterFinish: (function(){ this.updateDetails(); }).bind(this) 
        });*/

        var thisLightbox = this;
        
		thisLightbox.lightboxImage.style.visibility = 'hidden';
		thisLightbox.lightboxImage.style.display = '';

        
		// Start the fade effect
		var fxs = new Fx.Style(this.lightboxImage, 'opacity',
        {
			duration:this.resizeDuration,
			onStart:function()
			{
			},
			onComplete:function() 
			{
				(function()
				{
					this.updateDetails();
				}).bind(thisLightbox).delay(100);
			}
		});

		fxs.start(0, 1);
        
        this.preloadNeighborImages();
    },

    //
    //  updateDetails()
    //  Display caption, image number, and bottom nav.
    //
    updateDetails: function() {

        // if caption is not null
        if (this.imageArray[this.activeImage][1] != "")
        {
			this.setElementText(this.caption, this.imageArray[this.activeImage][1]);
            this.showElement(this.caption);
        }
        
        // if image is part of set display 'Image x of x' 
        if (this.imageArray.length > 1)
        {
			this.setElementText(this.numberDisplay, LightboxOptions.labelImage + ' ' + (this.activeImage + 1) + ' ' + LightboxOptions.labelOf + '  ' + this.imageArray.length);
            this.showElement(this.numberDisplay);
        }

		/*
        new Effect.Parallel(
            [ 
                new Effect.SlideDown(this.imageDataContainer, { sync: true, duration: this.resizeDuration, from: 0.0, to: 1.0 }), 
                new Effect.Appear(this.imageDataContainer, { sync: true, duration: this.resizeDuration }) 
            ], 
            { 
                duration: this.resizeDuration, 
                afterFinish: (function()
                {
	                // update overlay size and update nav
	                var arrayPageSize = this.getPageSize();
	                //this.overlay.setStyle({ height: arrayPageSize[1] + 'px' });
	                this.overlay.style.height = arrayPageSize[1] + 'px';
	                this.updateNav();
                }).bind(this)
            });
            */
            
            var thisLightbox = this;
            var imageDataContainerHeight = 40;
            
            // Appear
/*
            this.imageDataContainer.style.display = '';
            var fxs = new Fx.Style(this.imageDataContainer, 'opacity',
					{
						duration:this.resizeDuration,
						onSetup:(function ()
						{
							thisLightbox.imageDataContainer.style.opacity = 0;
						}),
						onComplete:function()
						{
							// update overlay size and update nav
							var arrayPageSize = thisLightbox.getPageSize();
							thisLightbox.overlay.style.height = arrayPageSize[1] + 'px';
							thisLightbox.updateNav();							
						}
					});

				fxs.start(0, 1);
*/
            var fxsa = new Fx.Style(this.imageDataContainer, 'opacity',
					{
						duration:this.resizeDuration,
						onComplete:function()
						{
							// update overlay size and update nav
							var arrayPageSize = thisLightbox.getPageSize();
							thisLightbox.overlay.style.height = arrayPageSize[1] + 'px';
							thisLightbox.updateNav();
						}
					});

			fxsa.start(0, 1);

            var fxsb = new Fx.Style(this.imageDataContainer, 'height',
					{
						duration:this.resizeDuration,
						onStart: function()
						{
							thisLightbox.imageDataContainer.style.overflow = 'hidden';
							thisLightbox.imageDataContainer.style.height = 1;
							thisLightbox.imageDataContainer.style.display = '';
						}
					});

			fxsb.start(1,40);

    },

    //
    //  updateNav()
    //  Display appropriate previous and next hover navigation.
    //
    updateNav: function() {

        this.showElement(this.hoverNav);

        // if not first image in set, display prev image button
        if (this.activeImage > 0)
			this.showElement(this.prevLink);

        // if not last image in set, display next image button
        if (this.activeImage < (this.imageArray.length - 1))
			this.showElement(this.nextLink);
        
        this.enableKeyboardNav();
    },

    //
    //  enableKeyboardNav()
    //
    enableKeyboardNav: function() {
        document.addEvent('keydown', this.keyboardAction ); 
    },

    //
    //  disableKeyboardNav()
    //
    disableKeyboardNav: function() {
        document.removeEvent('keydown', this.keyboardAction ); 
    },

    //
    //  keyboardAction()
    //
    keyboardAction: function(event)
    {
        var keycode = event.keyCode;

        var escapeKey;
        if (event.DOM_VK_ESCAPE) {  // mozilla
            escapeKey = event.DOM_VK_ESCAPE;
        } else { // ie
            escapeKey = 27;
        }

        var key = String.fromCharCode(keycode).toLowerCase();
        
        if (key.match(/x|o|c/) || (keycode == escapeKey)){ // close lightbox
            this.end();
        } else if ((key == 'p') || (keycode == 37)){ // display previous image
            if (this.activeImage != 0){
                this.disableKeyboardNav();
                this.changeImage(this.activeImage - 1);
            }
        } else if ((key == 'n') || (keycode == 39)){ // display next image
            if (this.activeImage != (this.imageArray.length - 1)){
                this.disableKeyboardNav();
                this.changeImage(this.activeImage + 1);
            }
        }
    },

    //
    //  preloadNeighborImages()
    //  Preload previous and next images.
    //
    preloadNeighborImages: function(){
        var preloadNextImage, preloadPrevImage;
        if (this.imageArray.length > this.activeImage + 1){
            preloadNextImage = new Image();
            preloadNextImage.src = this.imageArray[this.activeImage + 1][0];
        }
        if (this.activeImage > 0){
            preloadPrevImage = new Image();
            preloadPrevImage.src = this.imageArray[this.activeImage - 1][0];
        }
    
    },
    
    
    setElementText : function(element, text)
    {
		if(this.hasInnerTextProperty)
		{
			element.innerText = text;
		}
		else
		{
			element.textContent = text;
		}
    },

    //
    //  end()
    //
    end: function() {
        this.disableKeyboardNav();
        this.hideElement(this.lightbox);
        
        var thisLightbox = this;
        var oldOpacity = LightboxOptions.overlayOpacity;

        //new Effect.Fade(this.overlay, { duration: this.overlayDuration });
        
        var fxs = new Fx.Style(this.overlay, 'opacity',
			{
				duration:this.overlayDuration,
				onComplete:function() 
				{				
					//thisLightbox.hideElement(thisLightbox.overlay);
					thisLightbox.overlay.style.visibility = 'hidden';
					thisLightbox.overlay.style.display = 'none';
					thisLightbox.overlay.style.opacity = oldOpacity;				
				}
			});
        
        fxs.start(LightboxOptions.overlayOpacity, 0);

        //$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
        var temp = $$('select', 'object', 'embed');
        
        for(var i=0; i<temp.length; i++)
        {
			temp[i].style.visibility = 'visible';
        }
    },
    
	getBrowserDimensions: function()
	{
		var dimensions = { };

		dimensions['width'] = (this.WebKit && !document.evaluate) ? self['innerWidth'] :(this.Opera) ? document.body['clientWidth'] : document.documentElement['clientWidth'];
		dimensions['height'] = (this.WebKit && !document.evaluate) ? self['innerHeight'] :(this.Opera) ? document.body['clientHeight'] : document.documentElement['clientHeight'];

		return dimensions;
	},

	getBrowserWidth: function()
	{
		return this.getBrowserDimensions().width;
	},

	getBrowserHeight: function()
	{
		return this.getBrowserDimensions().height;
	},

    //
    //  getPageSize()
    //
    getPageSize: function() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	},
	
	
	getElementWidth: function(element)
	{
		return this.getElementDimensions(element).width;
	},
	
	getElementHeight: function(element)
	{
		return this.getElementDimensions(element).height;
	},
	
	getElementDimensions: function(element)
	{
		element = $(element);

		var display = $(element).style.display;
		
		if (display != 'none' && display != null) // Safari bug
			return {width: element.offsetWidth, height: element.offsetHeight};

		// All *Width and *Height properties give 0 on elements with display none,
		// so enable the element temporarily
		var els = element.style;
		var originalVisibility = els.visibility;
		var originalPosition = els.position;
		var originalDisplay = els.display;
		els.visibility = 'hidden';
		els.position = 'absolute';
		els.display = 'block';
		var originalWidth = element.clientWidth;
		var originalHeight = element.clientHeight;
		els.display = originalDisplay;
		els.position = originalPosition;
		els.visibility = originalVisibility;
		return {width: originalWidth, height: originalHeight};
	},
	
	
	getEventElement: function(e)
	{
		if(this.IE)
		{
			return e.srcElement;
		}
		else
		{
			return e.target;
		}
	}
}

//new function () { new Lightbox(); }

//document.observe('dom:loaded', function () { new Lightbox(); });  // domready?
window.addEvent('domready', 
function ()
{
	Lightbox.initialize();
} );
