A variational approach in magnetofluid dynamics