function gallery(images){
	var gallTR = false;
	var gall = document.getElementById("gallery-thumbs");
	var wa = document.getElementById("gallery-workarea");
	gall.gallCaption = document.getElementById("gallery-caption");
	gall.maxInLine = 7;
	gall.leftIndex = 0;
	gall.imageIndex = 0;
	while (gall.childNodes.length){
		gall.removeChild(gall.childNodes[0]);
	};
	gall.gallCells = new Array();
	if(typeof(images)=="undefined") return;
	for(var i in images){
		if(typeof(images[i])=="undefined") continue;
		if(typeof(images[i].big)=="undefined") continue;
		if(typeof(images[i].thumb)=="undefined") {
			images[i].thumb = images[i].big;
		};
		if(typeof(images[i].caption)=="undefined"){
			images[i].caption = "";
		};
		
		if (!gallTR){
			var gallTB = document.createElement("tbody");
			var gallTR = document.createElement("tr");
			var gallTH = document.createElement("th");
			var leftButton = document.createElement("a");
			leftButton.href = "#";
			leftButton.id = "gallery-left";
			leftButton.onclick = function () {
				gallerySetAct("prev");
				return false;
			};
			gallTH.appendChild(leftButton);
			gallTR.appendChild(gallTH);
			gallTB.appendChild(gallTR);
			gall.appendChild(gallTB);
		};
		
		var cell = document.createElement("td");
		var thumb = document.createElement("img");
		thumb.src = images[i].thumb;
		thumb.onmouseover = function () {
			gallerySetAct(this);
		};
		var big = document.createElement("img");
		big.src = images[i].big;
		wa.appendChild(big);
		cell.appendChild(thumb);
		cell.thumb = thumb;
		cell.big = big;
		cell.caption = images[i].caption;
		if (gall.gallCells.length >= gall.maxInLine) {
			cell.style.display = "none";
		};
		gallTR.appendChild(cell);
		gall.gallCells.push(cell);
	};
	if (gallTR){
		var gallTH = document.createElement("th");
		var rightButton = document.createElement("a");
		rightButton.href = "#";
		rightButton.id = "gallery-right";
		rightButton.onclick = function () {
			gallerySetAct("next");
			return false;
		};
		gallTH.appendChild(rightButton);
		gallTR.appendChild(gallTH);
		gallerySetAct(0);
	};
};
function gallerySetAct(param){
	var gall = document.getElementById("gallery-thumbs");
	var wa = document.getElementById("gallery-workarea");
	switch (typeof(param)){
		case "undefined":
			return;
		case "string":
			switch (param){
				case "next":
					if (gall.imageIndex < gall.gallCells.length - 1 ) {
						param = gall.imageIndex + 1;
					} else {
						return;
					};
				break;
				case "prev":
					if (gall.imageIndex > 0) {
						param = gall.imageIndex - 1;
					} else {
						return;
					};
				break;
			};
		case "number":
			param = gall.gallCells[param].thumb;
		case "object":
			for (var i=0; i<gall.gallCells.length; i++){
				if (gall.gallCells[i].thumb != param){
					gall.gallCells[i].thumb.className = "";
					gall.gallCells[i].big.className = "";
				} else {
					gall.gallCells[i].thumb.className = "gallery-active";
					gall.gallCells[i].big.className = "gallery-big-active";
					gall.gallCaption.innerHTML = gall.gallCells[i].caption;
					gall.imageIndex = i;
				};
			};
			if (gall.imageIndex<gall.leftIndex || gall.imageIndex >= gall.leftIndex + gall.maxInLine){
				gall.leftIndex = (gall.imageIndex<gall.leftIndex)?gall.imageIndex:(gall.imageIndex - gall.maxInLine + 1);
				for (var i=0; i<gall.gallCells.length; i++){
					gall.gallCells[i].style.display = (i>=gall.leftIndex && i<gall.leftIndex + gall.maxInLine)?"":"none";
				};
			};
			break;
		default:
	};
};
