var glossary;

ShowTooltip = function(e)
{

	var text = $(this).next('.show-tooltip-text');

	
		if (text.attr('class') != 'show-tooltip-text')
			return false;
	
		text.fadeIn(200)
			.css('top', e.pageY)
			.css('left', e.pageX+10);
	return false;
}
HideTooltip = function(e)
{

	var text = $(this).next('.show-tooltip-text');
	if (text.attr('class') != 'show-tooltip-text')
		return false;

	text.fadeOut(200);
	text.css('display', 'none');
}

function getGlossary(){
	$.getJSON("/fileadmin/scripts/glossary.json", function(data){
		return data;

	});

}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

SetupTooltips = function()
{
	$.ajax({
		url: "/fileadmin/scripts/glossary.json",
		dataType: 'json',
		success: function( data ) {
			$('.show-tooltip')
			.each( function(){
				var strEntry = data[$(this).attr('title')];
				$(this).attr('target', '_blank');
				var firstChar = $(this).attr('title').toString().charAt(0).toUpperCase();
				if(firstChar >= 'A' && firstChar <= 'E' || firstChar == 'Ä'){
					var strUrl = "service/glossar/#" + $(this).attr('title');
				} else if (firstChar >= 'F' && firstChar <= 'J'){
					var strUrl = "service/glossar/range/F-J#" + $(this).attr('title');
				} else if (firstChar >= 'K' && firstChar <= 'O' || firstChar == 'Ö'){
					var strUrl = "service/glossar/range/K-O#" + $(this).attr('title');
				} else if (firstChar >= 'P' && firstChar <= 'T'){
					var strUrl = "service/glossar/range/P-T#" + $(this).attr('title');
				} else if (firstChar >= 'U' && firstChar <= 'Z' || firstChar == 'Ü'){
					var strUrl = "service/glossar/range/U-Z#" + $(this).attr('title');
				}
				console.log( strEntry );
				$(this).attr('href', strUrl);
				$(this)
					.after($('<span/>')
						.attr('class', 'show-tooltip-text')
						.html(strEntry));
			});				
		}
	});

}

$(document).ready(function() {
	$.ajax({
		url: "/fileadmin/scripts/glossary.json",
		dataType: 'json',
		success: function( data ) {
			$('.show-tooltip')
				.each( function(){
					
					var strEntry = data[$(this).attr('title')];
					$(this).attr('target', '_blank');
					var firstChar = $(this).attr('title').toString().charAt(0).toUpperCase();
					if(firstChar >= 'A' && firstChar <= 'E' || firstChar == 'Ä'){
						var strUrl = "service/glossar/#" + $(this).attr('title');
					} else if (firstChar >= 'F' && firstChar <= 'J'){
						var strUrl = "service/glossar/range/F-J#" + $(this).attr('title');
					} else if (firstChar >= 'K' && firstChar <= 'O' || firstChar == 'Ö'){
						var strUrl = "service/glossar/range/K-O#" + $(this).attr('title');
					} else if (firstChar >= 'P' && firstChar <= 'T'){
						var strUrl = "service/glossar/range/P-T#" + $(this).attr('title');
					} else if (firstChar >= 'U' && firstChar <= 'Z' || firstChar == 'Ü'){
						var strUrl = "service/glossar/range/U-Z#" + $(this).attr('title');
					}
					$(this).attr('href', strUrl);
					$(this)
						.after($('<span/>')
							.attr('class', 'show-tooltip-text')
							.html(strEntry)).hover(ShowTooltip, HideTooltip);
			});	
		}
	});
});



