﻿GNgui.SliderMenu = Class.create();
GNgui.SliderMenu.prototype = 
{
    initialize : function (Id, Parent, Width, Height, Closes, CloseFunction)
    {
        this.ClosingDir = Closes;
        this.CloseFunction = CloseFunction;
        this.Height = Height;
        this.Width = Width;
        
        this.body = document.createElement('div');
        this.body.BaseClass = this;
        this.body.setAttribute('id', Id);
        this.body.style.width = (Closes == 'left' || Closes == 'right' ) ? 0 : Width;
        this.body.style.height = (Closes == 'up' || Closes == 'down' ) ? 0 : Height;
        this.body.style.width = Width;
        this.body.style.height = Height;
        this.body.className = 'SliderMenuBody';
        this.body.style.visibility = 'hidden';
        this.body.style.overflow = 'hidden';
        Parent.appendChild(this.body);
        
        this.body.closer = document.createElement('img');
        this.body.closer.BaseClass = this;
        this.body.closer.setAttribute('id', Id + 'Image');
        this.body.closer.className = 'SliderMenuCloser';
        this.body.closer.src = './' + TARGET + '/images/slid_' + Closes + '.gif';
        this.body.closer.style.visibility = 'hidden';
        this.body.closer.onclick = this.Hide;
        Parent.appendChild(this.body.closer);
    },
    
    Show : function (cX, cY)
    {
        Parent = (this.BaseClass == null) ? this : this.BaseClass

        this.body.style.left = cX;
        this.body.style.top = cY;

        var _x = 0; var _y = 0;
        var _w = this.Width; var _h = this.Height;

        switch (this.ClosingDir)
        {
            case 'left':
                _x = parseInt(_w + cX);
                _y = parseInt(_h / 2  - 33 + cY);

                new GNgui.Animation (this.body.closer, cX, _y, 13, 67, 0, _x, _y, 13, 67, 100, true, 6, 300)
                new GNgui.Animation (this.body,        cX, cY,  0, _h, 0, cX, cY, _w, _h, 100, true, 6, 300)
                break;
            case 'right':
                _x = parseInt(cX - 13);
                _y = parseInt(_h / 2  - 33 + cY);

                new GNgui.Animation (this.body.closer, _x + _w, _y, 13, 67, 0, _x, _y, 13, 67, 100, true, 6, 300)
                new GNgui.Animation (this.body,        cX + _w, cY,  0, _h, 0, cX, cY, _w, _h, 100, true, 6, 300)
                break;
            case 'down':
                _x = parseInt(_w / 2  - 33 + cX);
                _y = parseInt(cY - 13);

                new GNgui.Animation (this.body.closer, _x, _y + _h, 67, 13, 0, _x, _y, 67, 13, 100, true, 6, 300)
                new GNgui.Animation (this.body,        cX, cY + _h, _w,  0, 0, cX, cY, _w, _h, 100, true, 6, 300)
                break;
            default:
                _x = parseInt(_w / 2  - 33 + cX);
                _y = parseInt(_h + cY);

                new GNgui.Animation (this.body.closer, _x, cY, 67, 13,  0, _x, _y, 67, 13, 100, true, 6, 300)
                new GNgui.Animation (this.body,        cX, cY, _w,  0,  0, cX, cY, _w, _h, 100, true, 6, 300)
        }
    },

    Hide : function ()
    {
        Parent = (this.BaseClass == null) ? this : this.BaseClass
        
        cX = parseInt(Parent.body.style.left);
        cY = parseInt(Parent.body.style.top);
        var _x = 0; var _y = 0;
        var _w = Parent.Width; var _h = Parent.Height;
        
        switch (Parent.ClosingDir)
        {
            case 'left':
                _x = parseInt(_w + cX);
                _y = parseInt(_h / 2  - 33 + cY);

                new GNgui.Animation (Parent.body.closer, _x, _y, 13, 67, 100, cX, _y, 13, 67, 0, false, 6, 300)
                new GNgui.Animation (Parent.body,        cX, cY, _w, _h, 100, cX, cY,  1, _h, 0, false, 6, 300)
                break;
            case 'right':
                _x = parseInt(cX - 13);
                _y = parseInt(_h / 2  - 33 + cY);

                new GNgui.Animation (Parent.body.closer, _x, _y, 13, 67, 100, _x + _w, _y, 13, 67, 0, false, 6, 300)
                new GNgui.Animation (Parent.body,        cX, cY, _w, _h, 100, cX + _w, cY,  1, _h, 0, false, 6, 300)
                break;

            case 'down':
                _x = parseInt(_w / 2  - 33 + cX);
                _y = parseInt(cY - 13);

                new GNgui.Animation (Parent.body.closer, _x, _y, 67, 13, 100, _x, _y + _h, 67, 13, 0, false, 6, 300)
                new GNgui.Animation (Parent.body,        cX, cY, _w, _h, 100, cX, cY + _h, _w,  1, 0, false, 6, 300)
                break;

            default:
                _x = parseInt(_w / 2  - 33 + cX);
                _y = parseInt(_h + cY);

                new GNgui.Animation (Parent.body.closer, _x, _y, 67, 13, 100, _x, cY, 67, 13, 0, false, 6, 300)
                new GNgui.Animation (Parent.body,        cX, cY, _w, _h, 100, cX, cY, _w,  1, 0, false, 6, 300)
        }

        if (Parent.CloseFunction != null) Parent.CloseFunction();
    }
}