﻿// JScript File



//Register Namespace
Namespace.Register("System.Web.UI.WFSMenu");
///<summary>
/// {Class} System.Web.UI.WFSMenu
/// simple rollover menu
/// Arguments: [id,controls,looks,option]
/// output <div id="" class="" etc></div>
///</summary>
System.Web.UI.WFSMenu = function(){ return {
				ID : null,
				_flow : "horizontal",
				_cssclass : null,
				_width : null,
				_height : null,
				_Controls : [],
				Controls : [],
				_Looks : [],
				_Options : [],
				writer : [""],
				///<summary>
                ///	loads the controls into the writer
                ///</summary>
				LoadControls : function()
				{
				    var olen = this._Controls.length;
				    var safety = 0;
				    for(var i=0;i<olen;i++)
				    {
				    if(safety>10)
				        break;
				       var id=this._Controls[i][0];
				       var options = this._Controls[i][1];
				       var looks = [];
				       var lkid = this._Controls[i][2];
				       var isactive = this._Controls[i][3];
				       isactive = (isactive && isactive.length>0)?isactive:false;
				       if(lkid && lkid.length>0)
				       {
				        looks = this.GetLook(lkid);
				       }
				        var menuitem;
				            menuitem = new System.Web.UI.MenuItem(id,options,looks,isactive,this);
				        this.Controls.push(menuitem);
				        safety++;
				    }
				    
				},
				///<summary>
                ///	adds a provided control to the menu's control collection 
                ///</summary>	
				AddControl : function(control)
				{
				    this.Controls.push(control);
				},
				///<summary>
                ///	attempts to get a look from the look collection 
                ///</summary>	
				GetLook : function(id)
				{
				    var olen = this._Looks.length;
				    for(var i=0;i<olen;i++)
				    {
				      if(this._Looks[i][0] == id)
				      {
				        return this._Looks[i][1];
				      }
				    }
				},
				///<summary>
                ///	loads the base properties for this control
                ///</summary>
				LoadOptions : function()
				{
				    var olen = this._Options.length;
				    for(var i=0;i<olen;i++)
				    {
				        switch(i)
				        {
				            case 0://flow
				                this._flow = this._Options[i]?this._Options[i]:this._flow;
				                break;
				            case 1://css
				                this._cssclass = this._Options[i]?this._Options[i]:null;
				                break;
				            case 2://width
				                this._width = this._Options[i]?this._Options[i]:null;
				                break;
				            case 3://height
				                this._height = this._Options[i]?this._Options[i]:null;
				                break;
				        }
				    }
				},
	            ///<summary>
                ///	gets any style attributes applied to this Item
                ///</summary>
	            GetStyle : function()
	            {
	                var style = ["style=\""];
	                if(this.BackgroundColor)
	                    style[style.length] = this.BackgroundColor + ";";
	                if(this._width)
	                    style[style.length] = this._width + "px;";
	                if(this._height)
	                    style[style.length] = this._height + "px;";
	                    
	                // TODO any other style attributes added to a menu item to be rendered..
	                    
	                    style[style.length] = "\"";
	                    return style.join("");
	            }, 
				///<summary>
                ///	returns the default css class
                ///</summary>
				BuildCss : function()
				{								        
				    if(this._cssclass)
				        return this._cssclass;
				},
				RenderChildControls : function(writer)
				{
				    var clen = this.Controls.length;
				    for(var i=0;i<clen;i++)
				    {
				        if(this.flow=="vertical")
				        {
				            writer[writer.length] = "<tr>";
				            writer[writer.length] = "<td>";
		                    Controls[i].RenderConrol(writer);
				            writer[writer.length] = "</td>";
				            writer[writer.length] = "</tr>";
				        }
				        else//horizontal
				        {
				            writer[writer.length] = "<td>";
				            if(this.Controls[i].RenderControl)
				                this.Controls[i].RenderControl(writer);
				            writer[writer.length] = "</td>";
				        }
				    }
				},				
				///<summary>
                ///	applies the looks to the rollover state
                ///</summary>
				GetItem : function(item)
				{
				    var clen =this.Controls.length;
				    for(var i=0;i<clen;i++)
				    {
				        var itm = this.Controls[i];
				        if(itm.ID == item)
				            return itm;
				    }
				},
				
				///<summary>
                ///	applies the looks to the rollover state
                ///</summary>
				ItemMouseOver : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.MouseOver)
				        obj.MouseOver();
				},
				///<summary>
                ///	applies the looks to the rollout state
                ///</summary>
				ItemMouseOut : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.MouseOut)
				        obj.MouseOut();
				},
				///<summary>
                ///	applies the looks to the mousedown state
                ///</summary>
				ItemMouseDown : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.MouseDown)
				        obj.MouseDown();
				},
				///<summary>
                ///	applies the looks to the mouseup state
                ///</summary>
				ItemMouseUp : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.MouseUp)
				        obj.MouseUp();
				},
				///<summary>
                ///	applies the looks to the mouseout state
                ///</summary>
				ItemMouseOut : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.MouseOut)
				        obj.MouseOut();	    
				},
				///<summary>
                ///	navigates to the link applied to this control
                ///</summary>
				ItemClick : function(name)
				{
				    var obj = this.GetItem(name);
				    if(obj && obj.Click)
				        obj.Click();
				},
				RenderControl : function()
				{							       
				    this.writer[this.writer.length] = "<table cellpadding=\"0\" cellspacing=\"0\" id=\""+this.ID+"\" class=\""+this.BuildCss()+"\" "+this.GetStyle()+">";
				    if(!(this.flow=="vertical"))
				        this.writer[this.writer.length] = "<tr>";
				    this.RenderChildControls(this.writer);
				    if(!(this.flow=="vertical"))
				        this.writer[this.writer.length] = "</tr>";
				    this.writer[this.writer.length] = "</table>"; 
				    document.write(this.writer.join(''));
				},
				Cotr : function()
				{				
                switch(arguments[0].length)
                {
                    case 1 : this.ID = arguments[0][0]; break;
                    case 2 : this.ID = arguments[0][0]; this._Controls = arguments[0][1]; break;
                    case 3 : this.ID = arguments[0][0]; this._Controls = arguments[0][1]; this._Looks = arguments[0][2]; break;
                    case 4 : this.ID = arguments[0][0]; this._Controls = arguments[0][1]; this._Looks = arguments[0][2]; this._Options = arguments[0][3]; break;
                 }
                 this.LoadOptions();
                 this.LoadControls();
                 return this;
				}
				
}.Cotr(arguments);}

