//This page should be used when there are medium and large pictures

function selectItem(i) {
	if (document.addtocart.selection.selectedIndex == 0) {
		document.addtocart.selection.selectedIndex = i;
		}
	else {
		document.addtocart.submit();
	}
}

function confirm() {
	if (document.addtocart.quantity.value == "" || document.addtocart.quantity.value == "0") {
		var a = "problem";
	}
	if (document.addtocart.color.type == "select-one") {
		if (document.addtocart.color.selectedIndex == 0) {
			var a = "problem";
		}
	}
	if (document.addtocart.size.type == "select-one") {
		if (document.addtocart.size.selectedIndex == 0) {
			var a = "problem";
		}
	}
	if (a == "problem") {
		alert ("Please make a selection.");
		}
	else {
		document.addtocart.add.value = "yes";
		document.addtocart.submit();
	}
}

var d;
var h;
var folder;
var mediumLength;
var newImages = new Array();
var newFolders = new Array();
var image = new Array();
var originalPicture;
var suffix;

function initialize(designerID,mediumString,largeString,width,length,j) {
	originalPicture = document.picture.src;
	folder = j;
	suffix = (folder == "line") ? ".jpg" : folder + ".jpg";
	var tempA = mediumString.split(",");
	mediumLength = tempA.length;
	h = mediumLength-1;
	var tempString = mediumString + ',' + largeString;
	var tempArray = tempString.split(",");
	var	arrayLength = tempArray.length;
	for (var i = 0; i <= arrayLength - 1; i++) {
		if (tempArray[i] != "") {
			image[i] = new Image(width,length);
			if (tempArray[i] == "noPhoto") {
				newImages[i] = "noPhoto";
				newFolders[i] = "";
				image[i].src = "/images/noPhoto.jpg";
				}
			else {
				var temp = tempArray[i].split(":");
				newImages[i] = temp[1];
				if (designerID < 10) {
					newFolders[i] = "wa00" + designerID + temp[0];
					}
				else if (designerID < 100) {
					newFolders[i] = "wa0" + designerID + temp[0];
					}
				else {
					newFolders[i] = "wa" + designerID + temp[0];
				}
				image[i].src = "/pictures/" + newFolders[i] + "/" + folder + "/" + newImages[i] + suffix;
			}
		}
	}
}

//General color select, picture swapping function, the index of the current selection is passed back to the page via the variable d
function swapImages(i){
	if (i.selectedIndex != '0') {
		var b = i.selectedIndex - 1;
		if (newImages[b] == "noPhoto") {
			document.picture.src = "/images/noPhoto.jpg";
			}
		else {
			document.picture.src = "/pictures/" + newFolders[b] + "/" + folder + "/" + newImages[b] + folder + ".jpg";
		}
	}
	d = b;
}

//Cycles through the entire array of pictures
var g = 0;
function zoomIn(i){
	g = (i == newImages.length-1) ? 1 : i + 1;
	document.picture.src = "/pictures/" + newFolders[g] + "/" + folder + "/" +  newImages[g] + folder + ".jpg";
}

//Cycles through the array of pictures in largeString, uses the h variable as the starting value, set in the initialize function
function zoomInNew(i){
	h = (i == newImages.length-1) ? mediumLength : i + 1;
	document.picture.src = "/pictures/" + newFolders[h] + "/" + folder + "/" +  newImages[h] + folder + ".jpg";
}

//Zooms using pictures in the large field, number must match color list, uses first item when no selection has been made; if there is no color list, can be used with an item list, in which case the selected index is passed in variable i
function zoomSingleIn(i){
	var c = (document.addtocart.color.type == "select-one") ? document.addtocart.color.length - 1: ((typeof(i) == "undefined") ? 1 : i);
	var b = (typeof(d) == "undefined") ? 0 : d;
	document.picture.src = "/pictures/" + newFolders[c+b] + "/" + folder + "/" +  newImages[c+b] + folder + ".jpg";
}

//Returns the main picture to its original after the zoomIn function, requires the photoshoot, folder and pictureID of the original picture
function zoomOut(photoshoot,folder,pictureID){
	if (folder == "line") {
		document.picture.src = "/pictures/" + photoshoot + "/line/" + pictureID + ".jpg";
		}
	else {
		document.picture.src = "/pictures/" + photoshoot + "/" + folder + "/" + pictureID + folder + ".jpg";
	}
}

//Returns the main picture to the select color, used in conjuctions with zoomSingleIn
function zoomOutNew(){
	var b = (typeof(d) == "undefined") ? 0 : d;
	if (newImages[b] == "noPhoto") {
		document.picture.src = "/images/noPhoto.jpg";
		}
	else {
		document.picture.src = "/pictures/" + newFolders[b] + "/" + folder + "/" + newImages[b] + folder + ".jpg";
	}
}

function zoomRollover(){
	document.zoom.src = "/images/zoom-over.gif";
}

//For use where popup pictures are different than pictures viewed on page.  Requires length of mediumString and position of current color selection
function popup(e,d){
	newAddress = "/popup:expanded/" + newFolders[e+d] + "," + newImages[e+d] + "," + folder + "/";
	vindu(newAddress,'',420,420)
}