var currentLocation = "";
var wndChild = null;
var NN4 = document.layers;
var IE4 = document.all;
var NN6 = document.getElementById && !IE4;

function GetCellPos(cell)
{
    return {x:cell.cellIndex, y:cell.parentNode.rowIndex};         
}

function OnImageClick(oThis)
{
	width = 650;
	height = 500;

	var position = "";
	if (NN4 || IE4 || NN6)
	{
		posX = Math.round((screen.width - width) / 2);
		posY = Math.round((screen.height - height) / 2);
		position = (NN4 || NN6) ? ",screenX=" + posX + ",screenY=" + posY : ",left=" + posX + ",top=" + posY;
	}

	var oImg = oThis.getElementsByTagName("img");

    var href = currentLocation.replace('?view', '') + "view/?img=" + oThis.href + "&border=" + oImg[0].border;

    var oCollection = document.getElementById('collection');
	if (oCollection)
	{
		var oTitle = null, oSize = null;
		if (oThis.parentNode.tagName == "TD" && oThis.parentNode.rowSpan > 1)
		{
			for (var i = 0; i < oThis.parentNode.childNodes.length; i++)
			{
				if (oThis.parentNode.childNodes[i].tagName == "DIV")
				{
					switch (oThis.parentNode.childNodes[i].className)
					{
						case "title":
							oTitle = oThis.parentNode.childNodes[i];
							break;
						case "size":
							oSize = oThis.parentNode.childNodes[i];
							break;
					}
				}
			}
		}
		else
		{
			var pos = GetCellPos(oThis.parentNode);
			if (oCollection.rows[pos.y + 1]) {
				oTitle = oCollection.rows[pos.y + 1].cells[pos.x];
			}
			if (oCollection.rows[pos.y + 2]) {
				oSize = oCollection.rows[pos.y + 2].cells[pos.x];
			}
			
		}
		
		if (oTitle)
			href += "&title=" + escapeEx(oTitle.innerHTML);
		if (oSize)
			href += "&size=" + escapeEx(oSize.innerHTML);
		//oThis.title = oThis.rel + '<div class="blackblock">' + oTitle.innerHTML + "<br>" + oSize.innerHTML + '</div>';
	}
	//alert(oThis.desc);
	//wndChild = window.open(href, "_blank", "height="+height+",width="+width+",status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes"+position);
	
	return false;
}
function escapeEx(str){
    var ret = '';
    for (i=0; i<str.length; i++) {
        var n = str.charCodeAt(i);
        if (n >= 0x410 && n <= 0x44F) n -= 0x350;
        else if (n == 0x451) n = 0xB8;
        else if (n == 0x401) n = 0xA8;
        if ((n < 65 || n > 90) && (n < 97 || n > 122) && n < 256){
            if (n < 16) ret += '%0'+n.toString(16);
            else ret += '%'+n.toString(16);
        }
        else ret += String.fromCharCode(n);
    }
    return ret;
}
function OnViewInterior(nIndex, width, height)
{
	//CloseChildWnd();

	var maxWidth = 667;
	var maxHeight = 500;        

	if (width > maxWidth || height > maxHeight)
	{
		var k1 = maxWidth / width;
		var k2 = maxHeight / height;
		var k = k1 > k2 ? k2 : k1;

		width = Math.round(width * k);
		height = Math.round(height * k);
	}

	nIndex--;
	height += 135;
	width += 100;
	
	var position = "";
	if (NN4 || IE4 || NN6)
	{
		posX = Math.round((screen.width - width) / 2);
		posY = Math.round((screen.height - height) / 2);
		position = (NN4 || NN6) ? ",screenX=" + posX + ",screenY=" + posY : ",left=" + posX + ",top=" + posY;
	}
	
	//wndChild = window.open(currentLocation + nIndex+'/', "_blank", "height="+height+",width="+width+",status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes"+position);
	
	return false;
}

function openNew(url, name, w, h) {
    window.open(url, name, 'top=150, left=150, menubar=0, toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, width='+w+', height='+h);
}
