// Copyright (c) 2006 Klever
// http://klever.tomsk.ru/

function go(u) {
	document.location=u
}

function newWin(src, width, height) {
	w=window.open(src, "photo", "width="+width+",height="+height)
	w.focus()
	return false
}

function newWinEx(src, width, height) {
	return newWin(src, width, height + 40)
}

function closeWin(url) {
	if (wo = window.opener) {
		if (wo.closed)
			window.open(url,'_blank');
		else if (wo.location.href.search(url) == -1)
			wo.location.href = url;
		self.close()
		wo.focus()
		return false
	}
	window.open(url,'_blank')
	self.close()
	return false
}

function togglePanel(pname) {
	p = document.getElementById(pname);
	if (p) {
		if (p.style.display=='none')
			p.style.display='block'
		else
			p.style.display='none'
	}
}

function togglePanelChecked(checkbox, pname) {
	p = document.getElementById(pname);
	if (checkbox.checked) {
		if (p.style.display!='block') p.style.display='block'
	}
	else {
		if (p.style.display!='none') p.style.display='none'
	}
}

function loadPhoto(senderImg,imgToLoad,nextImg) {
	//if (this.blur) this.blur()
	pname = 'bigPhoto'
	d = document
	bf = d.getElementById(pname)
	si = d.getElementById(senderImg)
	ni = d.getElementById(nextImg)
	pt = d.getElementById('photoTitle')
	preloadEl = d.getElementById('preload')
	
	if (smallImages)
	if (bf)
	if (si)
	if (ni) {
		for (i=0; i<smallImages.length; i++) {
			img = document.getElementById(smallImages[i])
			//if (img) img.style.border='solid 1px #EEE'
			if (img) img.src='/i/photo.gif'
		}
		
		//si.style.border='solid 1px #0066AA'
		si.src='/i/photo-active.gif'
		// use preload and "loading..." picture
		if (preloadEl) {
			bf.src='/i/loading.gif'
			
			// actual photo
			preloadEl.src = '/i/photos/'+imgToLoad
			if (preloadEl.onload) preloadEl.onload = copyImgSrc(preloadEl, bf)
			else preloadEl.onLoad = copyImgSrc(preloadEl, bf)
		}
		else {
			bf.src='/i/photos/'+imgToLoad
		}
		
		// url of prev/next link
		prev = document.getElementById('prevPhoto')
		if (prev) {
			prev.parentNode.href = bf.parentNode.href
		}
		
		// change url of bigPhoto
		bf.parentNode.href = ni.parentNode.href
		
		
		// change title
		if (pt) {
			pt.innerHTML = titles[si.id]
		}
		return false
	}
	return true;
}

function copyImgSrc(source, dest) {
	dest.src = source.src
}

function getEl(elId) {
	return document.getElementById(elId)
}

