
var $curPos = 1;
var $oldPos = 1;

function goTo(id) {
    if (document.images && id != $oldPos) {
		setLoading(true);
		var newImg = document.images[IMG_ID_PREFIX + id];
		var oldImg = document.images[IMG_ID_PREFIX + $oldPos];
		var itemImg = document.images[IMG_WORKS_ITEM_ID];
		newImg.src = IMG_MENU_PATH_WEB + id + IMG_MENU_SELECTED + IMG_MENU_FILE_EXT;
		oldImg.src = IMG_MENU_PATH_WEB + $oldPos + IMG_MENU_NORMAL + IMG_MENU_FILE_EXT;
//		try {itemImg.filters['blendTrans'].apply()} catch(e) {}
		itemImg.src = IMG_WORKS_PATH_WEB + IMG_WORKS_PREFIX + gWorkId + IMG_WORKS_POSTFIX + id + IMG_WORKS_FILE_EXT;
//		try {itemImg.filters['blendTrans'].play()} catch(e) {}
		$imagesNormal[id].src = newImg.src;
		$imagesNormal[$oldPos].src = oldImg.src;
		$oldPos = $curPos = id;
    }
	return false;
}

function prev() {
	if ($curPos > 1)
		goTo(--$curPos);
	return false;
}

function next() {
	if ($curPos < IMG_WORKS_MAX_QTY)
		goTo(++$curPos);
	return false;
}

var win;

function showImage() {
	win = window.open('image.php?id=' + gWorkId + '&pos=' + $curPos + '&lang=' + LANG, 'image', 'width=800,height=600,address=0,toolbar=0,statusbar=0');
	win.focus();
	return false;
}

function setLoading(loading) {
	if (!document.getElementById) return;
	if (loading == null) loading = true;
	$('loader').style.display = loading ? 'block' : 'none';
}

function  init() {
	var switches = document.getElementsByClassName('pos');
	for (var i = 0, n = switches.length; i < n; i++) {
		switches[i].onclick = new Function('return goTo(' + (i + 1) + ')');
		switches[i].onmouseover = new Function('over(' + (i + 1) + ')');
		switches[i].onmouseout = new Function('out(' + (i + 1) + ')');
	}
}

if (window.attachEvent) {
	window.attachEvent('onload', init);
} else if (window.addEventListener) {
	window.addEventListener('load', init, false);
}

