driving home from work this afternoon and my car just cut out,there was no dash lights and no elec at all

,i had a jiggle of the wires by battery, got back in the car and it started.i managed to get home.now the car will start but every time i flash my head lights it cuts out and i have no elec at all again then all of a sudden the power will come back on,but every time i start it and flash my lights it cuts out and i lose my elec,its even the same if i run some jump leads to my batt off a running car

its ok with headlights on normal,any ideas please???cheers