	function Variant(asin, img, variation, offers) {
		this.asin = asin;
		this.img = img;
		this.variation = variation;
		this.offers = offers;
		
		this.hasVariation = function(i, value) {
			if (this.variation[i] == value)
				return true;
			else
				return false;
		}
	}
	
	function Offer(merchant, condition, price, availability, listingID) {
		this.merchant = merchant;
		this.condition = condition;
		this.price = price;
		this.availability = availability;
		this.listingID = listingID;
	}
	
	function ProductPanel(variants, variations, details) {
		this.variants = variants;
		this.variations = variations;
		this.details = details;
		this.cur_Variants = new Array(); //?????????????
		this.cur_Variations = new Array();
		this.cur_Offer = 0;
		
		for (i in this.variations)
			this.cur_Variations.push(false);
		
		this.moreInfo_html = function(i) {
			var html = "<div class=\"alert\">Please select styles.</div>";
			for (i in this.variations) {
				html += "<strong>" + this.variations[i] + ": </strong>";
				if (this.cur_Variations[i]) {
					html += this.cur_Variations[i];
				}
				else {
					html += "<select name=\"" + i + "\" onchange=\"thisPanel.updateVariations(this.name, this.options[this.selectedIndex].value)\"><option selected=\"selected\">Select a " + this.variations[i] + ":</option>";
					var opts = this.determineOptions(i);
					for (var j in opts) {
						html += "<option value=\"" + opts[j] + "\">" + opts[j] + "</option>";
					}
					html += "</select>";
				}
				html += "<br />";
			}
			html += "<a href=\"#\" onclick='thisPanel.reset()' style=\"font-size: 9px;\">Reset styles</a>.";
			return html;
		}
		
		this.determineOptions = function(i) {
			var opts = new Array();
			for (var j in this.cur_Variants) {
				var variant = this.cur_Variants[j];
				if (!this.inArray(variant.variation[i], opts))
					opts.push(variant.variation[i]);
			}
			return opts;
		}
		
		this.inArray = function(needle, haystack) {
			for (i in haystack) {
				if (haystack[i] == needle)
					return true;
			}
			return false;
		}
		
		this.needMore = function() {
			
			for (var i in this.cur_Variations) {
				if (this.cur_Variations[i] == false)
					return true;
			}
			return false;
		}
		
		this.needWhat = function() {
			for (var i in this.cur_Variations) {
				if (this.cur_Variations[i] == false) {
					return i;
				}
			}
		}
		
		this.updateVariations = function(i, value) {
			this.cur_Variations[i] = value;
			this.updateView();
			this.updatePricing();
		}
		
		this.updateVariants = function() {
			this.cur_Variants = new Array();
			for (var i in this.variants) {
				var variant = this.variants[i];
				if (this.variantConforms(variant)) {
					this.cur_Variants.push(variant);
				}
			}
		}
		
		this.variantConforms = function(variant) {
			var varMatch = true;
			for (var j in this.variations) {
				var cur_Var = this.cur_Variations[j];
				var var_Var = variant.variation[j];
				if ((cur_Var) && (cur_Var != var_Var))
					varMatch = false;
			}
			return varMatch;
		}
		
		this.reset = function() {
			this.cur_Variations = new Array();
			for (i in this.variations)
				this.cur_Variations.push(false);
			this.cur_Offer = 0;
			this.updateView();
			this.updatePricing();
			}
		
		this.showInfo = function() {
			if (this.cur_Variants[0].offers.length > 0) {
				var html = "<strong>Availability: </strong>" + this.cur_Variants[0].offers[this.cur_Offer].availability + "<br />";
				for (i in this.variations) {
					html += "<strong>" + this.variations[i] + ": </strong>" + this.cur_Variations[i] + "<br />";
				}
				html += "<a href=\"#\" onclick='thisPanel.reset()' style=\"font-size: 9px;\">Reset styles</a>.";
				if (this.cur_Variants[0].img != 'Unknown') {
					document.images['productImage'].src = this.cur_Variants[0].img;
				}
			}
			else {
				var html = "<div class=\"alert\">This item is unavailable.</div>";
			}
			return html;
		}
		
		this.updateView = function() {
			this.updateVariants();
			if (this.needMore()) {
				document.getElementById('details').innerHTML = this.moreInfo_html();
			}
			else {
				document.getElementById('details').innerHTML = this.showInfo();
			}
		}
		
		this.updatePricing = function() {
			if (this.needMore()) {
				var html = "<tr><td><span class=\"alert\">Please select styles.</span></td></tr>";
				document.getElementById('purch').innerHTML = html;
			}
			else {
				document.getElementById('purch').innerHTML = this.pricing_html();
			}
		}
		
		this.pricing_html = function() {
			if (this.cur_Variants[0].offers.length > 0) {
				var offer = this.cur_Variants[0].offers[this.cur_Offer];
				
				var html = "<table><tr><td class=\"price_label\">Price: <br /><span style=\"font-size: 9px; color: #000000;\">" + offer.condition + " from " + offer.merchant + "</span></td><td class=\"price_tag\">" + offer.price + "</td></tr><tr><td colspan=\"2\" class=\"offer_column\"><div id=\"cartbtn\"><a href=\"shoppingCart.php?add=" + offer.listingID + "\"><img src=\"images/addtocart.gif\" alt=\"\" title=\"\" /></a></div>";
				if( this.cur_Variants[0].offers.length > 1 ) {
					html += "Other offers: <table id=\"offers\" cellpadding=\"3\" cellspacing=\"0\">";
					for( var i in this.cur_Variants[0].offers ) {
						if( i != this.cur_Offer ) {
							var off = this.cur_Variants[0].offers[i];
							html += "<tr onclick=\"thisPanel.setOffer(" + i + ")\" onmouseover=\"this.style.background = '#FFFFFF url(images/offer_bg.jpg) repeat-x top'\" onmouseout=\"this.style.background = '#FFFFFF none'\" style=\"cursor: pointer;\"><td>" + off.merchant + "</td><td>" + off.condition + "</td><td>" + off.price + "</td></tr>";
						}
					}
					html += "</table>";
				}
				html += "</td></tr></table>";
			}
			else {
				var html = "<div class=\"alert\">Unavailable.</div>";	
			}
			return html;
		}
		
		this.setOffer = function(i) {
			this.cur_Offer = i;
			this.updateView();
			this.updatePricing();
		}
	}
