function Slide(slider_id, mode, animate_time, single_open)
{

        Slide.base_constructor.call(this);
        
        this.slider_set = false;

        if(typeof(slider_id) == "object")
                this.slider_set = true;

        this.elem_name = slider_id;
        
        this.current_dir = Array();
        this.wrapper = Array();
        this.end_size = Array();
        this.current_slider = -1;
        this.start_another = -1;

        if(mode == "horizontal")
                this.mode = "horizontal";
        else if(mode == "horisontal")
                this.mode = "horizontal";
        else if(mode == "vertical")
                this.mode = "vertical";
        else
                this.mode = "vertical";

        if(animate_time)
                this.animate_time = animate_time;

        this.single_open_currently = false;
        
        if(single_open == true)
                this.single_open = true;
        else
                this.single_open = false;

        this.index = Slide.instances.length;
        Slide.instances[this.index] = this;

        this.internal_index = 0;

        if(this.slider_set)
                for(var i = 0; i < slider_id.length; i++)
                        real_add_event(window, "load",
                                new Function("Slide.instances[" + this.index + "].init_hide(" + i + ");")
                        );
        else
                real_add_event(window, "load",
                        new Function("Slide.instances[" + this.index + "].init_hide();")
                );

}


Slide.instances = Array();

sputools.extend(Slide, fx);


Slide.prototype.add_event = function(event, _function)
{
        add_event(this.elem, event, _function)
};


Slide.prototype.init_hide = function(index)
{

        if(this.slider_set)
        {

                this.wrapper[index] = document.createElement('div');

                if(this.mode == "horizontal")
                {
//                        this.wrapper[index].style.width = "100%";
//                        this.end_size[this.elem_name[index]] =  $(this.elem_name[index]).offsetWidth;
                        this.end_size[this.elem_name[index]] =  "500";
                        this.wrapper[index].style.width = this.end_size[this.elem_name[index]] + "px";
                        $(this.elem_name[index]).style.width = this.end_size[this.elem_name[index]] + "px";
                }
                else
                {
                        this.end_size[this.elem_name[index]] =  $(this.elem_name[index]).offsetHeight + 20;
                        this.wrapper[index].style.height = 0 + "px";
                }

					var next = $(this.elem_name[index]).nextSibling;
					if(!next)
						$(this.elem_name[index]).parentNode.appendChild(this.wrapper[index]);
					else
						$(this.elem_name[index]).parentNode.insertBefore(this.wrapper[index], next);

                this.wrapper[index].appendChild( $(this.elem_name[index]) );

                this.wrapper[index].style.overflow = "hidden";
                $(this.elem_name[index]).style.display = 'none';
                                                
        }
        else
        {
/*
                this.wrapper[0] = document.createElement('div');

                if(this.mode == "horizontal")
                {
                        this.end_size[this.elem_name] =  "100";
                        this.wrapper[0].style.width = this.end_size[this.elem_name] + "%";
                        //$(this.elem_name).style.width = this.end_size[this.elem_name] + "%";
                }
                else
                {
                        this.end_size[this.elem_name] =  $(this.elem_name).offsetHeight ;
                        this.wrapper[0].style.height = "0px";
                        //$(this.elem_name).style.height = this.end_size[this.elem_name]+ "px";
                }

                $(this.elem_name).parentNode.appendChild(this.wrapper[0]);
                this.wrapper[0].appendChild( $(this.elem_name) );

                this.wrapper[0].style.overflow = "hidden";
                $(this.elem_name).style.display = 'none';
                $(this.elem_name).style.overflow = "hidden";
                $(this.elem_name).style.margin = '1px';
*/
        }

}


Slide.prototype.do_slide = function(index)
{

        if(this.animating[this.current_slider])
                return;

        if(this.current_dir[this.elem_name[this.internal_index]] == "out" && this.single_open_currently && this.single_open == true && this.slider_set == true)
        {
                this.start_another = index;
                this.current_slider = this.elem_name[this.internal_index];

                this.slide_in();
                return true;
        }
        else
                this.start_another = -1;

        if(this.is_animating == true)
                return;

        if(typeof(index) == "number")
        {
                if(this.slider_set == true)
                        this.current_slider = this.elem_name[index];
                else
                        this.current_slider = index;

                this.internal_index = index;

        }
        else
                this.current_slider = this.elem_name;

        if($(this.current_slider).style.display == "none")
                this.slide_out();
        else
                this.slide_in();

};


Slide.prototype.slide_out = function()
{

        if($(this.current_slider).style.display != "none")
                return true;

        this.is_animating = true;
        this.animating[this.current_slider] = true;
        this.current_dir[this.current_slider] = "out";
        this.single_open_currently = true;
        
        this.go_move(this.current_slider);
        
};


Slide.prototype.slide_in = function()
{

        if($(this.current_slider).style.display == "none")
                return true;

        this.is_animating = true;
        this.animating[this.current_slider] = true;
        this.current_dir[this.current_slider] = "in";
        this.single_open_currently = false;
        
        this.go_move(this.current_slider);

};



Slide.prototype.final_size = function(index)
{
                           /*
        if(this.mode == "horizontal")
        {

                if(this.slider_set)
                        this.end_size[index] = parseInt($(this.elem_name[index]).offsetWidth);
                else
                        this.end_size[0] = parseInt($(this.elem_name).offsetWidth);
        }
        else
        {


                alert(this.end_size[0]);

                if(this.slider_set)
                        this.end_size[index] = parseInt($(this.elem_name[index]).offsetHeight);
                else
                        this.end_size[0] = parseInt($(this.elem_name).offsetHeight);

        }         */

};


Slide.prototype.go_move = function()
{

        this.start_times[this.current_slider] = (new Date()).getTime();

        if(this.current_dir[this.current_slider] == "out")
                if(this.mode == "horizontal")
                        this.wrapper[this.internal_index].style.width = "0px";
                else if(this.mode == "vertical")
                        this.wrapper[this.internal_index].style.height = "0px";
						
        $(this.current_slider).style.display = "block";
        this.wrapper[this.internal_index].style.display = "block";

        this.timers[this.current_slider] = setInterval("Slide.instances["+ this.index +"].move_frame()", this.timer_length);

};


Slide.prototype.move_frame = function()
{

        var elapsed_time = (new Date()).getTime() - this.start_times[this.current_slider];

        if (elapsed_time  > this.animate_time)
                this.finish_move(this.current_slider);
        else
        {

                var d =Math.round(elapsed_time  / this.animate_time * this.end_size[this.current_slider]);

                if(this.current_dir[this.current_slider] != "out")
                        d = this.end_size[this.current_slider] - d;

                if(this.mode == "horizontal")
                {
                        this.wrapper[this.internal_index].style.width  = d + "px";
                        //$(this.current_slider).style.width = d + "px";
                }
                else if(this.mode == "vertical")
                {
                        this.wrapper[this.internal_index].style.height  = d + "px";
                        //$(this.current_slider).style.height = d + "px";
                }

        }

};


Slide.prototype.finish_move = function()
{

        clearInterval(this.timers[this.current_slider]);

        if(this.current_dir[this.current_slider] == "in")
		  {
                $(this.current_slider).style.display = "none";
        }
        else
                if(this.single_open == true && this.slider_set == true)
                        this.single_open_currently = true;

        if(this.current_dir[this.current_slider] == "out")
        {
        
	        if(this.mode == "horizontal")
	        {
	                //$(this.current_slider).style.width = this.end_size[this.current_slider] + "px";
						this.wrapper[this.internal_index].style.width = "100%";
	                this.end_size[this.current_slider] =  $(this.current_slider).offsetWidth;
						this.wrapper[this.internal_index].style.width = this.end_size[this.current_slider] + "px";
			  }
	        else
			  {
	               // $(this.current_slider).style.height = this.end_size[this.current_slider] + "px";
						this.end_size[this.current_slider] = "100%";
						this.end_size[this.current_slider] =  $(this.current_slider).offsetHeight;
						this.wrapper[this.internal_index].style.height = this.end_size[this.current_slider] + "px";
			  }
			  		
		}
		else
		{
		
			if(this.mode == "horizontal")
			{
			        //$(this.current_slider).style.width = "0";
						this.wrapper[this.internal_index].style.width = "0";
			}
			else if(this.mode == "vertical")
			{
			        //$(this.current_slider).style.height = "0px";
						this.wrapper[this.internal_index].style.height = "0px";
			}
			
		}
		
        this.is_animating = false;
        this.animating[this.current_slider] = false;
        this.current_slider = -1;

        delete(this.animating[this.current_slider]);
        delete(this.timers[this.current_slider]);
        delete(this.start_times[this.current_slider]);
        delete(this.end_size[this.current_slider]);
        delete(this.current_dir[this.current_slider]);

        if(this.start_another != -1 && this.start_another != this.internal_index)
        {
                this.do_slide(this.start_another);
        }

        this.start_another = -1;

};


