	/*
		ToolTip
	*/
	
	var toolTip_OpenDelay = 200;
	var toolTip_HideDelay = 500;
	var toolTip_ElementId = 'toolTip'
	
	var toolTipHideEffect, toolTipShowEffect, toolTipOpenerTimer, toolTipHiderTimer, toolTipAjaxRequest, toolTipAjaxTimer;
	
	function toolTipParentMouseOut(link)
	{
		if (toolTipOpenerTimer != null)
		{
			clearTimeout(toolTipOpenerTimer);
		}
		
		if (toolTipAjaxTimer != null)
		{
			clearTimeout(toolTipAjaxTimer);
		}
		
		//Avbryter eventuella köade ajax-requests
		if (toolTipAjaxRequest != null)
		{
			toolTipAjaxRequest.cancel();
		}
		
		toolTipHiderTimer = setTimeout(function()
		{
			hideToolTip();
		}, toolTip_HideDelay);
	}
	
	function toolTipMouseOver()
	{
		clearTimeout(toolTipHiderTimer);
	}
	
	function toolTipMouseOut()
	{
		toolTipParentMouseOut();
	}
	
	function createToolTip()
	{		
		var body = document.getElementsByTagName('body');
		body = body[0];
		var insertion = new Insertion.Top(body, '<div id="'+toolTip_ElementId+'" style="display:none; z-index: 100;" onmouseover="toolTipMouseOver();" onmouseout="toolTipMouseOut();"></div>');
	}
	
	function clearToolTipClassNames()
	{
		var toolTip = $(toolTip_ElementId);
		
		//Hämtar ut alla classNames 
		var classNames = toolTip.classNames();
		classNames = $A(classNames);
		
		//Loopar igenom alla classnames och tar bort dom 
		for (var i=0; i<classNames.length; i++)
		{
			$(toolTip_ElementId).removeClassName(classNames[i]);
		}
	}
	
	function openToolTip(link, content, options)
	{
		if (options == null)
		{
			options = {};
		}
		
		if (toolTipHiderTimer != null)
		{
			clearTimeout(toolTipHiderTimer);
		}
		
		if (options.delay != null)
		{
			toolTip_OpenDelay = options.delay;
		}
		
		toolTipOpenerTimer = setTimeout(function()
		{
			observeMouseMovement();
		
			//Har vi inte öppnat toolTip:en förut så skapar vi den
			if ($(toolTip_ElementId) == null)
			{
				createToolTip();
			}
		
			var toolTip = $(toolTip_ElementId);
			toolTip.innerHTML = content;
			
			clearToolTipClassNames();
			
			//Lägger till default-ClassName igen
			Element.addClassName(toolTip, 'toolTip');
			
			//Lägger till eventuella mer classNames för att snygga till toolTipen
			if (options.className != null)
			{
				Element.addClassName(toolTip, options.className)
			}
			
			var posX = pointerX; //findPosX(link);
			var posY = pointerY; //findPosY(link);
			
			if (posX == 0) { posX = findPosX(link); }
			if (posY == 0) { posY = findPosY(link); }

			posX += 15;
			posY += 15;
			
			if (options.offsetY != null) {	posY = posY + options.offsetY; }
			
			Element.setStyle(toolTip, { left: ''+posX+'px', top: ''+posY+'px'})
			
			if (Element.getOpacity(toolTip) > 0.9)
			{
				Element.setOpacity(toolTip, 0.7);
			}	
			
			toolTipShowEffect = Effect.Appear(toolTip, { duration: 0.3 });

		}, toolTip_OpenDelay);
	}
	
	function hideToolTip()
	{
		if ($(toolTip_ElementId) != null)
		{
			toolTipHideEffect = Effect.Fade($(toolTip_ElementId), { duration: 0.3 });
		}
	}
	
	function openAjaxToolTip(link, url, pars, options)
	{
		openToolTip(link, '', options);
		
		setTimeout(function()
		{
			if ($(toolTip_ElementId) != null && $(toolTip_ElementId).innerHTML == "")
			{
				$(toolTip_ElementId).innerHTML = '<p class="center small nomargin"><img src="/images/loading_wide.gif" /><br /><em>Laddar...</em></p>';
			}
		}, toolTip_OpenDelay + 200);
		
		if (options.method != null)
		{
			var method = options.method;
		}
		else
		{
			var method = 'get';
		}
		
		toolTipAjaxTimer = setTimeout(function()
		{
			var toolTipAjaxRequest = new Ajax.Updater(
				toolTip_ElementId, 
				url, 
				{
					method: method, 
					parameters: pars
				});
			
		}, toolTip_OpenDelay + 100);
	}
	
	/*
	//	Custom toolTips
	*/
	function openWordDescriptionToolTip(link, word)
	{
		openAjaxToolTip(link, '/actions/tooltips/wordDescription.php', 'word='+word+'', {className: "toolTip_wordDescription"});
		return false;
	}

	function openRecepieToolTip(link, recipeId, offsetX, offsetY)
	{
		openAjaxToolTip(link, '/actions/tooltips/recipe.php', 'recipeId='+recipeId+'', {className: "toolTip_recepie"});
		return false;
	}
	
	//Måste ha denna för att det ska funka atta använda på usersidan -> Bilder. använd inte denna igen, använd: openRecepieToolTip()
	function openRecepieToolTipHaxx(link, recipeId, offsetX, offsetY)
	{
		openAjaxToolTip(link, '/actions/tooltips/recipe.php', 'recipeId='+recipeId+'', {className: "toolTip_recepie"});
		return false;
	}
	
	function openUserToolTip(link, userId)
	{
		openAjaxToolTip(link, '/actions/tooltips/user.php', 'userId='+userId+'', {className: "toolTip_user"});
		return false;
	}
	
	function openIngredientToolTip(link, ingredName)
	{
		openAjaxToolTip(link, '/actions/tooltips/ingredient.php', 'ingredientName='+ingredName+'', {className: "toolTip_ingredientDescription", delay: 50});
		return false;
	}