// funkce pro zobrazení a schování nápovědy
function showHelp()
{
	document.getElementById("help").style.display = "block";
}

function hideHelp()
{
	document.getElementById("help").style.display = "none";
}

function NapovedaInitialize(){
	var BrowserTopCorrectionDown = 0; /* korekce polohy - bublina pod */
	var BrowserTopCorrectionUp = 0; /* korekce polohy - bublina nad */
	var okraj = 26;
	var IE6 = $.browser.msie && /MSIE\s(6\.)/.test(navigator.userAgent);
	var IE7 = $.browser.msie && /MSIE\s(7\.)/.test(navigator.userAgent);
	var IE8 = $.browser.msie && /MSIE\s(8\.)/.test(navigator.userAgent);
	if (IE6) {
		BrowserTopCorrectionDown = 25;
		BrowserTopCorrectionUp = 4;
	} 
	if (IE7) {
		BrowserTopCorrectionDown = 25;
		BrowserTopCorrectionUp = 4;
	}
	if (IE8) {
		BrowserTopCorrectionDown = 2;
		BrowserTopCorrectionUp = -14;
	}
	$(".jqHelp").mouseover(function () {
		if (IE6) {
			$("select").hide();
		}
		if ($(this).attr("title")!='') {
			$(this).attr("help", this.title);
		}
		if (typeof $(this).attr("title") != 'undefined') {
			//$(this).removeAttr("title");
			$(this).attr({title:""});
			$(this).find("img").attr({title:""});
			this.alt = "";
			$(this).find('img').alt="";
		}
		if (typeof $(this).attr("help") != 'undefined') {
			var position = $(this).position();
			//var position2 = $("#leftColumn").scrollTop();
			$("#page").scrollTop(500);
			//alert(position2);
			//alert('top: ' + $(this).parent().position().top + ', left: ' + $(this).parent().position().left);
			$(this).prepend('<table class="jqHelpTable" cellspacing="0" cellpadding="0"><tbody><tr><td class="topleft"></td><td class="top"></td><td class="topright"></td></tr><tr><td class="left"></td><td><div class="jqHelpContent">' + $(this).attr("help") + '</div></td><td class="right"></td></tr><tr><td class="bottomleft"></td><td class="bottom"></td><td class="bottomright"></td></tr></tbody></table>');
			var table = $(this).parent().find('table')
			
			var leftColumn_top = $("#leftColumn").offset().top;
			var min_misto_nahore = 101; /*min. vzdalenost od content plochy*/
			/*var min_misto_nahore = 101 + $("html").scrollTop();*/
			var maxwidth = $(this).parent().parent().width() - 2*okraj + 5; /*korekce stinu*/			
			var x_point = position.left + $(this).width()/2; /* x souradnice sousteciho objektu*/
			
			table.width(32);
			while (table.width() < maxwidth && table.height() > 52) {
				table.width(table.width() + 10);
			}
			
			if (table.height() > 52) table.width(maxwidth);
			if (table.width() > maxwidth) table.width(maxwidth);
			
			if ((x_point + table.width()/2) < maxwidth) { /* pokud se vejde do dane oblasti => zarovnano na stred */
				if ((x_point - table.width()/2) > okraj) {
					table.css("left",(x_point - table.width()/2) + "px");
				} else {
					table.css("left",(okraj) + "px");
				}
			} else {
				if (maxwidth > table.width()) {
					table.css("left",(okraj + maxwidth - table.width()) + "px");
				} else {
					table.css("left",okraj + "px");
				}
			}
			var puvodni_top = table.position().top;
			table.css("top",(position.top - table.height() - 5 + BrowserTopCorrectionUp) + "px"); /* bublina nad */
			var misto_nad_bublinou = $(this).offset().top - $("html").scrollTop() - table.height() - 10; /*misto nad bublinou*/
			if ((misto_nad_bublinou < 0) || (table.offset().top - leftColumn_top) < min_misto_nahore) table.css("top",(puvodni_top + 5 + BrowserTopCorrectionDown) + "px"); /* bublina pod */
		}
	});
	$(".jqHelp").mouseout(function () {
		$(this).parent().find('table').remove();
		if (IE6) {
			$("select").show();
		}
	});
}
