function ImageGallery(_iso1, _smallGallery, _bigGallery){
	var
		gallery = _smallGallery;
	var
		iso1 = _iso1;
	var
		gallery_big = _bigGallery;
	var 
		galleryIndex=0;
	var
		bigActive = false;
	var
		expandNavigation;
	var
		showNavigation = false;
	// public functions
	this.setImage = setImage;
	this.previousImage = previousImage;
	this.nextImage = nextImage;
	this.toggleImageSize = toggleImageSize;
	this.imageIconMouseEvent = imageIconMouseEvent;
	this.startSlideShow = startSlideShow;
	this.preloadImage = preloadImage;
	this.setShowNavigation = setShowNavigation;
	
	function setShowNavigation(_state){
		if (showNavigation != _state){
			showNavigation = _state;
			setVisibilityById('image_gallery_navi_control', showNavigation);
			
			// reset index
			setImage(galleryIndex);
		}		
	}
	
	function slideNextImage(){
		nextImage();
	}
	function startSlideShow(_interval){
		if (!_interval)
			return;
		document.slideNextImage = slideNextImage;
		window.setInterval("document.slideNextImage()", _interval);
	}
	
	function getIndexByGroup(gallery, groupid){
		var
			index = -1;
		
		for (i=0; i < gallery.length; i++){
			if (gallery[i].groupid == groupid){
				index = i;
				break;
			}
		}
			
		return index;
	}
	
	function calcImageGalleryOffset(_index){
		if (bigActive){
			if (_index < 0)
				_index += gallery_big.length;
			return _index%gallery_big.length;
		}else{
			if (_index < 0)
				_index += gallery.length;
			return _index%gallery.length;
		}
	}	
	function setImage(_index){
		galleryIndex = calcImageGalleryOffset(_index);
		
		if (bigActive){
			debug('show_big url:'+gallery_big[galleryIndex].target.uri);
		
			document.getElementById('gallery_image_big').src = gallery_big[galleryIndex].target.uri;
			// preload previous and next image
			preloadImage(gallery_big[calcImageGalleryOffset(galleryIndex+1)].target);
			preloadImage(gallery_big[calcImageGalleryOffset(galleryIndex-1)].target);
			// preload small image
			/*preloadImage(gallery[getIndexByGroup(gallery, gallery_big[galleryIndex].groupid)].target);*/
		}
		else{
			document.getElementById('gallery_image_small').src = gallery[galleryIndex].target.uri;
			// preload previous and next image
			preloadImage(gallery[calcImageGalleryOffset(galleryIndex+1)].target);
			preloadImage(gallery[calcImageGalleryOffset(galleryIndex-1)].target);
			
			if (!gallery_big || getIndexByGroup(gallery_big, gallery[galleryIndex].groupid) == -1)
				setExpandNavigation(0);
			else{
				setExpandNavigation(1);
				// preload big image
				preloadImage(gallery_big[getIndexByGroup(gallery_big, gallery[galleryIndex].groupid)].target);				
			}
		}
		
		updateAltText();
	}
	
	function previousImage(){
		setImage(galleryIndex-1);		
	}
	
	function nextImage(){
		setImage(galleryIndex+1);
	}
			
	function toggleImageSize(){
		if (!bigActive){
			bigActive = true;
			hideElementById('content_unten');
			hideElementById('menu2und3');
			// find the index of the given group
			setImage(getIndexByGroup(gallery_big, gallery[galleryIndex].groupid));
			showElementById('gallery_div_big');
			hideElementById('gallery_div_small');
			setExpandNavigation(2);
		}else{
			bigActive = false;
			showElementById('content_unten');
			showElementById('menu2und3');
			// find the index of the given group
			setImage(getIndexByGroup(gallery, gallery_big[galleryIndex].groupid));
			showElementById('gallery_div_small');	
			hideElementById('gallery_div_big');		
		}
		
		if (this.toggleCallback)
			this.toggleCallback(bigActive);
	}	
	
	function imageIconMouseEvent(num, over){
		if (num == 0){
			// previous
			var img = document.getElementById('previous_image');
			if (!over)
				img.src = '/icons/bg_mitte_bildnavi_prev.gif';
			else
				img.src = '/icons/bg_mitte_bildnavi_prev_over.gif';
		}else
		if (num == 1){
			// next
			var img = document.getElementById('next_image');
			if (!over)
				img.src = '/icons/bg_mitte_bildnavi_next.gif';
			else
				img.src = '/icons/bg_mitte_bildnavi_next_over.gif';
		}else{
			var img = document.getElementById('minimize_image');
			// minimize maximize
			if (expandNavigation == 1){
				// expand
				if (!over)
					img.src = '/icons/bg_mitte_bildnavi_expand.gif';
				else
					img.src = '/icons/bg_mitte_bildnavi_expand_over.gif';				
			}else
			if (expandNavigation == 2){
				// minimize
				if (!over)
					img.src = '/icons/bg_mitte_bildnavi_minimize.gif';
				else
					img.src = '/icons/bg_mitte_bildnavi_minimize_over.gif';				
			}
		}		
	}
	
	function setExpandNavigation(nav){
		expandNavigation = nav;
		var img = document.getElementById('minimize_image');
		if (img){
			if (nav == 0){
				// hidden
				//img.style.visibility = 'hidden';
			}else
			if (nav == 1){
				// expand
				img.src = '/icons/bg_mitte_bildnavi_expand.gif';
				//img.style.visibility = 'visible';
			}else{
				// minimize
				img.src = '/icons/bg_mitte_bildnavi_minimize.gif';
				//img.style.visibility = 'visible';
			}
			
			setDisplayBlockOrNoneById('minimize_image', nav != 0);
		}
		
		var
			lrNav = showNavigation && gallery.length >1;
		
		setDisplayBlockOrNoneById('previous_image', lrNav);
		setDisplayBlockOrNoneById('next_image', lrNav);
		
	}
	
	function updateAltText(){
		if (!bigActive && gallery[galleryIndex].alttext && gallery[galleryIndex].alttext[iso1]){
			var
				width = 640-2;
			var
				gap = 0;
				
			if(showNavigation && gallery.length >1)
				gap += 2*18;
			if (expandNavigation != 0)
				gap += 18;
			setContent('image_gallery_navi_text', gallery[galleryIndex].alttext[iso1]);
			setElementPositionById('image_gallery_navi_title', gap, null, width-gap, null);
			setElementPositionById('image_gallery_navi_text', gap, null, width-gap-5, null);
			showElementById('image_gallery_navi_text');
			showElementById('image_gallery_navi_title');
		}else{
			hideElementById('image_gallery_navi_text');
			hideElementById('image_gallery_navi_title');
		}
	}
}