function showList(listId, img)
{ 
	if (document.getElementById(listId).className == 'invisibleChilds')
	{
		document.getElementById(listId).className = 'visibleChilds';
		img.src = '/images/minus.gif';
	}
	else
	{
		document.getElementById(listId).className = 'invisibleChilds';
		img.src = '/images/plus.gif';
	}
}

function submitSearchForm(form)
{
	document.location = form.action + '/query_' + form.query.value;
	return false;
}


function replaceImage(id, thumbnail)
{
	var currentPreviewSource = document.getElementById('preview' + id).src;
	document.getElementById('preview' + id).src = thumbnail.src.replace('_thumbnail', '_preview');
	thumbnail.src = currentPreviewSource.replace('_preview', '_thumbnail')
}

function openImagePopup(imgPath, title, alt)
{
	imgPath = imgPath.replace('_preview', '');
    var win = window.open('', 'preview', 'width=2,height=2,left=50%,top=0,screenX=0,screenY=0,resizable=1,scrollbar=0,status=0');

    var winDoc = win.document;
    if (title == undefined)
	{
		title = 'Нажмите на изображение, чтобы закрыть';
	}
    if (alt == undefined)
	{
		alt = 'Нажмите на изображение, чтобы закрыть';
	}
    var content = '<html><head><title>' + title + '</title><style>body {overflow: hidden; margin: 0;} img {border: 0;}</style></head><body><a href="javascript:self.close()"><img alt="' + alt + '" id="image" src="' + imgPath + '" /></a></body></html>';
    win.document.write(content);

    winDoc.body.onload = function()
    {
    	var obj = winDoc.getElementById('image');

    	var w = obj.width;
		var h = obj.height;

    	var iHeight = document.body.clientHeight;
		var iWidth = self.innerWidth;

    	var left = (self.opera ? iWidth : screen.availWidth) / 2 - w / 2;
    	var top = (self.opera ? iHeight : screen.availHeight) / 2 - h / 2;
    	win.resizeTo(w+10, h+26);
    	win.moveTo(left, top);
    }
    win.onload = winDoc.body.onload; // special for Mozilla

    win.document.close();
    win.focus();
}

function showChilds(id)
{
	if (document.getElementById(id).className == 'invisibleChilds')
	{
		document.getElementById(id).className = 'visibleChilds';
	}
	else
	{
		document.getElementById(id).className = 'invisibleChilds';
	}
}

function showAll(obj)
{
	if (obj.parentNode.className == 'directoryToc')
	{
		obj.parentNode.className = 'directoryToc showList';
	}
	else
	{
		obj.parentNode.className = 'directoryToc';
	}
}
