﻿Type.registerNamespace('Julian.Extenders');

Julian.Extenders.TooltipController = function()
{
	/// <summary>
    /// Controls the groups of the tooltips. Max one tooltip in a group should be displayed.
    /// </summary>
    
    Julian.Extenders.TooltipController.initializeBase(this);

	//The tooltip groups
	//assoc array from groupnames.
    this._groups = [];
    
}

Julian.Extenders.TooltipController.prototype = 
{

    registerNode: function(groupname, tooltipId)
    {
		/// <summary>
        /// Register a tooltip to the controller
        /// </summary>
    	/// <param name="groupname" type="String">
        /// The name of the group
        /// </param>    
    	/// <param name="tooltipId" type="String">
        /// The id of the tooltip
        /// </param>        
		if(this._groups[groupname] == undefined || this._groups[groupname] == null)
		{
			//create array
			this._groups[groupname] = [];
		}
		if(!Array.contains(this._groups[groupname], tooltipId))
		{
			//add the tooltipid to the group
			Array.add(this._groups[groupname], tooltipId);
		}
    
    }, 
    hideOtherInGroup : function(groupname, tooltipId)
    {
		/// <summary>
        /// Hide other tooltips in the group
        /// </summary>
    	/// <param name="groupname" type="String">
        /// The name of the group
        /// </param>    
    	/// <param name="tooltipId" type="String">
        /// The id of the current tooltip
        /// </param>        
		if(this._groups[groupname] != undefined && this._groups[groupname] != null)	
		{
			var i;
			for(i=0; i< this._groups[groupname].length;i++)
			{
				var id = this._groups[groupname][i];
				if(id != undefined && id != null)
				{
					//ignore yourself
					if(id != tooltipId)
					{
						this._hideElem(id);
					}
				}
			}
		}
    }, 
    _hideElem : function (elemId)
    {
    	/// <summary>
        /// Hide a tooltip
        /// </summary>
    	/// <param name="elemId" type="String">
        /// The id of the tooltip that should be hidden.
        /// </param>    
       if(elemId != null)
		{
			var elem = $get(elemId);
			if (elem && elem != null)
			{
				var tooltipType = Type.parse('Julian.Extenders.TooltipExtenderBehavior');
				var behaviors = Sys.UI.Behavior.getBehaviorsByType(elem, tooltipType);
				if (behaviors != null && behaviors.length > 0) 
				{
					behaviors[0].hide();
				}
			}
		}
    }
} 

Julian.Extenders.TooltipController.inheritsFrom(Sys.Component);
Julian.Extenders.TooltipController.registerClass('Julian.Extenders.TooltipController', Sys.Component);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();