I have a problem which I can't figure out myself! I'm trying to swap images on hovering with another image. The problem however is that the images are called/loaded dynamically from a Json call. Inside that JSON call I need to create some sort of variable to use outside that JSON call so I can swap the image.
I think I can manage to swap the images myself but right now I'm having trouble to create a variable which can be used outside the getJSON call. In my case how can I use iHover image in var productHtml?? 
II thought returning iHover would do the trick but that isn't!! Right now iHover returns a blank string or when using [] a blank array. 
Any help??
My jQuery
 $.getJSON(url, function (data){
   ... stuff ... 
     $.each(product.related, function(index, rel){
       ... stuff ...
         var image = 'http://cdn.webshopapp.com/i/' + image_id_convert(rel.image) + '/100x150x2/image.jpg'; // this is the main image!!
          var iHover = '';           
            $.getJSON(url, function (data){
              var image2 = rel.images[1]; // this needs to be the second image in the json file
              var image2Pic = 'http://cdn.webshopapp.com/i/' + image_id_convert(image2) + '/100x150x2/image.jpg'; // this is needed to convert a string to an actual link!!
             ... more stuff ...
              });
              iHover = image2Pic;
              return iHover;
            });
            var productHtml = '<img class="rollover" src="'+image+'" data-alt-src="'+iHover+'" alt="'+rel.fulltitle+'"/>';
 
     
    