Add a handler on click on image and funcs to updown:
function goUp() {
$("#animate").animate({
top: 0
}, 5000, function() {
setTimeout(goDown, 50);
});
}
function goDown() {
$("#animate").animate({
top: height
}, 5000, function() {
setTimeout(goUp, 50);
});
}
$("#animate").on('click',function(){$('#animate').stop();
if(upleft == 0)
{goDown(); upleft=1;}
else {goLeft();upleft=0}
})