/*
 sada funkci pro snadnejsi listovani fotogaleriema
 */

function keypressHandler(event) {
	var key = event.which || event.keyCode;
	switch (key) {
		case Event.KEY_RIGHT:
			if ($('listNext')) window.location = $('listNext').href;
			break;
		case Event.KEY_LEFT:
			if ($('listPrev')) window.location = $('listPrev').href;
			break;
		case Event.KEY_ESC:
			window.close();
			break;
	}
}

function imageClick(evt) {
	var xpos = Event.pointerX(evt);
	var half = (evt.target.getWidth()/2)+evt.target.cumulativeOffset().left;
	if (xpos>half) {	// dalsi - pokud existuje
		if ($('listNext')) window.location = $('listNext').href;
		else window.close();
	}
	else {				// predchozi - pokud existuje
		if ($('listPrev')) window.location = $('listPrev').href;
		else window.close();
	}
}

function imageOver(evt) {
	var xpos = Event.pointerX(evt);
	var half = (evt.target.getWidth()/2)+evt.target.cumulativeOffset().left;
	var iTit = '';
	if (xpos>half) {	// dalsi - pokud existuje
		if ($('listNext')) iTit = 'další obrázek';
	}
	else {				// predchozi - pokud existuje
		if ($('listPrev')) iTit = 'předchozí obrázek';
	}
	evt.target.title = iTit;
}

// obsluha udalosti a dalsi operace po nacteni stranky
Event.observe(window, 'load', function() {
	Event.observe(document, 'keyup', keypressHandler);
	Event.observe('theImg','click',imageClick);
	Event.observe('theImg','mouseover',imageOver);
	$('theImg').setStyle({cursor:'pointer'});
});