﻿GNgui.Button = Class.create();
GNgui.Button.prototype = 
{
    initialize : function (Id, Parent, Position, Width, Text, Icon, Expandable, Accessibility, ClickEventFunc, TextAlign)
    {
        if (Accessibility == null) Accessibility = true;

        this.Obj = $ce('div');
            this.Obj.style.position = "absolute";
            this.Obj.style.top = Position * 24;
            this.Obj.setAttribute('id', Id);
            this.Obj.style.width = Width;
	        this.Obj.style.height = 24;
	        this.Obj.style.color = "#000000";
	        this.Obj.style.fontWeight = "bold";
	        this.Obj.style.fontFamily = "Arial";
	        this.Obj.style.fontSize = "14px";
	        this.Obj.style.backgroundImage = "url(./" + TARGET + "/Images/contextMenu/contextMenu_s_c.gif)";
            this.Obj.style.cursor = "hand";
            
            this.Obj.Expandable = Expandable;
            this.Obj.Accessibility = Accessibility;
            this.Obj.ClickEventFunc = ClickEventFunc;
        $ac(Parent, this.Obj);

        if ( Icon != null && TextAlign == 'Left')
        {
            this.Obj.cImage = $ce('Img');
                this.Obj.cImage.src = "./" + TARGET + "/Images/contextMenu/" + Icon;
                this.Obj.cImage.style.position = "absolute";
                this.Obj.cImage.style.left = 6;
                this.Obj.cImage.style.top = 4;
                this.Obj.cImage.style.width = 16;
                this.Obj.cImage.style.height = 16;
            $ac(this.Obj, this.Obj.cImage);
        }
        
        this.Obj.cText = $ce('span');
            this.Obj.cText.innerText = Text;
            this.Obj.cText.style.position = "absolute";
            this.Obj.cText.style.top = 5;
            switch (TextAlign)
            {
                case "Left":
                    this.Obj.cText.style.textAlign = "left";
	                this.Obj.cText.style.width = Width - (Expandable == true?18:6);
                    this.Obj.cText.style.left = (Icon != null) ? 25 : 6;
                break;
                case "Right":
                    this.Obj.cText.style.textAlign = "right";
                    this.Obj.cText.style.left = 0;
                break;
                default:
                    this.Obj.cText.style.textAlign = "center";
	                this.Obj.cText.style.width = Width  - (Expandable == true?24:12);
                    this.Obj.cText.style.left = 6;
            }
        $ac(this.Obj, this.Obj.cText);

        this.Obj.leftImg = $ce('img');
            this.Obj.leftImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_l.gif";
            this.Obj.leftImg.style.position = "absolute";
            this.Obj.leftImg.style.left = 0;
        $ac(this.Obj, this.Obj.leftImg);

        this.Obj.rightImg = $ce('img');
            this.Obj.rightImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_r" + (Expandable == true? "_e.gif":".gif"); 
            this.Obj.rightImg.style.position = "absolute";
            this.Obj.rightImg.style.left = Width - (Expandable == true?18:6);
        $ac(this.Obj, this.Obj.rightImg);
        
        if (Accessibility != null &&  Accessibility == false)
        {
            this.Obj.style.color = "#222222";
        }
        

        Event.observe ( this.Obj, 'mouseover', GNgui.Button.prototype.MouseOver.bindAsEventListener(this));    
        Event.observe ( this.Obj, 'mouseout',  GNgui.Button.prototype.MouseOut.bindAsEventListener(this));    
        Event.observe ( this.Obj, 'mousedown', GNgui.Button.prototype.MouseDown.bindAsEventListener(this));
        Event.observe ( this.Obj, 'mouseup',   GNgui.Button.prototype.MouseUp.bindAsEventListener(this));
        
        Event.observe ( this.Obj, 'click' , GNgui.Button.prototype.MouseClick.bindAsEventListener(this));
    },
    
    MouseOver : function ()
    {   this.Obj.style.backgroundImage = "url(./" + TARGET + "/Images/contextMenu/contextMenu_h_c.gif)";
        this.Obj.leftImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_h_l.gif";
        this.Obj.rightImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_h_r" + (this.Obj.Expandable == true? "_e.gif":".gif");},
    MouseOut : function ()
    {   this.Obj.style.backgroundImage = "url(./" + TARGET + "/Images/contextMenu/contextMenu_s_c.gif)";
        this.Obj.leftImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_l.gif";
        this.Obj.rightImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_r" + (this.Obj.Expandable == true? "_e.gif":".gif");},
    MouseDown : function ()
    {   this.Obj.style.backgroundImage = "url(./" + TARGET + "/Images/contextMenu/contextMenu_o_c.gif)";
        this.Obj.leftImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_o_l.gif";
        this.Obj.rightImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_o_r" + (this.Obj.Expandable == true? "_e.gif":".gif");},
    MouseUp : function ()
    {   this.Obj.style.backgroundImage = "url(./" + TARGET + "/Images/contextMenu/contextMenu_s_c.gif)";
        this.Obj.leftImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_l.gif";
        this.Obj.rightImg.src = "./" + TARGET + "/Images/contextMenu/contextMenu_s_r" + (this.Obj.Expandable == true? "_e.gif":".gif");},
    MouseClick : function ()
    {
        if (this.Obj.Accessibility)
            if (this.Obj.ClickEventFunc != null) this.Obj.ClickEventFunc()  
    },
    
    Disable : function ()
    {
        this.Obj.Accessibility = false;
        this.Obj.style.color = "#222222";
    },

    Enable : function ()
    {
        this.Obj.Accessibility = true;
            this.Obj.style.color = "#000000";
    },

    GetID : function ()
        {return this.Obj.id;},
        
    SetTop : function (Top)
        {this.Obj.style.top = Top;},

    SetZOrder : function (Index)
        {this.Obj.style.zIndex = Index;}
}