/*
 * otevre okno s napovedou
 */

var popupWin = {
	'help' : null,
	'characteristics' : null,
	'picture': null
};

Event.onDOMReady(function() {
	var anchors = $$('a[rel="help"]');
	anchors.each(function(anchor) {
		Event.observe(anchor, 'click', function(event) {
			openPopup(event, anchor, 'help', 600, 500, 'right', 'event', 'yes');
			Event.stop(event);
		});
	});
	var anchors = $$('a[rel="glossary"]');
	anchors.each(function(anchor) {
		Event.observe(anchor, 'click', function(event) {
			openPopup(event, anchor, 'characteristics', 600, 500, 'right', 'event', 'yes');
			Event.stop(event);
		});
	});
	// okno s obrazkem a prepinacem nahledu
	var anchors = $$('a.picturepopupext');
	anchors.each(function(anchor) {
		Event.observe(anchor, 'click', function(event) {
			openPopup(event, anchor, 'picture', 770, 680, 'center', 'center', 'no');
			Event.stop(event);
		});
	});
	// okno s obrazkem bez prepinace nahledu
	var anchors = $$('a.picturepopup');
	anchors.each(function(anchor) {
		Event.observe(anchor, 'click', function(event) {
			openPopup(event, anchor, 'picture', 622, 680, 'center', 'center', 'no');
			Event.stop(event);
		});
	});
});

function openPopup(e, a, type, width, height, xpos, ypos, scrollbars) {
	var link = a.readAttribute('href');
	if(popupWin[type] != null && ! popupWin[type].closed) {
		popupWin[type].close();
	}
	//alert(type + ': ' + link)
	var left;
	var top;
	switch(xpos) {
		case 'center':
			left = (screen.width - width) / 2;
			break;
		case 'right':
			left = screen.width - width;
			break;
		case 'event':
			left = Math.min(screen.width - width, e.screenX);
			break;
		default:
			left = 0;
			break;
	}
	switch(ypos) {
		case 'center':
			top = (screen.height - height) / 2;
			break;
		case 'bottom':
			top = screen.height - height;
			break;
		case 'event':
			top = Math.min(screen.height - height, e.screenY);
			break;
		default:
			top = 0;
			break;
	}
	popupWin[type] = window.open('' + link, '' + type, 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',scrollbars=' + scrollbars);
}

