var ns_topshare;

if (!ns_topshare)
	ns_topshare = {};


if(!ns_topshare.ns_controllers)
	throw new Error('Missing dependency. Make sure Controllers.js is included.');

if(!ns_topshare.ns_menucontrollers)
{
	ns_topshare.ns_menucontrollers = {};

	ns_topshare.ns_menucontrollers.MenuController = function(p_ctrl_id, p_alwaysVisible, p_status, 
			p_cssBaseClass, p_cssCustomClass, p_initialVisibilityClass, p_cssStyle, p_orientationClass, 
			p_multChildren, p_tag, p_tagParams, p_targetName, p_targetType, p_targetUrl, p_viewcontext)
	{
		this.superclass(p_ctrl_id, p_viewcontext);

		this.always_visible = p_alwaysVisible;
		this.status = p_status;
		this.css_base_class = p_cssBaseClass;
		this.css_custom_class = p_cssCustomClass;
		this.visibility_class = p_initialVisibilityClass;
		this.css_style = p_cssStyle;
		this.allow_multiple_children_open = p_multChildren;
		this.orientation = p_orientationClass;
		this.tag = p_tag;
		this.tagParams = p_tagParams;
		this.tagurl = '/tagexpander/asp/tagexpander.aspx?nbrNodeID=-1&tag=';
		this.targetName = p_targetName;
		this.targetType = p_targetType;
		this.targetUrl = p_targetUrl;
		this.layoutCategory = -1;

		this.AddHandler(ns_topshare.ns_controllers.BUTTON_CLICK, this.HandleToggle);
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype = 
		new ns_topshare.ns_controllers.Controller();
	ns_topshare.ns_menucontrollers.MenuController.prototype.superclass = 
		ns_topshare.ns_controllers.Controller;
	ns_topshare.ns_menucontrollers.MenuController.prototype.constructor = 
		ns_topshare.ns_menucontrollers.MenuController;


	ns_topshare.ns_menucontrollers.MenuController.prototype.HandleToggle = function(p_msg)
	{
		if(this.HasSibling(p_msg.senderID))
			this.Toggle(true);
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype.Toggle = function(expandTag)
	{
		if(!this.always_visible)
		{
			this.status = !this.status;
			if (this.status)
			{
				this.visibility_class = 'tsMenuAan ';
				if(this.tag != '' && expandTag)
					this.ExpandTag();
			}
			else
				this.visibility_class = 'tsMenuUit ';
		}
		else
		{
			if(!this.allow_multiple_children_open)
			{
				this.status = false;
				this.visibility_class = 'tsMenuUit ';
			}
		}

		var stl = this.css_base_class + ' ' + this.visibility_class + ' ' + this.orientation;
		var target = document.getElementById(this.ctrl_id);
		target.className = stl;
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype.ExpandTag = function()
	{
		if(this.tag != '')
		{
			var tag = '@' + this.tag + ' ';

			if (this.tagParams != '')
				tag = tag + this.tagParams + ' ';

			tag = tag + this.tag + '@';
			tag = escape(tag);
			var url = this.tagurl + tag;
			var html = this.LoadHtml(url);
			document.getElementById(this.ctrl_id).innerHTML = html;
			// Is there a script involved?
			this.ScanEvalJS(document.getElementById(this.ctrl_id));
		}
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype.Open = function()
	{
		this.status = true;
		this.visibility_class = 'tsMenuAan ';

		if(this.tag != '')
			this.ExpandTag();

		var stl = this.css_base_class + ' ' + this.visibility_class + ' ' + this.orientation;
		var target = document.getElementById(this.ctrl_id);
		//	alert(this.ctrl_id);
		target.className = stl;
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype.Close = function()
	{
		this.status = false;
		this.visibility_class = 'tsMenuUit ';
		var stl = this.css_base_class + ' ' + this.visibility_class + ' ' + this.orientation;
		var target = document.getElementById(this.ctrl_id);
		target.className = stl;
	};

	ns_topshare.ns_menucontrollers.MenuController.prototype.SetLayoutCategory = function(p_layoutCategory)
	{
		this.layoutCategory = p_layoutCategory;
	};

}


