function $(varr) {
	return document.getElementById(varr);
}
var fotogallerij = {
	pic : false,
	pics : new Array(),
	emptypic : 'empty.gif',
	pic_groot_w : 500,
	pic_groot_h : 300,
	init : function(bar_w,bar_h,groot_w,groot_h,arr) {
		this.pic = false;
		this.pics = Array();
		if ($('pic_groot')) {
			this.pic_groot_w = groot_w;
			this.pic_groot_h = groot_h;
			$('pic_bar').className = 'pic_bar';
			$('pic_bar').style.width = ((bar_w*3)+12);
			$('pic_groot').style.width = this.pic_groot_w;
			$('pic_groot').style.height = this.pic_groot_h;
			teller = 0;
			for (i=0; i<arr.length; i++){
				this.pics[teller] = arr[i];
				teller++;
			}
			this.getBar(bar_w,bar_h,false,0);
		}
		if (this.pic == false) {
			this.getPic(0);
		}
	},
	getPic : function(id) {
		this.innerDiv('pic_groot','');
		var newIMG = document.createElement('IMG');
		newIMG.setAttribute('src',this.pics[id]); 
		this.pic = id;
		$('pic_groot').appendChild(newIMG);
		
		pic_width = this.pic_groot_w;
		pic_height = this.pic_groot_h;
		percentage_width = (newIMG.offsetWidth / pic_width);
		percentage_height = (newIMG.offsetHeight / pic_height);
		
		if (percentage_width >= percentage_height) {
			if (pic_width > newIMG.offsetWidth && pic_height > newIMG.offsetHeight) {
				pic_width = newIMG.offsetWidth;
				pic_height = newIMG.offsetHeight;
			} else {
				pic_height = newIMG.offsetHeight*pic_width/newIMG.offsetWidth;
			}
		} else {
			if (pic_width > newIMG.offsetWidth && pic_height > newIMG.offsetHeight) {
				pic_height = newIMG.offsetHeight;
				pic_width = newIMG.offsetWidth;
			} else {
				pic_width = newIMG.offsetWidth*pic_height/newIMG.offsetHeight;
			}
		}
		this.innerDiv('pic_groot','');
		newIMG.setAttribute('width',pic_width);
		newIMG.setAttribute('height',pic_height);
		$('pic_groot').appendChild(newIMG);
	}, 
	getBar : function(w,h,onlyScroll,scrollStart) {
		this.innerDiv('pic_bar','');
		
		if (onlyScroll == false) {
			if (this.pic == 0) { 
				//picstart = -1;
				picstart = 0;
			} else {
				picstart = this.pic - 1;
			}
		} else {
			picstart = scrollStart;
		}
		if (picstart < 0) { 
			picstart = 0; 
		}
		picend = picstart + 2;
		//alert(picend + '-'  + this.pics.length);
		if (picend >= this.pics.length && picstart != 0) {
			picstart = picstart -1;
		}
		/*if (picstart == -1) {
			up = document.createElement('P');
			up.appendChild(this.makePic(this.emptypic,w,h,i));
			$('pic_bar').appendChild(up);
		}*/
		for (i=0; i<this.pics.length; i++){
			if (i >= picstart && i <= picend) {
				p = this.makePic(this.pics[i],w,h,i);
				p.onclick = function() {
					fotogallerij.getPic(this.name);
					fotogallerij.getBar(this.width,this.height,false,0);
				}
				if (i == this.pic) {
					p.style.cssText = 'border:2px dotted #fff;';
				} else {
					p.style.cssText = 'border:2px solid #014B8C;';
				}
				/*up = document.createElement('P');
				up.appendChild(p);
				$('pic_bar').appendChild(up);*/
				$('pic_bar').appendChild(p);
			}
		}
		/*if (i <= picend) {
			up = document.createElement('P');
			up.appendChild(this.makePic(this.emptypic,w,h,i));
			$('pic_bar').appendChild(up);
		}*/
		//if (picstart != -1 || i > picend) {
		if (picstart != 0 || i > (picend + 1)) {
			br = document.createElement('br');
			$('pic_bar').appendChild(br);
			br = document.createElement('br');
			$('pic_bar').appendChild(br);
		}
		//if (picstart != -1) {
		if (picstart != 0) {
			var newLINK = document.createElement('A');
			newLINK.setAttribute('href','#');
			newLINK.setAttribute('name','links');
			newLINK.style.cssText = 'float:left;border:0;';
			newLINK.onclick = function() {
				fotogallerij.getBar(w,h,true,picstart-1);
				return false;
			}
			//doc = document.createTextNode('prev');
			doc = this.makePic('img/button_prev.jpg',119,20,'prev');
			doc.setAttribute('border',0);
			doc.style.cssText = 'padding:0;margin:0;';
			newLINK.appendChild(doc);
			$('pic_bar').appendChild(newLINK);
		}
		//if (i > picend) {
		//if (i > picend+1) {
			var newLINK = document.createElement('A');
			newLINK.setAttribute('href','#');
			newLINK.setAttribute('name','links');
			newLINK.style.cssText = 'float:right;border:0;';
			newLINK.onclick = function() {
				fotogallerij.getBar(w,h,true,picstart+1);
				return false;
			}
			//doc = document.createTextNode('next');
			doc = this.makePic('img/button_next.jpg',118,20,'next');
			doc.setAttribute('border',0);
			doc.style.cssText = 'padding:0;margin:0;';
			newLINK.appendChild(doc);
			$('pic_bar').appendChild(newLINK);
		//}
	},
	makePic : function(src,width,height,name) {
		var newIMG = document.createElement('IMG');
		newIMG.setAttribute('src',src);
		newIMG.setAttribute('width',width); 
		newIMG.setAttribute('height',height); 
		newIMG.setAttribute('name',name);
		newIMG.setAttribute('border','0');
		return newIMG;
	}, 
	innerDiv : function(name,value) {
		if ($(name).htmlContent) {
			$(name).htmlContent = value;
		} else {
			$(name).innerHTML = value;
		}
	}
}
