if (window.Product && window.Product.Zoom) {
	var toggleFull = Product.Zoom.prototype.toggleFull.toString ();
	eval ("Product.Zoom.prototype._toggleFull = " + toggleFull);
	Product.Zoom.prototype.toggleFull = function () {
		var img = $(this.containerEl).down ("img");
		var w = img.width + 120;
		var h = img.height + 120;
		w = (w > 640) ? 640 : w;
		h = (h > 640) ? 640 : h;
		var html = "<html><body><img src='" + $(this.containerEl).down ("img").src + "'/></body></html>";
		objPopWin = popWin ("about:blank", 'gallery', 'width=' + w + ',height=' + h + ',left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); 
		objPopWin.document.open();
		objPopWin.document.write (html);
		objPopWin.document.close();
		return this;
		/*
		this._toggleFull ();
		if (this.showFull)  {
			this.containerEl.style.position = "absolute";
			this.containerEl.style.zIndex = 9999;
			this.containerEl.style.border = "1px solid black";
		}
		else {
			this.containerEl.style.position = "";
			this.containerEl.style.zIndex = 9999;
			this.containerEl.style.border = "";
		}
		*/
	}
}

var objPopWin = null;
function popWin(url,win,para) {
	if (objPopWin != null && !objPopWin.closed) {
		objPopWin.close ();
	}
    objPopWin = window.open(url,win,para);
    objPopWin.focus();
	return objPopWin;
}

function CheckInventory (inventory) {
	if (inventory !== undefined && inventory.Quantity !== undefined) {
		var qty = parseInt (inventory.Quantity, 10);
		if (isNaN (qty)) {
			qty = 0;
			return;
		}
		var form = $("product_addtocart_form");
		if (qty < 1) {
			form.select(".availability span").each (
				function (obj, i) {
					obj.update ("Out of stock");
				}
			)
			form.select("div.add-to-cart").each (
				function (obj, i) {
					obj.hide ();	
				}
			)
			form.select("span.or").each (
				function (obj, i) {
					obj.hide ();	
				}
			)
		}
		else {
			form.select(".availability span").each (
				function (obj, i) {
					if (qty == 1) {
						obj.update ("Only 1 left in stock.");
					}
					else {
						obj.update ("~" + qty + " left in stock.");
					}
				}
			)
		}
	}
}
