images_id = new Array();
images_titles = new Array();
images_width = new Array();
images_height = new Array();
images_names = new Array();

if (!Array.prototype.indexOf)
	Array.prototype.indexOf = function(searchElement, fromIndex){
		for(var i = fromIndex||0, length = this.length; i<length; i++)
			if(this[i] === searchElement) return i;
		return -1;
	};

function get_image_prev(id) {
	var prevID = -1;
	
	var cur_ind = images_id.indexOf(id);
	
	if (cur_ind > 0)
		prevID = images_id[cur_ind - 1];
	
	return prevID;
}

function get_image_next(id) {
	var nextID = -1;
	
	var cur_ind = images_id.indexOf(id);


	if (cur_ind < images_id.length - 1)
		nextID = images_id[cur_ind + 1];

	return nextID;
}

function image_show(id) {
	var block = document.getElementById('image_big');
	var img = document.getElementById('image_big_in');
	
	img.style.display = 'none';
	
	if (detectIE6()) {
		document.getElementById('img_prev').style.display = 'none';
		document.getElementById('img_next').style.display = 'none';
		
		block.style.width = '300px';
		block.style.height = '100px';
	
		document.getElementById('image_big_load').style.display = 'none';
		document.getElementById('image_big_title').innerHTML = 'Ваш браузер больше не поддерживается.';
	}
	else {
		document.getElementById('image_big_load').style.display = 'table';
		document.getElementById('image_big_title').innerHTML = images_titles[id];
		img.src = '/showobject.php?id=' + id + '&size=1';
	
		block.style.width = images_width[id] + 64 + 'px';
		block.style.height = images_height[id] + 72 + 'px';
	
		var prev = get_image_prev(id);
		var next = get_image_next(id);
	
		if (prev!=-1) {
			document.getElementById('img_prev').style.display = 'block';
			document.getElementById('img_prev').onclick = function() { image_show_new(prev); };
		}
		else {
			document.getElementById('img_prev').style.display = 'none';
		}
	
		if (next!=-1) {
			document.getElementById('img_next').style.display = 'block';
			document.getElementById('img_next').onclick = function() { image_show_new(next); };
		}
		else {
			document.getElementById('img_next').style.display = 'none';
		}
		
		img.onload = function() {img.style.display = 'block';};
	}
	
	block.style.display = 'block';
	
	var winH = (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
	var winT = (document.body.scrollTop == 0)?document.documentElement.scrollTop:document.body.scrollTop;
	block.style.top = Math.max(winT + (winH - block.offsetHeight) / 2, 0) + 'px';
	block.style.marginLeft = - block.offsetWidth / 2 + 'px';
}

function image_show_new(id) {
	var block = document.getElementById('image_big');
	var img = document.getElementById('image_big_in');
	
	img.style.display = 'none';
	
	if (detectIE6()) {
		document.getElementById('img_prev').style.display = 'none';
		document.getElementById('img_next').style.display = 'none';
		
		block.style.width = '300px';
		block.style.height = '100px';
	
		document.getElementById('image_big_load').style.display = 'none';
		document.getElementById('image_big_title').innerHTML = 'Ваш браузер больше не поддерживается.';
	}
	else {
		document.getElementById('image_big_load').style.display = 'table';
		document.getElementById('image_big_title').innerHTML = images_titles[id];
		img.src = '/images/up/' + images_names[id];
	
		block.style.width = images_width[id] + 64 + 'px';
		block.style.height = images_height[id] + 72 + 'px';
	
		var prev = get_image_prev(id);
		var next = get_image_next(id);
	
		if (prev!=-1) {
			document.getElementById('img_prev').style.display = 'block';
			document.getElementById('img_prev').onclick = function() { image_show_new(prev); };
		}
		else {
			document.getElementById('img_prev').style.display = 'none';
		}
	
		if (next!=-1) {
			document.getElementById('img_next').style.display = 'block';
			document.getElementById('img_next').onclick = function() { image_show_new(next); };
		}
		else {
			document.getElementById('img_next').style.display = 'none';
		}
		
		img.onload = function() {img.style.display = 'block';};
	}
	
	block.style.display = 'block';
	
	var winH = (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
	var winT = (document.body.scrollTop == 0)?document.documentElement.scrollTop:document.body.scrollTop;
	block.style.top = Math.max(winT + (winH - block.offsetHeight) / 2, 0) + 'px';
	block.style.marginLeft = - block.offsetWidth / 2 + 'px';
}

// Функция для показа одиночной картинки (чтоб не было смешения одиночной и серии картинок на одной страницы)
function image_show_single(id, title, imgW, imgH) {
	var block = document.getElementById('image_big');
	var img = document.getElementById('image_big_in');
	
	img.style.display = 'none';
	document.getElementById('img_prev').style.display = 'none';
	document.getElementById('img_next').style.display = 'none';
	
	if (detectIE6()) {
		block.style.width = '300px';
		block.style.height = '100px';
	
		document.getElementById('image_big_load').style.display = 'none';
		document.getElementById('image_big_title').innerHTML = 'Ваш браузер больше не поддерживается.';
	}
	else {
		document.getElementById('image_big_load').style.display = 'table';
		document.getElementById('image_big_title').innerHTML = title;
		img.src = '/showobject.php?id=' + id + '&size=1';
	
		block.style.width = imgW + 64 + 'px';
		block.style.height = imgH + 62 + 'px';
	
		img.onload = function() {img.style.display = 'block';};
	}
	
	block.style.display = 'block';
	
	var winH = (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
	var winT = (document.body.scrollTop == 0)?document.documentElement.scrollTop:document.body.scrollTop;
	block.style.top = Math.max(winT + (winH - block.offsetHeight) / 2, 0) + 'px';
	block.style.marginLeft = - block.offsetWidth / 2 + 'px';
}

function image_show_single_new(name, title, imgW, imgH) {
	var block = document.getElementById('image_big');
	var img = document.getElementById('image_big_in');
	
	img.style.display = 'none';
	document.getElementById('img_prev').style.display = 'none';
	document.getElementById('img_next').style.display = 'none';
	
	if (detectIE6()) {
		block.style.width = '300px';
		block.style.height = '100px';
	
		document.getElementById('image_big_load').style.display = 'none';
		document.getElementById('image_big_title').innerHTML = 'Ваш браузер больше не поддерживается.';
	}
	else {
		document.getElementById('image_big_load').style.display = 'table';
		document.getElementById('image_big_title').innerHTML = title;
		img.src = '/images/up/' + name;
	
		block.style.width = imgW + 64 + 'px';
		block.style.height = imgH + 62 + 'px';
	
		img.onload = function() {img.style.display = 'block';};
	}
	
	block.style.display = 'block';
	
	var winH = (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
	var winT = (document.body.scrollTop == 0)?document.documentElement.scrollTop:document.body.scrollTop;
	block.style.top = Math.max(winT + (winH - block.offsetHeight) / 2, 0) + 'px';
	block.style.marginLeft = - block.offsetWidth / 2 + 'px';
}

function image_hide() {
	var block = document.getElementById('image_big');
	
	if (block.style.display == 'block') {
		document.getElementById('image_big_in').src = '';
		document.getElementById('image_big_title').innerHTML = '';
		document.getElementById('img_prev').style.display = 'none';
		document.getElementById('img_next').style.display = 'none';
		block.style.display = 'none';
	}
}

function detectIE6() {
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		var b_version = navigator.appVersion;
		var re = /\MSIE\s+(\d\.\d\b)/;
		var res = b_version.match(re);
		if (res[1] <= 6){
			return true;
		}
	}
	return false;
}

//function image_preload(imgs) {
//    imgs_pre = new Array();
//    for(i=0; i<imgs.length; i++) {
//        imgs_pre[i] = new Image();
//		imgs_pre[i].src = '/showobject.php?id=' + imgs[i] + '&size=1';
//    } 
//}
//
//window.onload = function() { image_preload(images_id); };