Fade 4 Leds with delay

I try to fade 4 led with delay in this way:

When the first led reach 255 (max) must wait 2 seconds and after start to fade out. At the same time, when the first led fade out, the second led must start to fade on.... This loop must be repeat for the 4 leds.

The problem:

First led doesn't switch off completly, when the second fade on. The 3th led remain switch on at 255 value.... the 4th doesn't switch on at all.

this is the code that I'm using:

int brightness=0; 
int brightnessnext=0;
int change = 5; 
int changenext = 5; 
int ledact = 3; 
int lednext = 0; 
int ledchange = 1; 
int ledactcompletefadeon = 0;
int lednextcompletefadeon = 1;
int ledactfadeout = 0;
int lednextfadeout = 1;
int p = 0;
int x = 1;

void setup()
{
  pinMode(10,OUTPUT); 
  pinMode(3,OUTPUT); 
  pinMode(5,OUTPUT); 
  pinMode(6,OUTPUT);
}

int main()
{
  init();
 int i, pin[4] = { 3, 5, 6, 10};
  while (x < 10) {
  
  if (lednextcompletefadeon == 1 || ledactfadeout == 0){
     analogWrite(ledact, brightness); 
     brightness = brightness + change;
    }	 

  if (brightness == 255){ 
    delay(2000);
	lednextfadeout = 0;
    change=-change;       
    p = p +1;
    if (p==4) {
      p =-1;
    }
    lednext = pin[p]; 
    ledactcompletefadeon = 1;
  }
  
  if (ledactcompletefadeon == 1 || lednextfadeout == 0){
    analogWrite(lednext, brightnessnext);
    brightnessnext = brightnessnext + changenext; 
	
   }	
  if (brightnessnext == 255){ 
	delay(2000);
    ledactfadeout = 0;
    changenext=-changenext;     
    p = p +1;
     if (p==4) {
      p =-1;
      }
    ledact = pin[p];
    lednextcompletefadeon = 1;
  }
	
  if (brightness == 0){            
    analogWrite(ledact,0);      
	change=-change;              
	ledactfadeout = 1;
	ledactcompletefadeon = 0;
  }

  if (brightnessnext == 0){            
    analogWrite(lednext,0);       
	changenext=-changenext;              
	lednextfadeout = 1;
	lednextcompletefadeon = 0;
  }
  
  delay(30);              

  } 
  return 0;
 }

Could you help me to fix it?

Thank you in advance
Best Regards,
Marco

Cross-posting.
http://forum.arduino.cc/index.php?topic=278971.msg1961477#msg1961477

I close here...