$(document).ready(function() {
	var timer = null;

	//inicializace prázdného formulářového políčka pokud je předdefinované
	$('.focinput').fitt();

	//promítačka obrázků
	$('.slideshow').cycle({
		fx: 'fade'
	});

	// potřebová navigace
	$("#necessary area").bind("mouseover", function() {
		clearTimeout(timer);
		$(".tooltip-hp").hide();
		var actualItem = $("#necessary area").index(this)+1;
		var backgroundY = actualItem*-400;
		$("#underline").css("background-position","0px "+backgroundY+"px");
		$("#tooltip-"+actualItem).show();
	});
	$("#necessary area").bind("mouseout", function() {
		clearTimeout(timer);
		$("#underline").css("background-position","0px 0px");
		timer = setTimeout( function() { $(".tooltip-hp").hide(); }, 400 );
		//$(".tooltip-hp").hide();
	});
	$(".tooltip-hp").bind("mouseover", function() {
		clearTimeout(timer);
	});
	$(".tooltip-hp").bind("mouseout", function() {
		clearTimeout(timer);
		timer = setTimeout( function() { $(".tooltip-hp").hide(); }, 100 );
		//$(".tooltip-hp").hide();
	});

	//odkazy mimo web
	/*
	$(document).ready(function() {
		$('#main a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).addClass('external')
		.click(function() {
			window.open(this.href);
			return false;
		});
	});
	*/

	// menu
	$('ul#menu>li').bind('mouseover', function (){
		clearTimeout(timer);
		$(".tooltip-hp").hide();
		$('ul#menu>li').removeClass('hover');
		$(this).addClass('hover');
		$('ul#menu>li.active .submenu').css('display', 'none');
		clearTimeout(timer);

		if($.browser.msie && $.browser.version < 7) {
				$('.disguise1').css('visibility', 'hidden');
		}
	});

	$('ul#menu>li').bind('mouseout', function (){
		clearTimeout(timer);
		if($.browser.msie && $.browser.version < 7) {
				$('.disguise1').css('visibility', 'visible');
		}
	});

	$('ul#menu>li.active').bind('mouseover', function (){
		clearTimeout(timer);
		$('ul#menu>li.active .submenu').css('display', 'block');
	});

	$('ul#menu>li:not(.active)').bind('mouseout', function(){
		clearTimeout(timer);
		var activeElement = $(this);
		$('ul#menu>li.active .submenu').css('display', 'block');
		timer = setInterval(function(){ activeElement.removeClass('hover');}, 300);
	});

/*
	$("ul#menu .submenu>li").mouseover(function(){
		$(this).addClass("hover");
	}).mouseout(function(){
		$(this).removeClass("hover");
	});
*/
	$("ul#menu .submenu>li").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); });
		clearTimeout(timer);
	// náhrade elementu legend za třídu legend ve firefoxu
	if($.browser.mozilla) {
		$("legend").each(function () {
			$(this).replaceWith("<div class=\"clr legend\">" + $(this).text() + "</div>");
		});
	}

	// skrytí požadovaných prvků
	$(".jQ-hide").hide();

	//slovník pojmů
	$("acronym").each( function() {
		var url = $("a", $(this)).attr("href");
		var kWord = $("a", $(this)).text();
		var title = $(this).attr("title");
		var rootWord = $("a", $(this)).attr("title");
		
		$(this).data("kWord", kWord);
		$(this).data("url", url);
		$(this).data("title", title);
		$(this).data("rootWord", rootWord);
		
		$(this).html("").text(kWord).tooltip({
			bodyHandler: function() {
				return "<h5>"+$(this).data("rootWord")+"</h5><p>"+$(this).data("title")+"</p><div class=\"bottom\"><a href=\""+$(this).data("url")+"\">slovník pojmů</a></div>";
			},
			showURL: false,
			top: -5,
			id: "vocabulary-tooltip"
		});
	});

	// Toogle - skrývání a zobrazování obsahu
	$('.toogle-box').hide();
	$('.toogle').click(function() {
		$('.toogle-box').toggle(1);
		return false;
	});

	$(function() {
		$('.datePicker').datepicker({
			changeMonth: true,
			changeYear: true
		});
	});

	/* overlay */
	$("thead th").each(function(){
		$(this).bind("mouseover", function() {
			$(" .overlay",this).show();
		}).bind("mouseout", function() {
			$(" .overlay",this).hide();
		});
	});

/*
$(".languages a:gt(0)", $(oId)).each(function() {
		sb.append('<li><a href="'+$(this).attr("href")+'">'+$(this).html().replace("-small","")+'</a></li>');
	});
*/

});

/* flash charts */
function writeFlashChart(from, to, fundCodesChart) {
	if(fundCodesChart.length > 0) {
		document.write('<div id="graph"><p>Pro zobrazení banneru je nutné mít povolen JavaScript a&nbsp;nainstalovánu'+
		'aktuální verzi Flash pluginu společnosti Adobe.<br />'+
		'Plugin je ke stažení <a href="http://www.adobe.com/go/getflashplayer" target="_blank" class="external">zde</a>.</p></div>');
		uniqueID = Math.random();
		var flashvars = {
		};
		var params = {
			bgcolor: "#ffffff",
			swliveconnect: "true"
		};
		var attributes = {
		};
		// /swf/u/chart/sample.xml nahradit něčím takovým /srv/www/cs/izp/xmlData.do%3FuniqueID%3D'+uniqueID+'%26from%3D'+from+'%26to%3D'+to+'%26fundCodes%3D'+fundCodesChart1+'"
		swfobject.embedSWF("/swf/u/chart/charts.swf?library_path=/swf/u/chart/charts_library&xml_source=/swf/u/chart/sample.xml", "graph", "516", "285", "8.0.34", null, flashvars, params, attributes);
	}
}
