pass an image url to a variable from an block from a stack

Permalink
$stack = Stack::getByName("slider");
$blocks = $stack->getBlocks();
foreach($blocks as $block) {
$vari=$block->getBlockPath(); //display the newly sorted blocks

echo $vari;
}
$imgurl = "/application/themes/abc/images/backgrounds/image1.jpg";
?>

I want to pass the image url to a variable then pass it further to javascript. I have this code until now. any ideas? thx