//javascript functions for building the mini active lightbox and refreshing it

var maxImgLength = 36;

function loadLBImages()
{
	updateLBImage(getImgObj('LBPreview1'), 0);
	updateLBImage(getImgObj('LBPreview2'), 1);
	updateLBImage(getImgObj('LBPreview3'), 2);
	updateLBImage(getImgObj('LBPreview4'), 3);
	updateLBImage(getImgObj('LBPreview5'), 4);
	updateLBImage(getImgObj('LBPreview6'), 5);
}

function getImgObj(Elem)
{	
  if(document.getElementById) {
  	var imgObj = document.getElementById(Elem);
  } else if (document.all){
  	var imgObj = document.all[Elem];
  }
	return imgObj;
}

function updateLBImage(img, indexnum)
{
	
	if (myLBItems[indexnum]) {
  	imageID = myLBItems[indexnum][0];
  	imageType = myLBItems[indexnum][1];
  	//alert(imageType)
	if (imageID) {
    	var last2 = imageID.substring(imageID.length-2, imageID.length);
    	var nextlast2 = imageID.substring(imageID.length-4, imageID.length-2);
    	var URL;
    	if(imageType == 77 || imageType == 158) {
    		URL = 'http://images.jupiterimages.com/cd/thumb-xs/' + last2 + '/' + nextlast2 + '/' + imageID + '.jpg';
    	} else {
    		URL = 'http://images.jupiterimages.com/common/thumb-xs/' + last2 + '/' + nextlast2 + '/' + imageID + '.jpg';
    	}
        img.src = URL;
    	img.onLoad = updateLBImageSize(img);
		} else {
			img.src = "/images/ji/spacer.gif";
		}
	} else {  //no image, replace with the spacer
		img.src = "/images/ji/spacer.gif";
	}
	
}

function updateLBImageSize(img)
{
	if (img.width > img.height) {
			img.height = Math.round(maxImgLength * (img.height / img.width));
			img.width = maxImgLength;
	} else {
			img.width = Math.round(maxImgLength * (img.width / img.height));
			img.height = maxImgLength;
	}
	if (img.height == 0) {
		img.height = maxImgLength;
	}
	if (img.width == 0) {
		img.width = maxImgLength;
	}
}
