Mattel to buy Canadian toy maker Mega Brands