var LIGHTGALLERY = new Class({
	initialize: function() {
		var _self = this;
		this.sID = null;
		
		this.images = new Array();
		this.imagePath = './images/';
		this.ajaxPath = './ajax/getImages.php';
		this.activeImage = 0;
		this.diashowTimer = null;
		this.diashowTime = 5000;
		this.diashow = false;
		
		this.timer = null;
		this.fadeTime = 3000;
		
		this.options = {
			imagePath:'./images/',
			name:null,
			directory:null,
			description:null,
			lightgalleryID:'lightgallery',
			controlPanelWrapperID:'controlpanel-wrapper',
			diashowWrapperID:'diashow-wrapper',
			diashowButtonPlaySrc:'button-diashow-play.gif',
			diashowButtonPauseSrc:'button-diashow-pause.gif',
			closeButtonWrapperID:'close-button-wrapper',
			closeButtonSrc:'button-close.gif',
			galleryInformationWrapperID:'gallery-information-wrapper',
			imageIndexID:'image-index',
			scrollFactor:5,
			scrollLeftButtonWrapperID:'scroll-left-button-wrapper',
			scrollLeftButtonID:'scroll-left-button',
			scrollLeftButtonSrc:this.imagePath + 'button-scroll-left.gif',
			scrollRightButtonWrapperID:'scroll-right-button-wrapper',
			scrollRightButtonID:'scroll-right-button',
			scrollRightButtonSrc:this.imagePath + 'button-scroll-right.gif',
			thumbnailWrapperID:'thumbnail-wrapper',
			thumbnailsID:'thumbnails',
			thumbnailHeight:60,
			thumbnailWidth:60,
			thumbnailBorder:0,
			thumbnailMarginRight:5,
			thumbnailMorphDown:5,
			previewWidth:200,
			previewHeight:200,
			previewBorder:3,
			imageWrapperID:'image-wrapper',
			imageWrapperHeight:0,
			imageBorder:0,
			imageOffsetHeight:60
		};
		
		this.elements = {
			lightgallery:null,
			controlPanelWrapper:null,
			diashowWrapper:null,
			diashow:null,
			diashowLabel:null,
			closeButtonWrapper:null,
			closeButtonLabel:null,
			closeButton:null,
			scrollLeftButtonWrapper:null,
			scrollLeftButton:null,
			scrollRightButtonWrapper:null,
			scrollRightButton:null,
			thumbnailWrapper:null,
			thumbnails:null,
			imageWrapper:null
		};
		
		this.fx = {
			diashowWrapper:null,
			timeDiashowWrapperFadeIn:300,
			timeDiashowWrapperFadeOut:300,
			closeButtonWrapper:null,
			timeCloseButtonWrapperFadeIn:300,
			timeCloseButtonWrapperFadeOut:300,
			scrollLeft:null,
			timeScrollLeft:500,
			scrollLeftButton:null,
			timeScrollLeftButtonFadeIn:300,
			timeScrollLeftButtonFadeOut:100,
			scrollRight:null,
			timeScrollRight:500,
			scrollRightButton:null,
			timeScrollRightButtonFadeIn:300,
			timeScrollRightButtonFadeOut:100
		};
		
		this.labels = {
			playDiashow:'Diashow starten',
			pauseDiashow:'Pause',
			closeLightgallery:'schlie\u00dfen',
			image:'Bild',
			imageOf:'von',
			scrollToLeft:'nach links scrollen',
			scrollToRight:'nach rechts scrollen'
		};
		
		document.addEvent('mousemove', function() {
			if(_self.timer != null) window.clearTimeout(_self.timer);
			_self.timer = window.setTimeout(function() {_self.hidePrevNextButtons();}, _self.fadeTime);
		});
		
		document.addEvent('keyup', function(event) {
			if(_self.elements.diashow != null) {
				switch(event.code) {
					case 32:
						_self.elements.diashow.fireEvent('click');
						break;
					case 37:
						_self.stopDiashowTimer();
						_self.showPrevImage();
						break;
					case 39:
						_self.stopDiashowTimer();
						_self.showNextImage();
						break;
					default:
						break;
				}
			}
		});
		
		window.addEvent('resize', function() {
			_self.resize();
		});
	},
	
	getImages: function(sID) {
		var _self = this;
		new Request.JSON({
			url:this.ajaxPath,
			onComplete: function(response) {
				if(response.images) {
					if(typeof dialog == 'object') dialog.show();
					_self.sID = sID;
					if(response.gallery.name) _self.options.name = response.gallery.name;
					if(response.gallery.directory) _self.options.directory = response.gallery.directory;
					if(response.gallery.description) _self.options.description = response.gallery.description;
					_self.setImages(response.images);
				} else _self.showError(0);
			}
		}).get({'sid':sID});
	},
	
	setImages: function(images) {
		for(var i = 0; i < images.length; i++) {
			var last = (i == images.length -1 ? true : false);
			this.images.push(new IMAGE(i, this.options, images[i], last));
		}
		
		this.show();
	},
	
	show: function() {
		var _self = this;
		var body = document.getElementsByTagName('body')[0];
		
		this.elements.lightgallery = new Element('div', {'id':this.options.lightgalleryID}).setStyles({'width':window.getWidth().toInt()});
		this.elements.controlPanelWrapper = new Element('div', {'id':this.options.controlPanelWrapperID});
		
		var wrapper = new Element('div').setStyles({'height':40, 'line-height':40, 'border-bottom':'1px solid #eeeeee'});
		// diashow-button
		this.elements.diashowWrapper = new Element('div', {'id':this.options.diashowWrapperID}).setStyles({'opacity':0});
		this.elements.diashow = new Element('img', {'alt':this.labels.playDiashow, 'src':this.options.imagePath + this.options.diashowButtonPlaySrc, 'title':this.labels.playDiashow}).setStyles({'cursor':'pointer', 'height':22, 'margin':'0px 5px -7px 0px', 'width':22});
		/*this.elements.diashow.addEvent('mouseover', function() {
			if(_self.fx.diashowWrapper != null) _self.fx.diashowWrapper.cancel();
			_self.fx.diashowWrapper = new Fx.Morph(_self.elements.diashowWrapper, {duration:_self.fx.timeDiashowWrapperFadeIn}).start({'opacity':1});
		});
		this.elements.diashow.addEvent('mouseout', function() {
			if(_self.fx.diashowWrapper != null) _self.fx.diashowWrapper.cancel();
			_self.fx.diashowWrapper = new Fx.Morph(_self.elements.diashowWrapper, {duration:_self.fx.timeDiashowWrapperFadeOut}).start({'opacity':0.4});
		});*/
		this.elements.diashow.addEvent('click', function() {
			if(_self.diashow) {
				_self.stopDiashowTimer();
			} else {
				_self.diashow = true;
				this.src = _self.imagePath + _self.options.diashowButtonPauseSrc;
				_self.elements.diashowLabel.set('html', _self.labels.pauseDiashow);
				_self.startDiashowTimer();
			}
		});
		this.elements.diashowLabel = new Element('span').setStyles({'cursor':'pointer'}).set('html', this.labels.playDiashow);
		this.elements.diashowLabel.addEvent('mouseover', function() {
			this.setStyles({'text-decoration':'underline'});
		});
		this.elements.diashowLabel.addEvent('mouseout', function() {
			this.setStyles({'text-decoration':'none'});
		});
		this.elements.diashowLabel.addEvent('click', function() {
			if(_self.diashow) {
				_self.stopDiashowTimer();
			} else {
				_self.diashow = true;
				_self.elements.diashow.src = _self.imagePath + _self.options.diashowButtonPauseSrc;
				_self.elements.diashowLabel.set('html', _self.labels.pauseDiashow);
				_self.startDiashowTimer();
			}
		});
		this.elements.diashowWrapper.grab(this.elements.diashow).grab(this.elements.diashowLabel);
		wrapper.grab(this.elements.diashowWrapper);
		
		// close-button
		this.elements.closeButtonWrapper = new Element('div', {'id':this.options.closeButtonWrapperID}).setStyles({'opacity':0});
		this.elements.closeButton = new Element('img', {'alt':this.labels.closeLightgallery, 'src':this.options.imagePath + this.options.closeButtonSrc, 'title':this.labels.closeLightgallery}).setStyles({'cursor':'pointer', 'height':22, 'margin':'0px 0px -7px 5px', 'width':22});
		/*this.elements.closeButton.addEvent('mouseover', function() {
			if(_self.fx.closeButtonWrapper != null) _self.fx.closeButtonWrapper.cancel();
			_self.fx.closeButtonWrapper = new Fx.Morph(_self.elements.closeButtonWrapper, {duration:_self.fx.timeCloseButtonWrapperFadeIn}).start({'opacity':1});
		});
		this.elements.closeButton.addEvent('mouseout', function() {
			if(_self.fx.closeButtonWrapper != null) _self.fx.closeButtonWrapper.cancel();
			_self.fx.closeButtonWrapper = new Fx.Morph(_self.elements.closeButtonWrapper, {duration:_self.fx.timeCloseButtonWrapperFadeOut}).start({'opacity':0.4});
		});*/
		this.elements.closeButton.addEvent('click', function() {
			new Fx.Morph(_self.elements.thumbnails, {duration:500}).start({'opacity':0});
			new Fx.Morph(_self.elements.controlPanelWrapper, {duration:500}).start({'opacity':0});
			new Fx.Morph(_self.elements.imageWrapper, {duration:500}).start({'opacity':0}).chain(function() {
				_self.elements.lightgallery.destroy();
				_self.initialize();
				if(typeof dialog == 'object') dialog.hide();
			});
		});
		this.elements.closeButtonLabel = new Element('span').setStyles({'cursor':'pointer'}).set('html', this.labels.closeLightgallery);
		this.elements.closeButtonLabel.addEvent('mouseover', function() {
			this.setStyles({'text-decoration':'underline'});
		});
		this.elements.closeButtonLabel.addEvent('mouseout', function() {
			this.setStyles({'text-decoration':'none'});
		});
		this.elements.closeButtonLabel.addEvent('click', function() {
			new Fx.Morph(_self.elements.thumbnails, {duration:500}).start({'opacity':0});
			new Fx.Morph(_self.elements.controlPanelWrapper, {duration:500}).start({'opacity':0});
			new Fx.Morph(_self.elements.imageWrapper, {duration:500}).start({'opacity':0}).chain(function() {
				_self.elements.lightgallery.destroy();
				_self.initialize();
				if(typeof dialog == 'object') dialog.hide();
			});
		});
		this.elements.closeButtonWrapper.grab(this.elements.closeButtonLabel).grab(this.elements.closeButton);
		wrapper.grab(this.elements.closeButtonWrapper);
		
		// gallery-information
		this.elements.galleryInformationWrapper = new Element('div', {'id':this.options.galleryInformationWrapperID}).setStyles({'opacity':0});
		this.elements.galleryInformationWrapper.set('html', this.labels.image + '&nbsp;<span id="' + this.options.imageIndexID + '"></span>&nbsp;' + this.labels.imageOf + '&nbsp;' + (this.images.length).toString().zerofill(3));
		wrapper.grab(this.elements.galleryInformationWrapper).grab(new Element('div', {'class':'clear'}));
		this.elements.controlPanelWrapper.grab(wrapper);
		
		// scroll-left-button
		this.elements.scrollLeftButtonWrapper = new Element('div', {'id':this.options.scrollLeftButtonWrapperID});
		this.elements.scrollLeftButton = new Element('img', {'alt':this.labels.scrollToLeft, 'id':this.options.scrollLeftButtonID, 'title':this.labels.scrollToLeft}).setStyles({'cursor':'pointer', 'height':60, 'margin-right':this.options.thumbnailMarginRight, 'margin-top':this.options.thumbnailBorder, 'opacity':0, 'width':25});
		this.elements.scrollLeftButton.addEvent('mouseover', function() {
			if(_self.fx.scrollLeftButton != null) _self.fx.scrollLeftButton.cancel();
			_self.fx.scrollLeftButton = new Fx.Morph(this, {duration:_self.fx.timeScrollLeftButtonFadeIn}).start({'opacity':1});
		});
		this.elements.scrollLeftButton.addEvent('mouseout', function() {
			if(_self.fx.scrollLeftButton != null) _self.fx.scrollLeftButton.cancel();
			_self.fx.scrollLeftButton = new Fx.Morph(this, {duration:_self.fx.timeScrollLeftButtonFadeIn}).start({'opacity':0.4});
		});
		this.elements.scrollLeftButton.addEvent('click', function() {
			_self.scrollToLeft();
		});
		this.elements.scrollLeftButton.addEvent('load', function() {
			if(_self.fx.scrollLeftButton != null) _self.fx.scrollLeftButton.cancel();
			_self.fx.scrollLeftButton = new Fx.Morph(this, {duration:_self.fx.timeScrollLeftButtonFadeIn}).start({'opacity':0.4});
		});
		this.elements.scrollLeftButton.src = this.options.scrollLeftButtonSrc;
		this.elements.scrollLeftButtonWrapper.grab(this.elements.scrollLeftButton);
		
		// scroll-right-button
		this.elements.scrollRightButtonWrapper = new Element('div', {'id':this.options.scrollRightButtonWrapperID}).setStyles({'margin-left':this.options.thumbnailMarginRight});
		this.elements.scrollRightButton = new Element('img', {'alt':this.labels.scrollToRight, 'id':this.options.scrollRightButtonID, 'title':this.labels.scrollToRight}).setStyles({'cursor':'pointer', 'height':60, 'margin-top':this.options.thumbnailBorder, 'opacity':0, 'width':25});
		this.elements.scrollRightButton.addEvent('mouseover', function() {
			if(_self.fx.scrollRightButton != null) _self.fx.scrollRightButton.cancel();
			_self.fx.scrollRightButton = new Fx.Morph(this, {duration:_self.fx.timeScrollRightButtonFadeIn}).start({'opacity':1});
		});
		this.elements.scrollRightButton.addEvent('mouseout', function() {
			if(_self.fx.scrollRightButton != null) _self.fx.scrollRightButton.cancel();
			_self.fx.scrollRightButton = new Fx.Morph(this, {duration:_self.fx.timeScrollRightButtonFadeIn}).start({'opacity':0.4});
		});
		this.elements.scrollRightButton.addEvent('click', function() {
			_self.scrollToRight();
		});
		this.elements.scrollRightButton.addEvent('load', function() {
			if(_self.fx.scrollRightButton != null) _self.fx.scrollRightButton.cancel();
			_self.fx.scrollRightButton = new Fx.Morph(this, {duration:_self.fx.timeScrollRightButtonFadeIn}).start({'opacity':0.4});
		});
		this.elements.scrollRightButton.src = this.options.scrollRightButtonSrc;
		this.elements.scrollRightButtonWrapper.grab(this.elements.scrollRightButton);
		
		// thumbnail-wrapper
		this.elements.thumbnailWrapper = new Element('div', {'id':this.options.thumbnailWrapperID}).setStyles({'height':this.options.thumbnailHeight + 2 * (this.options.thumbnailBorder + this.options.thumbnailMorphDown)});
		this.elements.thumbnails = new Element('div', {'id':this.options.thumbnailsID});
		this.elements.thumbnails.setStyles({
			'height':this.options.thumbnailHeight + 2 * this.options.thumbnailBorder + this.options.thumbnailMorphDown,
			'width':((this.options.thumbnailWidth + 2 * this.options.thumbnailBorder) * this.images.length) + (this.options.thumbnailMarginRight * (this.images.length - 1))
		});
		this.elements.thumbnailWrapper.grab(this.elements.thumbnails);
		
		this.elements.controlPanelWrapper.grab(this.elements.scrollLeftButtonWrapper).grab(this.elements.scrollRightButtonWrapper).grab(this.elements.thumbnailWrapper);
		this.elements.lightgallery.grab(this.elements.controlPanelWrapper);
		
		this.elements.imageWrapper = new Element('div', {'id':this.options.imageWrapperID}).setStyles({'top':this.elements.controlPanelWrapper.getHeight().toInt()});
		this.elements.lightgallery.grab(this.elements.imageWrapper);
		
		body.appendChild(this.elements.lightgallery);
		
		this.setDimensions();

		var images = new Array();
		for(var i = 0; i < this.images.length; i++) {
			images.push(this.images[i].filenameThumb);
			this.images[i].showThumbnailWrapper();
		}

		new Asset.images(images, {
			onProgress: function(counter, index) {
				_self.images[index].showThumbnail();
			},
			onComplete: function() {
				for(var i = 0; i < _self.images.length; i++) if(_self.images[i].options.isActive) _self.activeImage = i;
				
				if(_self.activeImage == 0) {
					_self.images[_self.activeImage].fx.thumbnailWrapper = new Fx.Morph(_self.images[_self.activeImage].elements.thumbnailWrapper, {duration:_self.images[_self.activeImage].fx.timeThumbnailWrapperFadeIn}).start({'border-color':'#eee', 'margin-top':_self.images[_self.activeImage].options.thumbnailMarginTop});
					_self.images[_self.activeImage].showImage();
				}
			}
		});
	},
	
	setDimensions: function() {
		if($(this.options.controlPanelWrapperID.toString()) && $(this.options.imageWrapperID.toString())) {
			this.elements.lightgallery.setStyles({'width':window.getWidth().toInt()});
			var totalHeight = window.getHeight();
			this.options.imageWrapperHeight = totalHeight - $(this.options.controlPanelWrapperID.toString()).getHeight();
			if(this.elements.imageWrapper != null) this.elements.imageWrapper.setStyle('height', this.options.imageWrapperHeight);
		}
	},
	
	setActiveImageInactive: function(indx) {
		this.activeImage = indx;
		if($(this.options.imageIndexID.toString())) {
			$(this.options.imageIndexID.toString()).set('html', (indx + 1).toString().zerofill(3));
			if($(this.options.diashowWrapperID.toString()).getStyle('opacity') == 0) new Fx.Morph(this.options.diashowWrapperID.toString(), {duration:500}).start({'opacity':1});
			if($(this.options.galleryInformationWrapperID.toString()).getStyle('opacity') == 0) new Fx.Morph(this.options.galleryInformationWrapperID.toString(), {duration:500}).start({'opacity':1});
			if($(this.options.closeButtonWrapperID.toString()).getStyle('opacity') == 0) new Fx.Morph(this.options.closeButtonWrapperID.toString(), {duration:500}).start({'opacity':1});
		}
		for(var i = 0; i < this.images.length; i++) if(this.images[i].options.isActive && this.images[i].indx != indx) this.images[i].hideImage();
	},
	
	scrollToLeft: function() {
		var left = this.elements.thumbnails.getStyle('left').toInt();
		var distance = this.options.scrollFactor * (this.options.thumbnailWidth + 2 * this.options.thumbnailBorder + this.options.thumbnailMarginRight);
		if(left + distance > 0) distance = Math.abs(left);
		
		if(this.fx.scrollLeft != null) this.fx.scrollLeft.cancel();
		this.fx.scrollLeft = new Fx.Morph(this.elements.thumbnails, {duration:this.fx.timeScrollLeft}).start({'left':left + distance});
	},
	
	scrollToRight: function() {
		var left = this.elements.thumbnails.getStyle('left').toInt();
		var distance = this.options.scrollFactor * (this.options.thumbnailWidth + 2 * this.options.thumbnailBorder + this.options.thumbnailMarginRight);
		var thumbnailsWidth = this.elements.thumbnails.getWidth();
		var thumbnailWrapperWidth = this.elements.thumbnailWrapper.getWidth();
		if(Math.abs(left) + distance + thumbnailWrapperWidth > thumbnailsWidth) distance = thumbnailsWidth - thumbnailWrapperWidth - Math.abs(left);
		if(thumbnailsWidth <= thumbnailWrapperWidth) distance = 0;
		
		if(this.fx.scrollRight != null) this.fx.scrollRight.cancel();
		this.fx.scrollRight = new Fx.Morph(this.elements.thumbnails, {duration:this.fx.timeScrollRight}).start({'left':left - distance});
	},
	
	showPrevImage: function() {
		var indx = this.activeImage - 1;
		if(indx < 0) indx = this.images.length - 1;
		
		this.checkPosition(indx);
		
		if(this.images[indx].fx.thumbnailWrapper != null) this.images[indx].fx.thumbnailWrapper.cancel();
		this.images[indx].fx.thumbnailWrapper = new Fx.Morph(this.images[indx].elements.thumbnailWrapper, {duration:this.images[indx].fx.timeThumbnailWrapperFadeIn}).start({'border-color':'#eee', 'margin-top':this.images[indx].options.thumbnailMarginTop});
		this.images[indx].showImage();
	},
	
	showNextImage: function() {
		var indx = this.activeImage + 1;
		if(indx >= this.images.length) indx = 0;
		
		this.checkPosition(indx);
		
		if(this.images[indx].fx.thumbnailWrapper != null) this.images[indx].fx.thumbnailWrapper.cancel();
		this.images[indx].fx.thumbnailWrapper = new Fx.Morph(this.images[indx].elements.thumbnailWrapper, {duration:this.images[indx].fx.timeThumbnailWrapperFadeIn}).start({'border-color':'#eee', 'margin-top':this.images[indx].options.thumbnailMarginTop});
		this.images[indx].showImage();
	},
	
	checkPosition: function(indx) {
		var left = this.elements.thumbnails.getStyle('left').toInt();
		var thumbnailWidth = this.options.thumbnailWidth + 2 * this.options.thumbnailBorder + this.options.thumbnailMarginRight;
		var thumbnailsWidth = this.elements.thumbnails.getWidth();
		var thumbnailWrapperWidth = this.elements.thumbnailWrapper.getWidth();
		var thumbnailLeft = indx * thumbnailWidth;
		var distance = this.options.scrollFactor * thumbnailWidth;
		
		if(thumbnailLeft - Math.abs(left) + this.options.thumbnailWidth + 2 * this.options.thumbnailBorder > thumbnailWrapperWidth) {
			// thumbnail is out of range (right side) - scroll right
			if(Math.abs(left) + distance + thumbnailWrapperWidth > thumbnailsWidth) distance = thumbnailsWidth - thumbnailWrapperWidth - Math.abs(left);
			if((indx + 1) * thumbnailWidth - Math.abs(left)- thumbnailWrapperWidth > distance) distance = (indx + 1) * thumbnailWidth - Math.abs(left) - thumbnailWrapperWidth;
			
			if(this.fx.scrollRight != null) this.fx.scrollRight.cancel();
			this.fx.scrollRight = new Fx.Morph(this.elements.thumbnails, {duration:this.fx.timeScrollRight}).start({'left':left - distance});
		} else if(Math.abs(left) > thumbnailLeft) {
			// thumbnail is out of range (left side) - scroll left
			if(left + distance > 0) distance = Math.abs(left);
			if(Math.abs(left) - thumbnailLeft > distance) distance = Math.abs(left) - thumbnailLeft;
			
			if(this.fx.scrollLeft != null) this.fx.scrollLeft.cancel();
			this.fx.scrollLeft = new Fx.Morph(this.elements.thumbnails, {duration:this.fx.timeScrollLeft}).start({'left':left + distance});
		}
	},
	
	hidePrevNextButtons: function() {
		if(typeof(this.images[this.activeImage]) == 'object') this.images[this.activeImage].hidePrevNextButtons();
	},
	
	startDiashowTimer: function() {
		var _self = this;

		if(this.diashow) {
			this.diashowTimer = (function() {
				_self.showNextDiashowImage();
			}).delay(this.diashowTime);
		}
	},
	
	stopDiashowTimer: function() {
		this.diashow = false;
		this.elements.diashow.src = this.imagePath + this.options.diashowButtonPlaySrc;
		this.elements.diashowLabel.set('html', this.labels.playDiashow);
		this.diashowTimer = $clear(this.diashowTimer);
	},
	
	showNextDiashowImage: function() {
		if(this.diashow) this.showNextImage();
	},
	
	resize: function() {
		this.diashowTimer = $clear(this.diashowTimer);
		
		if(this.elements.thumbnails != null && this.elements.thumbnailWrapper != null) {
			var _self = this;
			var left = this.elements.thumbnails.getStyle('left').toInt();
			var thumbnailsWidth = this.elements.thumbnails.getWidth();
			var thumbnailWrapperWidth = this.elements.thumbnailWrapper.getWidth();

			this.images[this.activeImage].fx.image = new Fx.Morph(this.images[this.activeImage].elements.image, {duration:100}).start({'opacity':0}).chain(function() {
				if(_self.images[_self.activeImage].subtitle != '') _self.images[_self.activeImage].elements.subtitleWrapper.setStyles({'opacity':0});
				_self.images[_self.activeImage].elements.prevButtonWrapper.setStyles({'display':'none'});
				_self.images[_self.activeImage].elements.nextButtonWrapper.setStyles({'display':'none'});
			});
			this.setDimensions();
			if((thumbnailsWidth - Math.abs(left) < thumbnailWrapperWidth) && (thumbnailsWidth >= thumbnailWrapperWidth)) this.elements.thumbnails.setStyles({'left':-(thumbnailsWidth - thumbnailWrapperWidth)});
			this.checkPosition(this.activeImage);
			for(var i = 0; i < this.images.length; i++) this.images[i].options.isImageLoaded = false;
			this.images[this.activeImage].showImage();
		}
	},
	
	showError: function(errorCode) {
		switch(errorCode) {
			case 0:
				console.log('Bad response. No Image-Object found.');
				break;
			default:
				console.log('Unknown error.');
				break;
		}
	},
	
	containsDOM: function(container, containee) {
		var isParent = false;
		do {
			if((isParent = container == containee)) break;
			containee = containee.parentNode;
		}
		while (containee != null);
		return isParent;
	},
	  
	checkMouseOut: function(element, evt) {
		if(element.contains && evt.toElement) {
			return !element.contains(evt.toElement);
		}
		else if (evt.relatedTarget) {
			return !this.containsDOM(element, evt.relatedTarget);
		}
	}
});

String.prototype.zerofill = function(len) {
	var str = this;
	while(str.length < len) str = '0' + str;
	return str.toString();
}