var img_preloaded=new Array();
var ecatalog_block_interrupt = false;

function moveSlider2(wid, left_slider, right_slider, scroll_bar, initpos, timeout)
{
        if(this.scrol = document.getElementById(scroll_bar))
        {
        var re = new RegExp("gallery2_tree_media_", "g");
	
	var lslider = document.getElementById(left_slider);
	var rslider = document.getElementById(right_slider);
        this.timeout = timeout;
        this.initpos = initpos;
	this.wid = wid;
        this.const1 = Math.PI/this.wid;
        this.qwid = wid/10;
	this.curwid = 0;
	this.maxwidth = 0;
        this.imgct = 1;
        
	
                this.curwid = 0;
        
        this.scrol.onmouseover = function(){ecatalog_block_interrupt = true;}
        this.scrol.onmouseout = function(){ecatalog_block_interrupt = false;}
        
	this.initMaxWidth = function(count)
	{
		this.maxwidth = -1*(count*this.wid-2*this.wid);
	}

	this.left = function()
	{
			twid = this.curwid;
			this.curwid = this.curwid + this.wid;
			var self = this;
                        setTimeout(function(){self.moveLeft(twid);}, this.timeout);
	}
	
	this.right = function()
	{
			twid = this.curwid;
			this.curwid = this.curwid - this.wid;
                        var self = this;
                        setTimeout(function(){self.moveRight(twid);}, this.timeout);
	}
	
	this.moveRight = function(mov)
	{
		if(mov > this.curwid)
		{
			this.scrol.style.left = Math.ceil(mov+initpos)+'px';
			mov=this.moveFunction(mov, 'right');
			var self = this;
                        setTimeout(function(){self.moveRight(mov);}, this.timeout);
		}
		else
		{
			this.scrol.style.left = Math.ceil(this.curwid+initpos)+'px';
                        var elems = this.scrol.getElementsByTagName('table');
                        for(i = 0; i < elems.length;i++)
                        {
                                if(elems[i].className == 'picture_table')
                                {
                                        var obj = elems[i];
                                        break;
                                }
                        }
                        var firsttd = obj.getElementsByTagName('td')[0];
                        var lasttd = obj.getElementsByTagName('td')[(obj.getElementsByTagName('td').length)-1];
                        this.scrol.style.left = this.initpos+"px";
                        this.curwid = 0;
                        obj.getElementsByTagName('tr')[0].removeChild(firsttd);
                        obj.getElementsByTagName('tr')[0].appendChild(firsttd);

                        this.right();
		}
	}
	
	this.moveLeft = function(mov)
	{
		if(mov < this.curwid)
		{
			this.scrol.style.left = Math.ceil(mov+initpos)+'px';
			mov=this.moveFunction(mov, 'left');
			var self = this;
                        setTimeout(function(){self.moveLeft(mov);}, this.timeout);
		}
		else
		{
			this.scrol.style.left = Math.ceil(this.curwid+initpos)+'px';
		}
	}
        this.moveFunction = function(mov, pos)
	{
                if(ecatalog_block_interrupt == true)
                {
                        return mov;
                }
                else
                {
                        ddd = 1;
                        if(pos == 'left')
                        {
                                mov = mov+ddd;
                        }
                        else if(pos == 'right')
                        {
                                mov = mov-ddd;
                        }
                        return mov;
                }
	}
        
        }
        else
        {
                this.right = function(){return false;}
        }
}

