$(document).ready(function(){
		$('ul#menu a').each(function(i, o) {
				$('span', this).css({
						top: 0,
						height: 'auto'
				});

				$(this).hover(
					function() {
						var h = $('span', this).height();
						$('span', this).animate({
								top: (0 - h - 4) + 'px'
						});
					},
					function() {
						$('span', this).animate({
								top: 0
						});
					}
				);

				$(this).click(function() {
						$('body').append('<div id="overlay"></div>');

						var w = $(document).width();
						var h = $(document).height();

						$('#overlay').css({
								position: 'absolute',
								top: 0,
								left: 0,
								width: w + 'px',
								height: h + 'px',
								backgroundColor: '#2B1100',
								opacity: 0
						});

						$('#overlay').animate({
								opacity: .9
						});

						$('#overlay').click(function() {
								boxClose();
						});

						$('body').append('<div id="obal-obsahu"></div>');

						var w = $(window).width();
						var h = $(window).height();
						var sl = w / 2;
						var st = h / 2;
						var t = 0;
						var l = 0;

						if (h > 650) {
							t = (h - 650) / 2;
							h = 650;
						}

						if (h < 500) {
							h = 500;
						}

						if (w > 930) {
							l = (w - 930) / 2;
							w = 930;
						}

						if (w < 700) {
							w = 700;
						}

						w = w - 4;
						h = h - 4;

						$('#obal-obsahu').css({
								position: 'absolute',
								top: st + 'px',
								left: sl + 'px',
								width: 0,
								height: 0,
								backgroundColor: '#f6f0da',
								border: '2px solid #ffe250'

						});

						$('#obal-obsahu').animate({
								width: w + 'px',
								height: h + 'px',
								top: t + 'px',
								left: l + 'px'
						});

						var text = $(this).text();

						$('#obal-obsahu').append('<h2>' + text + '</h2>');
						$('#obal-obsahu h2').css({
								position: 'absolute',
								top: '10px',
								left: '10px',
								width: 'auto',
								margin: 0,
								lineHeight: '35px',
								fontSize: '22px',
								fontFamily: 'serif',
								fontStyle: 'italic',
								color: '#2b1100'
						});

						$('#obal-obsahu').append('<div id="zavriet">zavrieť</div>');
						$('#zavriet').css({
								position: 'absolute',
								top: '10px',
								right: '10px',
								width: 'auto',
								lineHeight: '35px',
								margin: 0,
								cursor: 'pointer',
								_cursor: 'hand'
						});

						$('#zavriet').click(function() {
								boxClose();
						})

						var url = $(this).attr('href');
						$('#obal-obsahu').append('<iframe src="' + url + '" frameborder="0"></iframe>');
						$('#obal-obsahu iframe').css({
								position: 'absolute',
								top: '45px',
								left: '10px',
								width: (w - 20) + 'px',
								height: (h - 55) +'px',
								border: 0
						});

						return false;
				});
		});

		$(window).resize(function() {
				var w = $(document).width();
				var h = $(document).height();

				$('#overlay').css({
						width: w + 'px',
						height: h + 'px'
				});

				var w = $(window).width();
				var h = $(window).height();
				var t = 0;
				var l = 0;

				if (h > 650) {
					t = (h - 650) / 2;
					h = 650;
				}

				if (h < 500) {
					h = 500;
				}

				if (w > 930) {
					l = (w - 930) / 2;
					w = 930;
				}

				if (w < 700) {
					w = 700;
				}

				$('#obal-obsahu').animate({
						width: w + 'px',
						height: h + 'px',
						top: t + 'px',
						left: l + 'px'
				});

				$('#obal-obsahu iframe').animate({
						position: 'absolute',
						top: '45px',
						left: '10px',
						width: (w - 20) + 'px',
						height: (h - 55) +'px',
						border: 0
				});
		});
});

function boxClose() {
	$('#overlay').animate({
			opacity: 0
		},
		function() {
			$(this).remove();
	});

	$('#obal-obsahu').animate({
			opacity: 0
		},
		function() {
			$(this).remove();
	});
}

