var copyrightMessage = "Deze afbeelding is auteursrechtelijk beschermd en mag niet\nzonder toestemming van de auteur worden gebruikt.";
var ImageLoader = Class.create();

        ImageLoader.prototype = {
            initialize: function( bigImageID, statischURL ) {
                this.imageURLs         = new Array();
                this.imagesLoaded      = new Array();
                this.images            = new Array();
                this.imageCount        = 0;
                this.activeImageID     = null;
                this.bigImage          = null;
                this.bigImageID        = bigImageID;
                this.indicator         = null;
                this.wwwstatisch       = statischURL;
                this.loadImages        = 0;
                this.ProtectImgEnabled = false;
            },

            protectImage: function(value) {
                this.ProtectImgEnabled = value;
            },

            addImage: function(imageNumber,imageURL) {
                this.imageURLs[imageNumber] = imageURL;
                this.imageCount++;
            },

            showImage: function(imageNumber) {
                if (this.imageCount > 0 && imageNumber <= this.imageCount) {
                    this.bigImage = $(this.bigImageID);
                    this.loadingIndicator();
                    this.switchImage(imageNumber);
                }
            },

            switchActiveThumbnail: function(imageNumber) {
                if (this.imageCount == 1)
                    return; // No thumbnails
            },

            switchImage: function(imageNumber) {
                this.bigImage = $(this.bigImageID);
                this.switchActiveThumbnail(imageNumber);
                this.bigImage.src = this.imageURLs[imageNumber];
                if(this.ProtectImgEnabled) { this.ProtectImg(this.bigImage); }
                this.activeImageID = imageNumber;
                this.preLoadImages();
            },

            preLoadImages: function() {
                var nextImage = this.activeImageID;
                do { 
                    this.preLoadImage(nextImage);
                    nextImage++;
                } while (nextImage <= (this.activeImageID + this.loadImages));
            },

            preLoadImage: function(imageNumber) {
                if (this.imagesLoaded[imageNumber] != true) {
                    this.images[imageNumber] = new Image();
                    this.images[imageNumber].src = this.imageURLs[imageNumber];
                    this.imagesLoaded[imageNumber] = true;
                }
            },

            loadingIndicator: function() {
                if ($('image_loader') && this.bigImage) {
                    if (this.indicator == null) {
                        var imgTop = 0;
                        var imgLeft = 0;
                        var obj = null;
                        obj = this.bigImage;
                        do { imgTop += obj.offsetTop; imgLeft += obj.offsetLeft; } while (obj = obj.offsetParent);
                        $('image_loader').style.top = imgTop + (Math.floor(this.bigImage.offsetHeight / 2)) - 16 + 'px';
                        $('image_loader').style.left = imgLeft + (Math.floor(this.bigImage.offsetWidth / 2)) - 16 + 'px';
                    }
                    $('image_loader').style.display = '';
                    this.bigImage.onload = function() { $('image_loader').style.display = 'none'; document.location = "#fotos"; }
                }
            },

 
            ProtectImg: function(img) {
                img.galleryimg = "no";
                img.ondragstart = function () { return false; }
                img.onmousedown = function (e) {
                if( e && e.preventDefault ) { e.preventDefault(); }
                if( document.all ) { 
                    if( event.button == 2 ) { alert(copyrightMessage); return false; } }
                    else { if( e.which == 3 ) { alert(copyrightMessage); return false; } }
                }
                img.oncontextmenu = function () { return false; }
            }
        };

function scroll_to_image() {
    var objAnchor = $('fotos');
    if (objAnchor.scrollIntoView) objAnchor.scrollIntoView(true);

    // Fixed BUG-1700
    Event.stopObserving($('top_image'), 'load', scroll_to_image);
}

