I moved the javascript code from index.php to file header.php (between <head> and </head> tags) of the template Im using and everything works now.
Mmmm ….
if I include the javascript at the end of the file index.php it does not break the style, but the delay of the redirect is very big …