$(document).ready(function(){

	//zjisti vysku okna prohlizece
	function winHeight() {
		if (window.innerHeight) { 
			return window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		}
		else if (document.body && document.body.clientHeight) {
			return document.body.clientHeight;
		}
		else return null;
	}
	
	// nahradi href u odkazu dle maleho obrazku
	$(".refimage").each(function() {
		var imgUrl = $(this).find('img').attr('src');
		//pokud je okno menší než 800 pixelu, odkaze se na iframe verzi, jinak primo na obrazek
		if (winHeight() < 800) { 
			imgUrl = '/scripts/_lightbox-picture-page.php?pict=' + encodeURIComponent(imgUrl.replace('/thn/', '/big/').replace(/\./g, '~.~'));
		}
		else {
			imgUrl = imgUrl.replace('/thn/', '/big/');
		}	
		$(this).attr({
       		href: imgUrl
       	});
		$(this).parent().find('span a').attr({
       		href: imgUrl
       	});
	});

	//... priradi mu fancybox do iframe...
	$(".refimage, .gallery-link").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'frameWidth': 720,
		'frameHeight': 450,
		'hideOnContentClick': true,
		'overlayShow': true,
		'overlayOpacity': 0.5
	});
});
