var zoom;



var mImgList = new Array("home","cart","about","contact","account");
var mOutImg = new Array();
var mOverImg = new Array();
var i,j;

//load images

if(document.images) {
	for(i=0;i<mImgList.length;i++) {
		mOutImg[mImgList[i]] = new Image();
		mOutImg[mImgList[i]].src = "/_resources/americansurplus.com/images/menu/m_"+mImgList[i]+".png";
		mOverImg[mImgList[i]] = new Image();
		mOverImg[mImgList[i]].src = "/_resources/americansurplus.com/images/menu/m_"+mImgList[i]+"_on.png";
	}
}



function mOvr(img) {
	if(document.images && document.images[img]) {
		if(document.images[img].filters) { document.images[img].filters.blendTrans.apply(); }
		document.images[img].src = mOverImg[img].src;
		if(document.images[img].filters) { document.images[img].filters.blendTrans.play(); }
	}
}


function mOut(img) {
	if(document.images && document.images[img]) {
		if(document.images[img].filters) { document.images[img].filters.blendTrans.apply(); }
		document.images[img].src = mOutImg[img].src;
		if(document.images[img].filters) { document.images[img].filters.blendTrans.play(); }
	}
}



function LoadProductImage(handle,showloadingimage){
	
	var mainImageID = "myimage";
	var instructionsID = "ProductImageInstructions";
	var loadingImageSrc = "/_resources/americansurplus.com/images/ajax-loader.gif";
	var thumbWidth = 50;
	var thumbHeight = 50;
	var mainImageWidth = 250;
	var mainImageHeight = 250;
	var zoomImageWidth = 400;
	var zoomImageHeight = 400;	
	
	var imgSrc;
	var magnifySrc;	
	imgSrc = handle.src;
	imgSrc = imgSrc.replace("width="+thumbWidth,"width="+mainImageWidth);
	imgSrc = imgSrc.replace("height="+thumbHeight,"height="+mainImageHeight);
	magnifySrc = imgSrc;
	magnifySrc = magnifySrc.replace("width="+mainImageWidth,"width="+zoomImageWidth);
	magnifySrc = magnifySrc.replace("height="+mainImageHeight,"height="+zoomImageHeight);
	
	if(zoom){zoom.parentNode.removeChild(zoom);}
	
	if(showloadingimage){
		// -- if used in IE before main image is done loading, we get the '1 item loading' bug --- //
		var parentHandle = getElement(mainImageID).parentNode;
		parentHandle.removeChild(getElement(mainImageID));
	
		var imageLoading = new Image();
		imageLoading.onload = function() {
			imageLoading.onload = null;
		}
		imageLoading.src = loadingImageSrc;
		imageLoading.id = mainImageID;
	
		parentHandle.appendChild(imageLoading);
		// --- end IE bug --- //
	}
	
	var zoomImage = new Image();
	zoomImage.onload = function() {
		zoomImage.onload = null;
		var image = new Image();
		
		image.onload = function() {
			
			image.onload = null;
			getElement(mainImageID).src = imgSrc;
			zoom = MojoMagnify.makeMagnifiable(getElement(mainImageID),magnifySrc);
			
			// move stuff out of the way...
			var imageWidth;
			var imageHeight;
			var instructionsHeight;
			imageWidth = getElement(mainImageID).offsetWidth;
			imageHeight = getElement(mainImageID).offsetHeight;
			instructionsHeight = getElement(instructionsID).offsetHeight;
			if(imageWidth > 0){				
				getElement("ProductDetailLeft").style.width = imageWidth + "px";
			}	
			if(imageHeight > 0){	
				getElement("ProductMultipleImages").style.top = (imageHeight + instructionsHeight) + "px";
				getElement("ProductMultipleImages").style.display = "block";
			}
			
		};
		image.src = imgSrc;
		
	};
	zoomImage.src = magnifySrc;		
}

function getElement(name) {
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	return o1;
}