function setPictures(){
	document.getElementById('current_picture').value = position;
	document.getElementById('one_pic').src = pic_folder + pictures[position];
	resizeImage(pictures[position], position);
	if (/*thumb == 1 && */pictures.length > 1){
		document.getElementById('counter').innerHTML = "1 of "+pictures.length;
	}
}

function getWidthAndHeight(){
	if (this.width > window_width || thumb == 1 && this.width > thumb_width){
		if (thumb == 1){
			w = thumb_width;
			h = parseInt(thumb_width/this.width*this.height)
		}else{
			w = window_width;
			h = parseInt(window_width/this.width*this.height)
		}
	}else{
		w = this.width;
		h = this.height
	}
	document.getElementById('one_pic').width = w;
	document.getElementById('one_pic').height = h;
	return true;
}

function move(param){
	var position = parseInt(document.getElementById('current_picture').value);
	if (param == 'next'){
		position = position + 1;
	}else{
		position = position - 1;
	}
	document.getElementById('current_picture').value = position;
	document.getElementById('one_pic').src = pic_folder + pictures[position];
	resizeImage(pictures[position], position);
	var position_visible = position +1;
	document.getElementById('counter').innerHTML = position_visible+" of "+pictures.length;
	if (thumb == 1){
		var src = document.getElementById('picture_link').href;
		src = src.substring(0, src.length-1) + position;
		document.getElementById('picture_link').href = src;
	}
}

function checkLinks(position){
	if ((position+1) == pictures.length){
		document.getElementById('next').style.visibility = 'hidden';
	}else{
		document.getElementById('next').style.visibility = 'visible';
	}
	if (position == 0){
		document.getElementById('prev').style.visibility = 'hidden';
	}else{
		document.getElementById('prev').style.visibility = 'visible';
	}
}

function resizeImage(name, position) {
	var myImage = new Image();
	myImage.name = pic_folder + name;
	myImage.onload = getWidthAndHeight;
	myImage.src = pic_folder + name;
	myImage.onload();
	checkLinks(position);
}

