var ajx_cache = Array();
var ivl = 0;
var cid = 0;

$(document).ready(function(){
	var i = 1;
	$('.infopop').each(function(idx, it){
		$(it).attr('id', 'infopop_'+i);
		$(it).mouseenter(function(e){
			// alert($(this).attr('title'));
			var ox = $(this).position().left
			if(ox > 450){
				ox = 450
			}
			$('#infopop_block').css('left', (347+ox)+'px');
			$('#infopop_block').css('top', ($(this).offset().top-2)+'px');
			var id = cid = $(this).attr('title');
			if(ajx_cache[id]){
			    ivl = setInterval(blockupdater, 10)
			} else {
				$('#in_infopop_text').html('<b>loading...</b>')
				$.ajax({
					type: "POST",
					url:'/'+lang+'/glossar/ajx.'+$(this).attr('title')+'.html',
					data:{d:$(this).attr('title')},
					// contentType: "application/x-www-form-urlencoded; charset=UTF-8",
					success:function(text){
						ajx_cache[id] = text
						ivl = setInterval(blockupdater, 200)
					}
				})
			}
		})
		$(it).click(function(){return false})
		i++;
	});
	$('#fld').focus(function(){
		if($(this).val() == suche){
			$(this).val('')
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val(suche)
		}
	}).blur()
	
})

function blockupdater(){
	$('#in_infopop_text').html(ajx_cache[cid]+'<p style="text-align: right;"><a href="/'+lang+'/glossar/'+cid+'.html">'+mdz+'</a></p>')
	//alert($(document).scrollTop())
	clearTimeout(ivl)
	$('#infopop_block').mouseleave(function(e){
		$('#infopop_block').css('left', '-10000px');
		$('#infopop_block').css('top', '-10000px');
	})

}
