opsmile.store =
{
	"giftOfTheMonthId": "1821",
	"util":
	{
		"hdrImgs":
		{
			"cart": ["../assetsv2/store/images/cart-header.jpg", "Shopping Cart", "702", "86"],
			"addr": ["../assetsv2/store/images/addr-header.jpg", "Billing Address", "902", "87"]
		},
		"q": window.location.search,
		"qget": function(p)
		{
			var m = this.q.match(new RegExp("(\\?|\\&)("+p+")=([^\\&]+)(\\&|$)"));
			if (m)
			{
				return m[3];
			}
			else
			{
				return "";
			}
		},
		"addHdrImage": function(tgt, k)
		{
			var img = this.hdrImgs[k];
			tgt.prepend('<img src="'+img[0]+'" alt="'+img[1]+'" width="'+img[2]+'" height="'+img[3]+'" border="0"/>');
		}
	},
	"pageCode": "unk",
	"init": function()
	{
		this.initBreadCrumb();
	},
	"initLeft": function(appId)
	{
		var jqcm = jQuery("#fw_body_left"), jqc, ns, n, nn, price, i, c, m, id, pcst;
		if ((jqc = jQuery("table.ShoppingCart", jqcm)).length)
		// Shopping cart page
		{
			this.pageCode = "cart";
			this.util.addHdrImage(jqcm, "cart");
			jqc.css("border-collapse", "separate").attr("border", "0").attr("cellspacing", "0");
			ns = jQuery("tr", jqc);
			for (i = 0, c = ns.length; i < c; i++)
			{	
				n = ns.eq(i);
				if (n.get(0).className.match(/(^|\s)ShoppingCartRow[0-9]+(\s|$)/))
				{
					jQuery("input[type='text']", (nn = jQuery("td", n)).eq(0).addClass("col_qty")).addClass("text_qty");
					nn.eq(1).addClass("col_descr");
					nn.eq(4).addClass("col_price");
				}
				else
				{
					(nn = jQuery("td", n)).eq(0).addClass("col_label");
					nn.eq(1).addClass("col_amount");
				}
			}
		}
		else if ((jqc = jQuery("#ConfigureProduct")).length)
		// Item detail page
		{
			this.pageCode = "detail";

			/* Product "Config" area */
			id = this.util.qget("product_id");
			if (id == this.giftOfTheMonthId)
			{
				pcst = "Purchase this product";
			}
			else
			{
				pcst = "Choose your gift";
			}
			jQuery("div.ProductConfigSection", jqc).html(pcst);

			if (id == this.giftOfTheMonthId)
			{
				pcst = "Price:";
			}
			else
			{
				pcst = "Customize:";
			}
			(n = jQuery("p.ProductConfigLabel", jqc)).html(pcst);

			price = new Number((n = jQuery("p", n.parent().next())).html().replace(/[^0-9\.]/g, ""));
			if (id == this.giftOfTheMonthId)
			{
				pcst = "$"+price;
			}
			else
			{
				pcst = "Select your gift from item menu and indicate quantity below";
			}
			n.html(pcst);

			jQuery("table.ProductConfig tr", jqc).eq(0).addClass("header_row");

			/* Product "Config" menu */
			ns = jQuery("option", jqc);
			for (i = 0, c = ns.length; i < c; i++)
			{
				n = ns.eq(i);
				if (m = n.html().match(/\$([0-9\.]+)/))
				{
					n.html(n.html().replace(/\$[0-9\.]+/, "$"+(price + (new Number(m[1])))));
				}
				else
				{
					n.append(" - $"+price);
				}
			}

			/* Product "Full Description" area */
			jqc = jQuery("div.ProductLongDescription", jqcm);
			(n = jQuery("img", jqc)).eq(0).addClass("header");
			n.eq(1).addClass("product");
		}
		else if ((appId == "8") || (appId == "1") ||
		         ((jqc = jQuery("form[name='ShoppingCart']")).length))
		// Billing addr page
		{
			this.pageCode = "addr";
			jqcm.parent().addClass("store_container_onecol");
			this.util.addHdrImage(jqcm, "addr");
		}
		else if ((ns = jQuery("#store_category_grid td")).length)
		// Item category page
		{
			this.pageCode = "cat";
			for (i = 0, c = ns.length; i < c; i++)
			{	
				jQuery("a", ns.eq(i)).eq(1).addClass("detail_link");
			}
		}
		
		/* Move the upsell */
		if ((n = jQuery("#fw_body_left > div.appArea > div.ShoppingUpSell")).length)
		{
			jQuery("#fw_body_left").append(n);
		}

		/* Kludge the shipping/billing checkbox */
		if ((appId == "8") && ((n = jQuery("#billing_address")).length))
		{
			n.css("display", "none").get(0).checked = true;
		}
	},
	"initRight": function()
	{
		var jqcm = jQuery("#fw_body_right"), jqc, ns, n, nn, price, i, c, m, id, pcst;
		switch (this.pageCode)
		{
			case "addr":
				
				break;
			default:
				break;
		}
	},
	"initBreadCrumb": function()
	{
		var n, str = "", navClass = "";
		if ((n = jQuery("#hgc_breadcrumb_product")).length)
		{
			str = jQuery("div.ProductDetailsHeader").html();
			switch (window.location.search.match(/(\?|\&)product_id=([^\&]+)(\&|$)/)[2])
			{
				case "1981":
					navClass = "nav_item_give";
					break;
				case "1821":
					navClass = "nav_item_gift";
					break;
			}
		}
		else if ((n = jQuery("#hgc_breadcrumb_category")).length)
		{
			switch (window.location.search.match(/(\?|\&)FOLDER=([^\&]+)(\&|$)/)[2])
			{
				case "1060":
					str = "Prepare Kids for Surgery";
					navClass = "nav_item_prepare";
					break;
				case "1071":
					str = "Provide Medicine &amp; Supplies";
					navClass = "nav_item_provide";
					break;
				case "1072":
					str = "Stock an Operating Room";
					navClass = "nav_item_stock";
					break;
				case "1073":
					str = "Comfort After Surgery";
					navClass = "nav_item_comfort";
					break;
				case "1090":
					str = "All Products";
					navClass = "nav_item_all";
					break;
				default:
					str = "Product Category";
					break;
			}
		}
		else if ((n = jQuery("#hgc_breadcrumb_unk")).length)
		{
			if (window.location.href.match(/EcommerceCheckout/))
			{
				str = "Checkout";
			}
			else if (jQuery("form[name='ShoppingCart']").length)
			{
				str = "Cart";
			}
			else
			{
				str = "All Products";
			}
		}

		n.html(str);

		if (window.location.pathname.match(/holiday-gift-catalog-2009\/home\.html/))
		{
			navClass = "nav_item_home";
		}

		if (navClass.length)
		{
			jQuery("#fw_primary_nav ."+navClass).addClass("nav_item_onpage");
		}
	}
};

jQuery(document).ready(function() { opsmile.store.init(); });