﻿// JScript File



//Register Namespace
Namespace.Register("System.Web.UI.MenuItem");
///<summary>
/// {Class} System.Web.UI.MenuItem
///	A Simple rollover menu element
/// Arguments: [id,options,looks]
/// output <div id="" class="" etc></div>
///</summary>
System.Web.UI.MenuItem = function(){ return {

				ID : null,
				Options : [],
				Looks : [],
				_Looks : [],
				_CssClass : null,
				_BackgroundColor : null,
				_Width : null,
				_Height : null,
				_Color : null,
				_Text : null,
				_Href : null,
				IsActive : false,
				IsClickable : false,
				Menu : null,
				DefaultLookID : null,
				RolloverLookID : null,
				PressedLookID : null,
				ActiveLookID : null,
				Image : null,
				RolloverImage : null,
				PressedImage : null,
				ActiveImage : null,
				SourceImage : null,
				Alt : "",
				///<summary>
                ///	sets the css class
                ///</summary>
				SetCssClass : function(cls)
				{
				    this.DefaultLookID = null;
				    this._CssClass = cls;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetCssClass : function()
				{
				    return this._CssClass;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetWidth : function(value)
				{
				    this._Width = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetWidth : function()
				{
				    return this._Width;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetHeight : function(value)
				{
				    this._Height = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetHeight : function()
				{
				    return this._Height;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetBackgroundColor : function(value)
				{
				    this._BackgroundColor = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetBackgroundColor : function()
				{
				    return this._BackgroundColor;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetColor : function(value)
				{
				    this._Color = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetColor : function()
				{
				    return this._Color;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetText : function(value)
				{
				    this._Text = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetText : function()
				{
				    return this._Text;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetHref : function(value)
				{
				    this._Href = value;
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetHref : function()
				{
				    return this._Href;
				},
				///<summary>
                ///	sets the css class
                ///</summary>
				SetLooks : function(value)
				{
				    this._Looks = value;
				    this.ApplyLooks();
				},
				///<summary>
                ///	returns the css class
                ///</summary>
				GetLooks : function()
				{
				    return this._Looks;
				},
				///<summary>
                ///	returns the default css class
                ///</summary>
				BuildCss : function()
				{			
				    if((this.IsActive)&&(this.ActiveLookID))
				    {	
				        if(this.ActiveLookID)
				        {
				            return this.Looks[this.ActiveLookID];
				        }
				    }
				    else if(this.DefaultLookID)
				    {
				            return this.Looks[this.DefaultLookID];
				    }
				        
				    if(this._CssClass)
				    {
				        return this._CssClass;
				    }
				},
				///<summary>
                ///	sets the style properties and link if available
                ///</summary>
	            ApplyOptions : function()
	            {
	            // there are 7 items in this object indexed as follows:
	                //CSS    -0
	                //Width  -1
	                //Height -2
	                //Color  -3
	                //BackgroundColor -4
	                //Text   -5
	                //Href   -6
	                var optlen = this.Options.length;
	              for(var i=0; i<optlen;i++)
	              {
	              var value = this.Options[i];
	              var hasvalue = (value && value.length>0);
	              if(value==true)
	                hasvalue = true;
	              if(value==false)
	                hasvalue = true;
	              if(hasvalue)
	              {
	                    switch(i)
	                    {
	                      case 0://CSS
	                            this._CssClass = value;
	                          break;
	                      case 1://Width
	                            this._Width = value;
	                          break;	                    
	                      case 2://Height
	                             this._Height = value;
	                         break;	   	                    
	                      case 3://Color
	                             this._Color = value;
	                         break;	  	                    
	                      case 4://BackgroundColor
	                             this._BackgroundColor = value;
	                         break;	 	                    
	                      case 5://Text
	                             this._Text = value;
	                         break;	 	                    
	                      case 6://Href
	                             this._Href = value;
	                         break;	 	                    
	                      case 7://ImageUrl
	                             this.Image = value;
	                         break;	 	                    
	                      case 8://RolloverImageUrl
	                             this.RolloverImage = value;
	                         break;	 	                    
	                      case 9://PressedImageUrl
	                             this.PressedImage = value;
	                         break;	 	                    
	                      case 10://ActiveImageUrl
	                             this.ActiveImage = value;
	                         break;		                    
	                      case 11://AlternateText
	                             this.Alt = value;
	                         break;	   
	                      case 12://IsClickable
	                           // alert(i + ": " + value);
	                            this.IsClickable = value;
	                         break;         
	                    }
	                }
	              }
	            },
				///<summary>
                ///	sets up the looks so that they are useable
                ///</summary>
	            ApplyLooks : function()
	            {	
	                var lvlen = 0;
	                if(this._Looks)        
	                    lvlen = this._Looks.length;
	                for(var i=lvlen-1;i>=0;i--)
	                {
	                    switch(i)
	                    {
	                        case 0://Default Look
	                                this.DefaultLookID = "DefaultLookID";
	                                this.Looks["DefaultLookID"] = this._Looks[i];
	                            break;
	                        case 1://Pressed Look
	                                this.PressedLookID = "PressedLookID";
	                                this.Looks["PressedLookID"] = this._Looks[i];
	                            break;	                    
	                        case 2://Rollover Look
	                                this.RolloverLookID = "RolloverLookID";
	                                this.Looks["RolloverLookID"] = this._Looks[i];
	                                break;
	                        case 3://Active Look
	                                this.ActiveLookID = "ActiveLookID";
	                                this.Looks["ActiveLookID"] = this._Looks[i];
	                            break;	                    
	                    }
	                }
	            },
				///<summary>
                ///	Applies the specified look to this element
                ///</summary>
	            ApplyLook : function(LookID)
	            {
	                if(this.ID)
	                {
	                    if(this.IsActive && this.ActiveLookID)
	                    {
	                       GetElement(this.ID).className = this.Looks[this.ActiveLookID]; 
	                       return;
	                    }
	                if(this.Looks[LookID])
				         GetElement(this.ID).className = this.Looks[LookID];
				    }
	            },
	            ///<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.Color)
	                    style[style.length] = this.Color + ";";
	                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("");
	            },  
				
				RenderControl : function(writer)
				{   
				    this.ApplyOptions();
				    this.ApplyLooks();
				    var cursorStyleOverride_Over = "";
				    var cursorStyleOverride_Out = "";
				    if(this.IsClickable)
				    {
				    cursorStyleOverride_Over = "this.style.cursor='pointer';";
				    cursorStyleOverride_Out = "this.style.cursor='default';";
				    }
				    writer[writer.length] = "<div id=\""+this.ID+"\" class=\""+this.BuildCss()+"\" "+this.GetStyle()+"";
				    writer[writer.length] = " onclick=\"window."+this.Menu.ID+".ItemClick('"+this.ID+"')\"";
				    writer[writer.length] = " onmouseover=\""+cursorStyleOverride_Over+"window."+this.Menu.ID+".ItemMouseOver('"+this.ID+"')\"";
				    writer[writer.length] = " onmousedown=\"window."+this.Menu.ID+".ItemMouseDown('"+this.ID+"')\"";
				    writer[writer.length] = " onmouseup=\"window."+this.Menu.ID+".ItemMouseUp('"+this.ID+"')\"";
				    writer[writer.length] = " onmouseout=\""+cursorStyleOverride_Out+"window."+this.Menu.ID+".ItemMouseOut('"+this.ID+"')\"";
				    writer[writer.length] = ">";
				    writer[writer.length] = this.Text?this.Text:"";
				    if(this.Image)
				    {
				        this.SourceImage = "_img"+this.ID;				        
				        if((this.IsActive)&&(this.ActiveImage))
				        {
				            writer[writer.length] = "<img id=\"_img"+this.ID+"\" src=\""+this.ActiveImage+"\" alt=\""+this.Alt+"\" />";				            
				        }
				        else
				        {
				            writer[writer.length] = "<img id=\"_img"+this.ID+"\" src=\""+this.Image+"\" alt=\""+this.Alt+"\" />";				            
				        }
				    }
				    writer[writer.length] = "<div>";
				},
				///<summary>
                ///	applies the looks to the rollover state
                ///</summary>
				MouseOver : function()
				{
				    if(this.CurrentLookID)
				        this.LastLookID = this.CurrentLookID;
				    this.CurrentLookID = this.DefaultLookID;
				    this.ApplyLook(this.RolloverLookID);
				    if(this.Image&&this.RolloverImage)
				    {
				        this.SetImage(this.RolloverImage);
				    }
				},
				///<summary>
                ///	applies the looks to the mousedown state
                ///</summary>
				MouseDown : function()
				{
				    if(this.CurrentLookID)
				        this.LastLookID = this.CurrentLookID;
				    this.CurrentLookID = this.PressedLookID;
				    this.ApplyLook(this.PressedLookID);
				    if(this.Image&&this.PressedImage)
				    {
				        this.SetImage(this.PressedImage);
				    }
				},
				///<summary>
                ///	applies the looks to the mouseup state
                ///</summary>
				MouseUp : function()
				{
				    if(this.CurrentLookID)
				        this.LastLookID = this.CurrentLookID;
				    this.CurrentLookID = this.DefaultLookID;
				    this.ApplyLook(this.DefaultLookID);
				    if(this.Image)
				    {
				        if(this.IsActive)
				        {
				            return;
				        }
				        this.SetImage(this.Image);
				    }
				},
				///<summary>
                ///	applies the looks to the mouseout state
                ///</summary>
				MouseOut : function()
				{
				    if(this.CurrentLookID)
				        this.LastLookID = this.CurrentLookID;
				    this.CurrentLookID = this.DefaultLookID;
				    this.ApplyLook(this.DefaultLookID);	
				    if(this.Image)
				    {
				        if(this.IsActive)
				        {
				            return;
				        }
				        this.SetImage(this.Image);				        
				    }			    
				},
				SetImage : function(url)
				{
				    GetElement(this.SourceImage).src = url;
				},
				///<summary>
                ///	navigates to the link applied to this control
                ///</summary>
				Click : function()
				{
				    if(this.IsActive && !this.IsClickable)
				        return;
				    if(this._Href)
				    {
				        window.location = this._Href;
				    }
				},
				Cotr : function()
				{				
					
                switch(arguments[0].length)
                {
                    case 1 : this.ID = arguments[0][0]; break;
                    case 2 : this.ID = arguments[0][0]; this.Options = arguments[0][1]; break;
                    case 3 : this.ID = arguments[0][0]; this.Options = arguments[0][1]; this._Looks = arguments[0][2]; break;                    
                    case 4 : this.ID = arguments[0][0]; this.Options = arguments[0][1]; this._Looks = arguments[0][2]; this.IsActive = arguments[0][3]; break;
                    case 5 : this.ID = arguments[0][0]; this.Options = arguments[0][1]; this._Looks = arguments[0][2]; this.IsActive = arguments[0][3]; this.Menu = arguments[0][4]; 
                   
                     break;
                 }
                 return this;
				}
				
				
				
}.Cotr(arguments);}

