its really hard to read that code and explain plan.

format your code, using the [ code ] and [ /code ] tags (no spaces)