$(document).ready(function() {

	var search_input = $("#search_input");
	search_input.focus(function() {
		if(search_input.val() == "Ide írja a keresendő kifejezést...")
			search_input.val("")
		if(search_input.val() == "Geben Sie hier einen Suchbegriff ein ...")
			search_input.val("")
		if(search_input.val() == "Enter a search term here ...")
			search_input.val("")
	});

	search_input.blur(function() {
		if(search_input.val() == "" && location.href.indexOf("l=de") !== -1)
			search_input.val("Geben Sie hier einen Suchbegriff ein ...")
		else if(search_input.val() == "" && location.href.indexOf("l=en") !== -1)
			search_input.val("Enter a search term here ...")
		else if(search_input.val() == "")
			search_input.val("Ide írja a keresendő kifejezést...")
	});


	$("ul#menu li").hover(function(){
		jQuery(this).addClass("hover");
		$('ul:first',this).fadeIn("fast");
	}, function(){
		jQuery(this).removeClass("hover");
		$('ul:first',this).hide();
	});






	// menu scroll
	$("#leftmenu li a").each(function() {
		var next = $(this).next("ul");

		// ha van almenu
		if( typeof next[0] != 'undefined') {

			var id   = $(this).attr("id");
			var itemsLength = $(this).next("ul").children("li").length;

			$(this).attr("href", "javascript:void(null)");
			$(this).click(function() {

				eraseCookie("openmenu_"+id);

				if(next.css("display") == 'none') {

					// ossze kell csukni mindet
					$("#leftmenu li ul").each(function () {
						if( jQuery(this).css("display") == "block" ) {
							var link = jQuery(this).prev("a");
							link.click();
						}
					});


					next.slideDown();

					var i = 0;

					$(this).next("ul").children("li").each(function() {
						$(this).animate({
							left: '0px'
						}, 500 + i*100, "swing" );
						i++;
					});

					createCookie("openmenu_"+id, "true", 7);
				}
				else {
					var i = itemsLength;

					$(this).next("ul").children("li").each(function() {
						$(this).animate({
							left: '-180px'
						}, 500 + i*100, "swing" );
						i--;
					});
					next.slideUp("slow");
				}


			});

		} else {
			jQuery(this).click(function () {
				$("#leftmenu li ul").each(function () {
					if( jQuery(this).css("display") == "block" ) {
						var link = jQuery(this).prev("a");
						link.click();
					}
				});
			})
		}

	});

	// nyitott menuk megjelenitese
	// vegigmegy minden almenun, es megnezi van e ilyen cookie
	$("#leftmenu li a").each(function() {

		var next = $(this).next("ul");
		// havan almenu
		if( typeof next[0] != 'undefined') {

			var id = $(this).attr("id");
			if(readCookie("openmenu_"+id)) {
				next.show();
				$(this).next("ul").children("li").each(function() {
					$(this).css("left", '0px');
				});
			}

		}

	});



	jQuery(".akadalymentes").click(function () {
		if(readCookie("akadalymentes") == "null" || readCookie("akadalymentes") == "false" ) {
			createCookie("akadalymentes","true",1);
		}
		else {
			eraseCookie("akadalymentes");
			createCookie("akadalymentes","false",1);
		}
	})



});






function createCookie(name,value,days) {

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
	}

	function eraseCookie(name) {
	createCookie(name,"",-1);
	}


	function getProgramok(datum, item, lang) {
  xajax_get_napi_programok(datum, lang);
	$('#naptar_popup_content').html('<center><img src="/images/loadinfo.net.gif" alt="" /></center>')
	//getting height and width of the message box

	var item_offs = $("#nap_"+item).offset();

	//calculating offset for displaying popup message
	if(item_offs.scrollLeft) {
	leftVal = item_offs.left + item_offs.scrollLeft + 33 + "px";
	} else {
	leftVal = item_offs.left + 33 + "px";
}

if(item_offs.scrollTop) {
	topVal=item_offs.top + item_offs.scrollTop +"px";
} else {
	topVal=item_offs.top + 30 + "px";
}

//show the popup message and hide with fading effect
$('#naptar_popup').css({
	left:leftVal,
	top:topVal
}).show();





}
