function openWin(url, title, width, height, ps) {
	if (!ps) ps = {};
	var win = window.open(url, title, "width=" + width + ",height=" + height + ",left=" + ((ps.left == null) ? Math.round((screen.width - width) / 2) : ps.left) + ",top=" + ((ps.top == null) ? Math.round((screen.height - height) / 2 - 40) : ps.top) + ",toolbar=0,menubar=0,location=0,status=" + (ps.status ? 1 : 0) + ",resizable=" + (ps.resizable ? 1 : 0) + ",scrollbars=" + (ps.scrollbars ? 1 : 0));
	if (!ps.noFocus) win.focus();
	return win;
}

function openEditor(url, width, height) {
	editCache=null;
	openWin(url, 'edit', width, height, { left: (screen.width - width - 20), top: 40, resizable: 1, scrollbars: 1, noFocus: 1 });
	return false;
}

var lastClick = 0;
function chooseItem(id, images) {
	if (document.getElementById) {
		var now = new Date().getTime();
		if (lastId != null && id != lastId || now - lastClick > 250)
			toggleItem(id, images);
		lastClick = now;
		return false;
	}
}

function toggleItem(id, images, deselect) {
	if (lastId && lastId != id) {
		var prevId = lastId;
		lastId = null;
		toggleItem(prevId, null, true);
	}
	var e = document.getElementById("detail_" + id);
	var open = e.style.display == 'none' || (e.className == "hidden" && e.style.display == '');
	if (open) {
		var ie/*@cc_on=@_jscript_version@*/;
		try {
			e.style.display = ie ? 'block' : 'table-row';
		} catch (ex) {
			e.style.display = 'block';
		}
		for (var i in images) {
			var img = document.images["img_" + id + "_" + images[i]];
			if (img) img.src = "/static/thumbs/" + images[i];
		}
		lastId = id;
	} else {
		e.style.display = 'none';
		lastId = null;
	}
	document.getElementById("row_" + id).className = deselect || !open ? "visited" : "active";
}

var lastRow = null;
function hoverRow(row, hover) {
	if (hover) {
		if (lastRow) hoverRow(lastRow, false);
		lastRow = row;
		row.bgColor = '#eeeeee';
	} else {
		if (lastRow && lastRow != row) hoverRow(lastRow, false);
		row.bgColor = '#ffffff';
		lastRow = null;
	}
}
