var speed_ms = 10;
var speed_px = 10;
var width_min = 111;
var height_min = 82;
var width_max = 208;
var height_max = 157;
var padding_top = 0;
var padding_left = 0;
var vertical = 1;
var zoom_mode = 2;

var img = new Array();
var i;
var first = -1;
var last = -1;

function nameByWidth(name, width)
{
	if (!(slash = name.lastIndexOf("/") + 1)) return name;
	dir = name.substr(0, slash);
	file = name.substr(slash);
	if (!(under = file.lastIndexOf("_") + 1)) return name;
	fname = file.substr(0, under);
    lname = file.substr(under);
    s = lname.split(".");
    if (width == 'min') suf = 'st';
    if (width == 'max') suf = 'lt';
	return dir + fname + suf + '.' + s[s.length - 1];
}

var image_change = function (image_i) {
	var image = img[image_i];
	var width = parseInt(image.style.width) + image.speed;
	var height = parseInt(image.style.height) + image.speed;
	var top = parseInt(image.style.top) + image.top;
	var left = parseInt(image.style.left) + image.left;
	if (width < width_min || height < height_min) {
		image.setAttribute('src', nameByWidth(image.src, 'min'));
		image.parentNode.style.position = 'static';
		image.style.position = 'static';
		image.style.width = width_min + 'px';
        image.style.height = height_min + 'px';
		clearInterval(image.interval);
	} else if (width > width_max || height > height_max) {
		image.style.width = width_max + 'px';
        image.style.height = height_max + 'px';
        clearInterval(image.interval);
	} else {
		image.style.width = width + 'px';
		image.style.height = height + 'px';
		image.style.top = top + 'px';
		image.style.left = left + 'px';
	}
}
function imageZoom() {
	img = document.getElementsByTagName('img');
	for (i = 0; i < img.length; i++) {
		if (img[i].name == 'zoom') {
			if (zoom_mode == 1) {
				if (first == -1 && img[i].offsetTop < width_max/2 + 10) first = i;
				else if (img[i].offsetTop + (width_min + width_max)/2 > document.height) last = i;
			}
			img[i].style.width = width_min + 'px';
			img[i].style.height = height_min + 'px';
			img[i].parentNode.style.top = 0 + 'px';
			img[i].parentNode.style.left = 0 + 'px';
			img[i].style.top = padding_top + 'px';
			img[i].style.left = padding_left + 'px';
			img[i].xi = i;
			//big = new Image();
			//big.src = nameByWidth(img[i].src, width_max);
			img[i].onmouseover = function () {
				this.speed = speed_px;
				this.style.zIndex = 10;
				
				this.parentNode.style.position = 'relative';
				this.style.position = 'absolute';
				if (this.xi == first || zoom_mode == 2) this.top = 0;
				else if (this.xi == last) this.top = -speed_px;
				else this.top = -Math.round(speed_px/2);

				if (zoom_mode == 1 || zoom_mode == 2) this.left = 0;
				else this.left = -Math.round(speed_px/2);

				if (this.interval) clearInterval(this.interval);
				this.src = nameByWidth(this.src, 'max');
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
			img[i].onmouseout = function () {
				this.speed = -speed_px;
				this.style.zIndex = 1;
				
				if (this.xi == first || zoom_mode == 2) this.top = 0;
				else if (this.xi == last) this.top = speed_px;
				else this.top = Math.round(speed_px/2);

				if (zoom_mode == 1 || zoom_mode == 2) this.left = 0;
				else this.left = Math.round(speed_px/2);
				
				if (this.interval) clearInterval(this.interval);
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
		}
	}
}

