function JSMove( offset )
{
	// check that previous
	// action do not still run
	if( in_process )
	{
	    return;
    }

    // set "run" status
    // we will release it
    // only after housekeeping
    // when script configure all DOM elements
    in_process = 1;

	current_pos = current_pos + offset;
    if( current_pos > total_size )
    {
    	current_pos = 1;
    }
    else if( current_pos < 0 && (current_pos * -1) >= (total_size-1) )
    {
    	current_pos = 1;
    }

    if( offset < 0 )
    {    	ApplyJSMoveLeft();
    	//$("#dis1").slideUp("fast", function() { HouseKeepingMoveUp(); });
        $("#dis1").animate({"left": "-=100px"}, "fast", function() { HouseKeepingMoveLeft(); });
    }
    else
    {    	ApplyJSMoveRight();
    	//$("#dis0").slideDown("fast", function() { $("#clr0").show(); $("#nlc0").show(); HouseKeepingMoveDown(); });
    	$("#dis0").animate({"left": "+=100px"}, "fast", function() { HouseKeepingMoveRight(); });
    }
}

function ApplyJSMoveLeft()
{
	next_num = getFirstNumberByPosition( current_pos );
	if( current_pos >= 1 )
	{		for( var i = 1; i < show_size; i++ )
	    {
	        next_num = getNextNumberByPosition( next_num );
	    }	}

    var nxt_show_size = show_size + 1;

    $("#dis"+show_size).after( "<div id=\"dis" + nxt_show_size + "\" style=\"display:none;float:left;\">" );
    $("#dis"+nxt_show_size).empty();
    $("#dis"+nxt_show_size).html( '' + $("#"+'pos'+next_num).html() + '' );
    $("#dis"+nxt_show_size).show();
}

function HouseKeepingMoveLeft()
{
    $("#dis1").remove();

    var j = 0;
    for( i = 1; i <= show_size; i++ )
    {
    	j = i + 1;
    	$("#dis"+j).attr( "id", "dis" + i );
    }

    in_process = 0;
}

function ApplyJSMoveRight()
{
	next_num = getFirstNumberByPosition( current_pos );
	if( current_pos < 1 )
	{
		for( var i = 1; i < show_size; i++ )
	    {
	        next_num = getPrevNumberByPosition( next_num );
	    }
	}

    $("#dis1").before( "<div id=\"dis0\" style=\"display: none;\">" );
    $("#dis0").empty();
    $("#dis0").html( '' + $("#"+'pos'+next_num).html() + '' );
    $("#dis0").show();
}

function HouseKeepingMoveRight()
{
	var prv_show_size = show_size - 1;

    $("#dis"+show_size).remove();

    var j = 0;
    for( var i = (show_size-1); i >= 0; i-- )
    {
    	j = i + 1;
    	$("#dis"+i).attr( "id", "dis" + j );
    }

    in_process = 0;
}

/*
function Round()
{
	for( var j = 1; j <= total_size; j++ )
	{
	}

	first_num = getFirstNumberByPosition( current_pos );
    num_str = 'pos' + first_num;

    next_num = first_num;
    for( var i = 1; i < total_size; i++ )
    {
        next_num = getNextNumberByPosition( next_num );
        num_str = 'pos' + next_num;
    }
}
*/

function getFirstNumberByPosition( pos )
{
	if( pos < 1 )
	{
		var r = (show_size + 1 - pos);
		if( r <= total_size )
		{			return r;		}
		else
		{			return (r - total_size);		}
	}
	else if( pos == 1 )
	{
		return pos;
	}
	else
	{
		return (total_size - pos + 2);
	}
}

function getNextNumberByPosition( pos )
{
	pos++;
	if( pos > total_size )
	{
		pos = 1;
	}

	return pos;
}

function getPrevNumberByPosition( pos )
{
	pos--;
	if( pos < 1 )
	{
		pos = total_size;
	}

	return pos;
}
