function kkloadImage(id,url,maxWidth,maxHeight)
{
  var oImg = new Image();

  oImg.onload = function () {

  var ratio = (oImg.width/oImg.height);
  var newWidth = 0;
  var newHeight = 0;

  if(oImg.width > maxWidth || oImg.height > maxHeight)
  {
    if(ratio == 1)
    {
      if(maxWidth >= maxHeight)
      {
        newWidth = maxHeight;
        newHeight = maxHeight;
      } else {
        newWidth = maxWidth;
        newHeight = maxWidth;
      }
    } else if(ratio > 1) {
       if (oImg.height >= maxHeight )
       {
         newWidth = Math.floor(maxHeight * ratio);
         newHeight = maxHeight;
       } else {
         newWidth = maxWidth;
         newHeight = Math.floor(maxWidth / ratio);
       }
    } else {
      newWidth = Math.floor(maxHeight * ratio);
      newHeight = maxHeight;
    }
  } else {

    newWidth = oImg.width;
    newHeight = oImg.height;
  }

  document.getElementById(id).width = newWidth;
  document.getElementById(id).height = newHeight;
  document.getElementById(id).src = oImg.src;

  }
  oImg.src = url;
}

function updateAllLoaderImages(activeview)
{
  var loaders =$('img.loader');
  for(var x = 0; x < loaders.length; x++)
  {
    if(activeview == 'list')
    {
      kkloadImage(loaders[x].id,loaders[x].title,40,40);
    }
    else
    {
      kkloadImage(loaders[x].id,loaders[x].title,188,134);
    }
    loaders[x].title = '';
  }
  var loaders = $('img.shoploader');
  for(var x = 0; x < loaders.length; x++)
  {
    kkloadImage(loaders[x].id,loaders[x].title,115,15);
    loaders[x].title = '';
  }
};

