push button with fading LEDs

Hi! I am new to arduino and programming in general and I was hoping someone might be able to help me out. I have set up a button with 3 LEDs and I am trying to make it change with each push of the button. This works fine for turning the LEDs on and off but I want to also have one the will set them into a fading routine. I have the code written for both but I can’t make the fading routine stop with the push of a button. Is there a way I can program it as a subroutine or make it so that it will check the button to see if it should move on to the next?

Here is the code for the push button with 3 LEDs

int led = 9;
int led2 = 10;
int led3 = 11;// led light
int button = 2; //push button
int val = 0; //variable for pushbutton
int oldval = 0; //previous vale of pushbutton
int state = 0; //state is a variable either 1 or 0

void setup() {
pinMode (led, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (button, INPUT);
}

void loop() {
val = digitalRead(button); //reads value of button
if ((val == HIGH) && (oldval == LOW)) { //makes sure that you are intending to change state
state = 1 + state; //not sure why but it works
delay(200); //delay so that there is time between val changing to oldval
}
oldval = val; //changes val to old val for next button push
if (state == 1) {
digitalWrite(led, HIGH);
digitalWrite(led2, LOW);
digitalWrite (led3, LOW);
}else if (state == 2)
{
digitalWrite(led2, HIGH);
digitalWrite(led, LOW);
digitalWrite (led3, LOW);

}
else if (state == 3){
digitalWrite(led2, LOW);
digitalWrite(led, LOW);
digitalWrite (led3, HIGH);

}
else if (state == 4) {
digitalWrite(led, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}

Here is where I want to insert the fading routine @ state ==5
else if (state == 6) {
digitalWrite(led2, LOW);
digitalWrite(led, LOW);
digitalWrite(led3, LOW);
state = 0;
}
}

here is the 3 fading LEDs code

int led1 = 9;
int led2 = 10;
int led3 = 11;
int y = 80; // greatest pulsewidth = brightest lights will get (max 255)
int x = 2;// must be a factor of y
int z = 20; //delay time
int i1 = 0;
int i2 = 0;
int i3 = y;
int i = 0;

void setup(){}

void loop()

{
i += x;
if (i <= y)
{
i1=0;
i2+=x;
i3-=x;
{
analogWrite (led1, i1);
analogWrite (led2, i2);
analogWrite(led3, i3);
delay(z);
}}
else if (i <= 2 * y)

{
i1+=x;
i2-=x;
i3=0;
{
analogWrite (led1, i1);
analogWrite (led2, i2);
analogWrite (led3, i3);
delay(z);
}
}
else if (i <= 3 * y)

{
i1-=x;
i2+=x;
i3=0;
{
analogWrite (led1, i1);
analogWrite (led2, i2);
analogWrite (led3, i3);
delay(z);
}
}
else if (i <= 4 * y)

{
i1=0;
i2-=x;
i3+=x;
{
analogWrite (led1, i1);
analogWrite (led2, i2);
analogWrite (led3, i3);
delay(z);
}
}
else { i=0;}

}

If anybody has any ideas I would really appreciate it.
Thanks!