
/* teclan Javascript function to change
 dynamic product choice images within drop down layout  */
function updateMarshbeckChoiceImage(dropDown,productID,imagePos,imageList)  {
	
	var myindex  = dropDown.selectedIndex
    var SelValue = dropDown.options[myindex].value
	var SelName = dropDown.options[myindex].text;
	//retrieve image map
	var imageMap = getProdChoiceImageMap(imageList);
	//get image
	var selectedImageFile = getImageFileFromName(imageMap,SelName);
	//set the image
	var theDiv = document.getElementById(productID + imagePos);
	if (theDiv) {
		//change the div styles based on image
		var img = new Image();
		img.src = selectedImageFile;
		img.lowsrc = 'loading.gif';
		//check the image has been loaded
		waitFor(img);
		//set div to dimensions of image if outer image
		if ((imagePos == 'Outer') && (img.width > 0)) {
			theDiv.style.width = img.width + 'px';
			theDiv.style.height = img.height + 'px';
		}
		//change image src
		theDiv.style.backgroundImage = "url('" + img.src + "')";
		theDiv.style.backgroundPosition = "center center";
		theDiv.style.backgroundRepeat = "no-repeat";

	}
}


function waitFor(img){
if(!img.complete){
		imgWait=setTimeout('waitFor(' + img + ')', 250);
	}
	else{
	// Code to execute on completion of download
		return true
	}
} 
/* Method retrieves the global variable 
ProdChoiceImageMap
and returns 2-d array of image/file name */
function getProdChoiceImageMap(imageList) {
	
	//check if we have any data to parse
	if (imageList != '') {
		//first split into temp array
		var tempMap = imageList.split(",");
		//create image map array
		var imageMap = new Array(tempMap.length);
		//split and populate array
		for(var i=0; i < tempMap.length; i++) {
			//and newster array into array
			imageMap[i] = new Array(2);
			//split contents into map
			var arr = tempMap[i].split("=");
			for (var x=0; x < arr.length;x++) {
				imageMap[i][x] = arr[x];
			}
		}
	}
	return imageMap;
}



/* method to return image match from image match */
function getImageFileFromName(imageMap,imageName) {
	var imageFileName = "";
	if (imageName != "") {
	
		for (var i=0;i<imageMap.length;i++) {
			if (imageName == imageMap[i][0]) {
				imageFileName = imageMap[i][1];
				break;
			}
			else {
				imageFileName = "blank.jpg";
			}
		}
	}
	return imageFileName;
}





