
var scrollDirection = 0;
var scrollPos = 1;
var scrollWidth;
var mySlide2;
var sliderWidth;
var actPhoto = 0;
var photoWidth;
var outerThumb;
var innerThumb;
var outerThumbWidth;
var outerThumbHeight;
var thumbListWidth;
var thumbListHeight;
var newPhoto;
var oldPhoto = 0;

window.addEvent('domready', function() {
	if ($('bm_gallery_thumbs_outer')) {
		outerThumb = $('bm_gallery_thumbs_outer');
		innerThumb = $('bm_gallery_thumbs_inner');
		outerThumbWidth = outerThumb.offsetWidth;
		outerThumbHeight = outerThumb.offsetHeight;
		thumbListWidth = innerThumb.offsetWidth;
		thumbListHeight = innerThumb.offsetHeight;
				
		if (slidedirection == 'vertical') {
			photoWidth = thumbListHeight / mediumPhotos.length;
			sliderWidth = document.getElementById('slider').offsetHeight;
			scrollWidth = thumbListHeight - outerThumbHeight + sliderWidth;
		}
		else {
			sliderWidth = document.getElementById('slider').offsetWidth;
			scrollWidth = thumbListWidth - outerThumbWidth + sliderWidth;
			photoWidth = thumbListWidth / mediumPhotos.length;
			
		}
		
		mySlide2 = new Slider($('slidebar'), $('slider'), {
			onChange: function(pos){
				if (slidedirection == 'vertical') 
					outerThumb.scrollTo(0, pos);
				else 
					outerThumb.scrollTo(pos, 0);
				scrollPos = pos;
			},
			steps: scrollWidth,
			mode: slidedirection
		});
		changePhoto(0);
	}
});


function changePhoto(number){
	newPhoto = 'medphoto_' + number;
	oldPhoto = 'medphoto_' + actPhoto;
	$(oldPhoto).setProperty('class','hide_photo');
	$(newPhoto).setProperty('class','show_photo');
	actPhoto = number;
	
	//document.getElementById('medium_view').src= mediumPhotos[number];
	//document.getElementById(('medphoto_' + number)).title = descriptions[number];
	//document.getElementById(('medphoto_' + number)).href = largePhotos[number];
	document.getElementById('bm_gallery_desc').innerHTML = descriptions[number];
	document.getElementById('bm_gallery_number').innerHTML = 'Bild ' + (number+1) + ' von ' + mediumPhotos.length;
	for(var i=0;i<mediumPhotos.length; i++){
		if(i == number){
			$('thumb_' + i).setProperty('class','thumb_active');
		}
		else{
			$('thumb_' + i).setProperty('class','thumb_normal');
		}
	}
	mySlide2.set(scrollWidth*number/(mediumPhotos.length-1));
	if(number == '0')
		document.getElementById('prevArrow').style.opacity = 0.5;
	else
		document.getElementById('prevArrow').style.opacity = 1;
	if(number == mediumPhotos.length-1)
		document.getElementById('nextArrow').style.opacity = 0.5;
	else
		document.getElementById('nextArrow').style.opacity = 1;
}

function nextPhoto(){
	if(actPhoto < mediumPhotos.length-1){
		changePhoto(actPhoto+1);
	}
}

function prevPhoto(){
	if(actPhoto > 0){
		changePhoto(actPhoto-1);
	}
}