$(document).ready(function() {

	/* varovani na pristupnost */
	if ($(".pristupnostP").size() > 0) {
		var cookieVal = $.cookie('topfun-pristupnost-p');
		if (cookieVal != 1) {
			$.openDOMWindow({
				loader: 0,
				modal: 1,
				width: '550',
				overlayOpacity: '95',
				windowSource: 'iframe',
				windowSourceURL: PAGEURL_UpozorneniP
			});
		}
	}
	$(".pristupnostConfirm .btn-ok").click(function() {		
		$.cookie('topfun-pristupnost-p', 1, { path: '/' });
		window.parent.location.reload();
		return false;
	});
	$(".pristupnostConfirm .btn-exit").click(function() {
		window.parent.location = HTTP_PATH;
		return false;
	});
	
	/* popup info */
	if (typeof(PAGEURL_Popupinfo) !== 'undefined' && PAGEURL_Popupinfo && window == window.top) {
		var cookieVal = $.cookie('topfun-popupinfo');
		if (cookieVal != 1) {
			$.cookie('topfun-popupinfo', 1, { expires: 2, path: '/' });
			$.openDOMWindow({
				loader: 0,
				width: '550',
				overlayOpacity: '95',
				windowSource: 'iframe',
				windowSourceURL: PAGEURL_Popupinfo
			});
		}
	}
	$(".popupConfirm .btn-ok").click(function() {				
		window.parent.location.reload();
		return false;
	});
	
	/* search */
	$("#form-search-text").listenForEnter().bind("pressedEnter", function() {			
		$("#form-search").submit();
	});

	$("#form-search").bind("submit", function() {
		if ($("#form-search-text").val() == MM_SearchHint) $("#form-search-text").val('');
	});
	$("#form-search-text").bind("blur", function() {
		if ($(this).val() == '') $(this).val(MM_SearchHint);
	});
	$("#form-search-text").bind("focus", function() {
		if ($(this).val() == MM_SearchHint) $(this).val('');
	});
	if ($("#form-search-text").val() == '') {
		$("#form-search-text").val(MM_SearchHint);
	}

	$("#form-search-button").bind("click", function() {			
		$("#form-search").submit();
		return false;
	});

	/* class="shorttext" */	
	$(".shorttext").each(function() {
		var ch = $(this).height();		
		var lh = parseInt($(this).css("line-height"));
		var res = lh * 5;
		if (res < ch) {			
			$(this).css("overflow", "hidden");
			$(this).height(res);
			$(this).after('<div class="cleaner"></div>').after('<a href="#vice" class="shorttext-more">'+MM_ShorttextMore+'</a>');
			var mb = parseInt($(this).css("margin-bottom"));			
			if (mb > 0) {
				$(this).css("margin-bottom", "0");
				$(this).next(".shorttext-more").css("margin-bottom", (mb+"px"));
			}
		}
	});
	$(".shorttext-more").click(function() {
		var mb = parseInt($(this).css("margin-bottom"));
		if (mb > 0) {			
			$(this).prev(".shorttext").css("margin-bottom", (mb+"px"));
		}
		$(this).prev(".shorttext").height("100%");
		$(this).remove();
		return false;
	});	
	
});

$(window).load(function() {
	autoHeightBlocks(".autoheight", 0);
	autoHeightBlocks(".autoheight1", 5);
	autoHeightBlocks(".autoheight2", 0);
	autoHeightBlocks(".autoheight3", 0);
	autoHeightBlocks(".autoheight4", 0);
});

function autoHeightBlocks(selector, add) {
	var maxHeight = 0;
	$(selector).each(function() {
		tmpHeight = $(this).height();
		if (tmpHeight > maxHeight) {
			maxHeight = tmpHeight;
		}
	});
	if (add > 0) {
		maxHeight += add;
	}
	$(selector).height(maxHeight);
}
