Model of electrochromic and related phenomena in tungsten oxide thin films