function VPA_vscroller(name,current_cell_index,show_cells)
{
    this.singleton_name=name;
	this.name=name;
	this.show_cells=show_cells;
	this.offset=0;
	this.timer=null;
	this.obj=document.getElementById(this.name);
	this.scroll_obj=this.obj.getElementsByTagName('table')[0];
	this.scroll_obj_left=this.scroll_obj.offsetLeft;
	this.cells=this.scroll_obj.rows[0].cells.length;
	this.cell_first=this.scroll_obj.rows[0].cells[0];
	this.cell_last=this.scroll_obj.rows[0].cells[this.cells-1];
	this.current_cell_index=current_cell_index;
    if (this.obj.className)
    {
        this.current_cell_index=(this.obj.className<this.cells-4) ? this.obj.className : this.obj.className-4;
    }
    this.cell_current=this.scroll_obj.rows[0].cells[this.current_cell_index];
	this.left_link=this.obj.rows[0].cells[0].getElementsByTagName('a')[0];
	this.left_link.setAttribute('obj', this.singleton_name);
	this.right_link=this.obj.rows[0].cells[2].getElementsByTagName('a')[0];
	this.right_link.setAttribute('obj', this.singleton_name);

	this.set_cell=function (cell,fast)
	{
		if (cell>=0 && this.cells-cell>=this.show_cells)
		{
            this.current_cell_index=cell;
			this.cell_current=this.scroll_obj.rows[0].cells[this.current_cell_index];
			this.left=-this.cell_current.offsetLeft;
			this.offset=parseInt(this.scroll_obj.style.left.replace(/px/i,''));
            if (fast==1)
            {
                //alert (this.scroll_obj.style.left+','+this.left);
                this.offset=this.left;
                this.scroll_obj.style.left=this.left+'px';
            }
            else
            {
                this.slow_motion();
            }
		}
	}
    
	this.slow_motion=function ()
	{
		this.timer=window.setInterval(function () {
            this.make_timer();
            }.bind(this),15);
	}

	this.make_timer=function()
	{
        if (Math.abs(this.offset-this.left)>=3)
		{
			var desc=(this.offset-this.left>=0) ? 3 : -3;
			this.offset-=desc;
			this.scroll_obj.style.left=this.offset+'px';
		}
		else
		{
			window.clearInterval(this.timer);
		}
	}

	this.left_link.onclick=function ()
	{
		this.set_cell(this.current_cell_index-1,0);
		return false;
	}.bind(this);

	this.right_link.onclick=function ()
	{
		this.set_cell(this.current_cell_index+1,0);
		return false;
	}.bind(this);

	this.set_cell(this.current_cell_index,1);
}

VPA_vscroller.prototype.toString=function() { return 'Object VPA_vscroller\n\nDeveloped by Andrey Pahomov (andrey.pahomov@gmail.com)';};

function vpa_gal_remove_file(obj,id)
{
	if(!id)id='gal_images';
    var tb=document.getElementById(id).getElementsByTagName('tbody')[0];
    var tr=obj.parentNode.parentNode;
    if (tb.rows[1]!=tr)
    {
        tb.removeChild(tr);
    }
}

function vpa_gal_add_file(id)
{
	if(!id)id='gal_images';
    var tb=document.getElementById(id);
    if (tb.rows.length>=11) return false;
    var cl=tb.rows[1];
    var ncl=cl.cloneNode(true);
    var lst=tb.rows[tb.rows.length-1];
    //lst.cells[1].className='display_on';
    tb.getElementsByTagName('tbody')[0].appendChild(ncl);
    tb.rows[tb.rows.length-1].getElementsByTagName('input')[0].value='';
}

function vpa_ajax_send_field(field_name,id,value)
{
    var ajax=new VPA_AJAX;
    //ajax.makeRequestPost('/index.php','get_status','type=my_gallery&action=set_abstract&value='+value+'&field='+field_name+'&id='+id);
    ajax.makeRequestPost('/index.php','get_status','type=my_gallery&action=set_abstract&value='+value+'&field='+field_name+'&id='+id);
}

function save_image_abstract(obj,id)
{
    p=obj.parentNode.parentNode.getElementsByTagName('textarea')[0];
    //t_obj=document.getElementById('info_form').getElementsByTagName('textarea')[0];
    vpa_ajax_send_field('abstract',id,p.value);
}

/**
* Подсветка фона поля зеленым цветом в случае успешного редактирования цены и красным в случае неуспешного
**/
function get_status(str)
{
    if (str==1)
    {
        p.style.backgroundColor='#1EE135';
        window.setTimeout(function() { this.style.backgroundColor='#FFFFFF'; }.bind(p),300);
    }
    else
    {
        p.style.backgroundColor='#F84222';
        window.setTimeout(function() { this.style.backgroundColor='#FFFFFF'; }.bind(p),1500);
    }
}
