function Shoptivate(endfn) {
	/*extern DOMhelp, Listbox, ShSearch, ShSettings, YAHOO*/
	var imgstem='';
	var detailMode = false;
	var divwd=ShSettings.lbItemWidth;
	var divht=ShSettings.lbItemHeight;
	var listdivht=ShSettings.lbListItemHeight;
	var areawd=0, areaht=0, shdheight=0, shdwidth=0;
	var o=DOMhelp.createElement;
	var shdetail=o('div#shdetail');
	var shcartmsg=o('div#shcartmsg');
	var helpimg=o('div#helpimg');
	var carthldr=o('div');
	var scripthldr=o('div');
	var lbox=new Listbox();
	var schobj=new ShSearch(lbox);
	var detailItem=null;
	var received_details=false;
	var secret=0;
	var dbid=0;
	var isListMode=false;
	var respectBackspace=false;
	var shcartfade= new YAHOO.util.Anim(shcartmsg, {opacity: {from: 1, to: 0}}, 2, YAHOO.util.Easing.easeIn);
	shcartfade.onComplete.subscribe(function() {shcartmsg.style.display='none';});
	var modesel=null;
	var shdetclose=null;
	function endDetailMode() {
		if (detailMode) {
			lbox.highlight(-1);
			detailMode=false;
			if (isListMode) {
				DOMhelp.replaceContent(modesel, selContentList());
				lbox.setItemDims(-1, listdivht, areawd, -1);
			} else {
				DOMhelp.replaceContent(modesel, selContentGrid());
				lbox.setWidth(areawd, -1);
			}
			shdetail.style.display=shdetclose.style.display='none';
			DOMhelp.replaceContent(shdetail);
		}
	}
	shdetclose=o('div#shclose', {onclick: endDetailMode});
	var gridMode=null;
	var gridImg='http://lib.store.yahoo.net/lib/teeda-online/gridsh.png';
	var listImg='http://lib.store.yahoo.net/lib/teeda-online/listsh.png';
	var gridImgGray='http://lib.store.yahoo.net/lib/teeda-online/gridgray.png';
	var listImgGray='http://lib.store.yahoo.net/lib/teeda-online/listgray.png';
	var cartImg='http://lib.store.yahoo.net/lib/teeda-online/smcartt.png';
	var carturl='http://order.store.yahoo.net/cgi-bin/wg-order?teeda-online';
	
	function selContentList() {
		return [o('a', {'href':'#', 'onclick':gridMode},
							o('img', {'border':'0', 'src':gridImg}), 'Grid'), ' \u00a0\u00a0\u00a0 ',
						o('b',
							o('img', {'src':listImg}), 'List'), ' \u00a0\u00a0\u00a0 ',
						o('a', {'href':carturl},
							o('img', {'border':'0', 'src':cartImg}), 'View Cart')];
	}
	function selContentGrid() {
		return [o('b',
							o('img', {'src':gridImg}), 'Grid'), ' \u00a0\u00a0\u00a0 ',
						o('a', {'href':'#', 'onclick':listMode},
							o('img', {'border':'0', 'src':listImg}), 'List'), ' \u00a0\u00a0\u00a0 ',
						o('a', {'href':carturl},
							o('img', {'border':'0', 'src':cartImg}), 'View Cart')];
	}
	function selContentGray() {
		return [o('span.shvgray',
							o('img', {'src':gridImgGray}), 'Grid'), ' \u00a0\u00a0\u00a0 ',
						o('span.shvgray',
							o('img', {'src':listImgGray}), 'List'), ' \u00a0\u00a0\u00a0 ',
						o('a', {'href':carturl},
							o('img', {'border':'0', 'src':cartImg}), 'View Cart')];
	}
	var listMode=function() {
		if (!isListMode) {
			isListMode=true;
			if (!detailMode) {
				lbox.setItemDims(-1, listdivht, areawd, -1);
			}
			DOMhelp.replaceContent(modesel, selContentList());
		}
		return false;
	};
	gridMode=function() {
		if (isListMode) {
			isListMode=false;
			if (!detailMode) {
				lbox.setItemDims(divwd, divht, areawd, -1);
			}
			DOMhelp.replaceContent(modesel, selContentGrid());
		}
		return false;
	};
	modesel=o('div#modesel', selContentGrid());
	function detailScroll(e) {
			if (e.detail && e.stopPropagation) {
				if ((e.detail<0 && shdetail.scrollTop>0) ||
						(e.detail>0 && shdetail.scrollTop+shdetail.offsetHeight<shdetail.scrollHeight+2)) {
					e.stopPropagation();
				}
			}
	//  var newTop=shdetail.scrollTop+((e.detail && e.detail<0) ? -40 : 40);
	//  newTop=Math.min(newTop, shdetail.scrollHeight+2-shdetail.offsetHeight);
	//  shdetail.scrollTop=Math.max(newTop,0);
	}
	function detailScrollIE() {
		if (window.event && window.event.wheelDelta && shdetail.doScroll) {
			shdetail.doScroll(window.event.wheelDelta<0 ? "scrollbarDown" : "scrollbarUp");
		}
	} 
	if (shdetail.addEventListener) {
		shdetail.addEventListener("DOMMouseScroll", detailScroll, false);
	} else {
		shdetail.onmousewheel=detailScrollIE;
	}

	function dismissWaiting(popmsg, statmsg) {
		shcartmsg.style.left=(areawd/2-150)+"px";
		shcartmsg.style.top=(areaht/2-26)+"px";
		DOMhelp.replaceContent(shcartmsg, o('div', popmsg));
		if (shcartfade.isAnimated()) {
			shcartfade.stop();
		}
		YAHOO.util.Dom.setStyle(shcartmsg, 'opacity', 1);
		shcartmsg.style.display='block';

		shcartfade.animate();
		if (statmsg) {
			PURCHASE.reset();
			PURCHASE.clearInputs();
			PURCHASE.cartMsg(statmsg);
		}
	}
	function waitingPopup(s) {
		DOMhelp.replaceContent(shcartmsg, o('div', o('img.shwait', {'src':'http://lib.store.yahoo.net/lib/teeda-online/waiting.gif'}), s));
		shcartmsg.style.left=(areawd/2-150)+"px";
		shcartmsg.style.top=(areaht/2-26)+"px";
		YAHOO.util.Dom.setStyle(shcartmsg, 'opacity', 1);
		shcartmsg.style.display='block';
	}
	function cartTimeout(s) {
		return function() {
			if (secret==s) {
				secret=Math.floor(Math.random()*0x7fffffff);
				dismissWaiting('Error adding item(s).');
			}
		};
	}
	PURCHASE.setCartAction(function() {
		secret=Math.floor(Math.random()*0x7fffffff);
		carthldr.innerHTML = '<iframe name="shcart_'+secret+'" style="display:none;"></iframe>';
		waitingPopup("Adding to cart...");
		setTimeout(cartTimeout(secret), 8000);
		return 'shcart_'+secret;
	});
	function unstem(s) {
		if (s.length>0) {
			if (s.charAt(0)=='S') {
				return imgstem+s.substring(1);
			}
			if (s.charAt(0)=='_') {
				return s.substring(1);
			}
		}
		return s;
	}
	window.product_detail=function(sku, extraData) {
		var itemData = detailItem[3];
		if (sku==itemData.id && detailMode) {
			received_details=true;

			var content;
			if (detailItem[2].length>1) {
				content = ITEMPAGE.hasOptions(extraData.caption, detailItem[0], extraData.specs,
					itemData.showOrder, itemData.ignoreQoh, detailItem[2], itemData.retail, itemData.wholesale,
					extraData.multiplier, itemData.name, unstem(extraData.inseturl), extraData.insetht,
					extraData.insetwd, unstem(extraData.insetthumburl), unstem(extraData.imgurl),
					extraData.imght, extraData.imgwd, unstem(extraData.smallimgurl), extraData.producturl,
					shdwidth);
			} else {
				content = ITEMPAGE.noOptions(extraData.caption, detailItem[0], itemData.retail,
					itemData.wholesale, extraData.specs, itemData.showOrder, itemData.ignoreQoh,
					detailItem[1], itemData.name, unstem(extraData.inseturl), extraData.insetht,
					extraData.insetwd, unstem(extraData.insetthumburl), unstem(extraData.imgurl),
					extraData.imght, extraData.imgwd, unstem(extraData.smallimgurl), extraData.producturl,
					shdwidth);
			}
			DOMhelp.replaceContent(shdetail, content);
		}
	};
	window.product_detail_error=function(sku) {};
	window.cartmsg=function(n) {
		var args=n.split(',');
		if (args[0]==secret) {
			secret=Math.floor(Math.random()*0x7fffffff);
			if (args.length>=3 && args[1]=='ok') {
				dismissWaiting('Item(s) added to cart.', 'Cart Total: $'+args[2]);
			} else if (args.length>=3 && args[1]=='out') {
				dismissWaiting('One or more quantities unavailable.', '(Unavailable) Cart Total: $'+args[2]);
			} else {
				dismissWaiting('Error adding item(s).');
			}
		}
	};
	function fitandcenter(url, className, imwd, imht, fitwd, fitht) {
		var dx, dy;
		if (imwd<=fitwd && imht<=fitht) {
			dx=(fitwd-imwd)/2;
			dy=(fitht-imht)/2;
			fitwd=imwd;
			fitht=imht;
		} else {
			if (imwd/imht > fitwd/fitht) {
				dx=0;
				dy=(fitht-fitwd*imht/imwd)/2;
				fitht=fitwd*imht/imwd;
			} else {
				dx=(fitwd-fitht*imwd/imht)/2;
				dy=0;
				fitwd=fitht*imwd/imht;
			}
		}
		var elt=o('img', {'src':url});
		elt.className=className;
		elt.style.width=fitwd+"px";
		elt.style.height=fitht+"px";
		elt.style.left=dx+"px";
		elt.style.top=dy+"px";
		return elt;
	}
	function itemDetails(item) {
		detailItem = item;
		var url='http://teeda.shoptivate.com/pdetail.php?sku='+detailItem[3].id+'&db='+dbid;
		received_details = false;
		DOMhelp.appendContent(scripthldr, o('script', {'src':url}));
		setTimeout(function() {if (!received_details) {
				DOMhelp.replaceContent(shdetail, o('div.prodcont', o('b', "Getting product information...")));}}, 300);
	}
	function startDetailMode(n) {
		if (!detailMode) {
			detailMode=true;
			if (isListMode) {
				lbox.setItemDims(divwd, divht, divwd+6, n);
			} else {
				lbox.setWidth(divwd+6, n);
			}
			DOMhelp.replaceContent(modesel, selContentGray());
			
			shdetail.style.left=shdetclose.style.left=(divwd+26)+"px";
			shdetail.style.height=shdheight+"px";
			shdetail.style.width=shdwidth+'px';
			shdetail.style.display=shdetclose.style.display='block';
		}
		var item=schobj.getItem(n);
		if (item) {
			itemDetails(item);
			lbox.highlight(n);
			shdetail.scrollTop=0;
		} else {
			DOMhelp.replaceContent(shdetail);
		}
	}
	function allItemsOut(options) {
		for (var i=0; i<options.length; ++i) {
			if (options[i][1]<1) {
				return false;
			}
		}
		return true;
	}
	schobj.setItemInCB(function(item, num, elt) {
		var showMyDetails=function() {startDetailMode(num);};
		var itemData = item[3];
		if (isListMode && !detailMode) {
			var thimg = [];
			if (itemData.thumburl) {
				thimg = fitandcenter(unstem(itemData.thumburl), 'listpic', itemData.thumbwd, itemData.thumbht, 70, 70);
				thimg.onclick=showMyDetails;
				thimg.style.cursor='pointer';
			}
			var options = [];
			var inputInfo=PURCHASE.getListInfoForSku(item[0], item[2].length);
			var soldOut = false;
			if (item[2].length>1) {
				soldOut = !itemData.showOrder || (!itemData.ignoreQoh && allItemsOut(item[2]));
				var optionelts=[];
				for (var i=0; i<item[2].length; ++i) {
					var opt = item[2][i];
					if (soldOut || itemData.ignoreQoh || opt[1]<1) {
						var attrs = {'value':opt[0]};
						if (inputInfo.selitem && opt[0].substr(0, inputInfo.selitem.length)==inputInfo.selitem) {
							attrs.selected='selected';
						}
						optionelts.push(o('option', attrs, opt[0]));
					}
				}
				options = o('select', {'id':inputInfo.selectid, 'onchange':inputInfo.selectfn}, optionelts);
			} else {
				soldOut = (!itemData.showOrder || (!itemData.ignoreQoh && item[1]>0));
			}
			var qtyinput = "Sold Out";
			if (!soldOut) {
				var inputelt=o('input', {'id':inputInfo.id, 'type':'text', 'size':'4',
					'value':inputInfo.qty, 'onkeyup':inputInfo.fn});
				inputelt.style.textAlign='right';
				qtyinput = ['Qty: ', inputelt];
			}
			var titlecell = o('td', o('b', itemData.name));
			var skucell = o('td.skucell', item[0]);
			titlecell.onclick=skucell.onclick=showMyDetails;
			titlecell.style.cursor=skucell.style.cursor="pointer";
			titlecell.onmouseover=function() {titlecell.style.textDecoration='underline';};
			titlecell.onmouseout=function() {titlecell.style.textDecoration='none';};
			skucell.onmouseover=function() {skucell.style.textDecoration='underline';};
			skucell.onmouseout=function() {skucell.style.textDecoration='none';};
			DOMhelp.replaceContent(elt,
				o('table.itemtable', o('tbody',
				  o('tr',
					  o('td.itempiccell', thimg),
						o('td',
						  o('table.itemdatatbl', o('tbody',
								o('tr',
									titlecell,
									o('td.wscell', o('b', 'Wholesale: $'+itemData.wholesale))),
								o('tr',
									skucell,
									o('td.qtycell', qtyinput)),
								o('tr',
									o('td.optionscell', {'colSpan':'2'}, options)))))))));
		} else {
			var img = itemData.thumburl ? o('img', {'src':unstem(itemData.thumburl)}) : [];
			var titleelt = o('div.title', itemData.name);
			DOMhelp.replaceContent(elt,
				img,
				titleelt,
				o('div.shvgnorm', item[0]),
				o('div.shvgnorm', '$'+itemData.wholesale));
			elt.onclick=showMyDetails;
			elt.onmouseover=function() {titleelt.style.textDecoration='underline';};
			elt.onmouseout=function() {titleelt.style.textDecoration='none';};
			elt.style.cursor="pointer";
		}
	});
	schobj.setInitCB(function(count, istem, databaseid) {
		imgstem = istem;
		dbid = databaseid;
		schobj.setQuerySuffix('&D='+databaseid);
	});
	this.outerDOMelements=function() {
		return [o('div#schtermbox', o('input#schterm'))];
	};
	this.DOMelements=function() {
		schobj.setHelpImg(helpimg);
		return [schobj.DOMelements(),
						lbox.DOMelements(),
						helpimg,
						shdetclose,
						shdetail,
						modesel,
						carthldr,
						scripthldr,
						PURCHASE.DOMelements,
						shcartmsg];
	};
	this.resizeNotify=function(ht, wd) {
		if (ht!=areaht) {
			shdheight = ht-(window.ieLT7 ? 72 : 82);
			if (detailMode) {
				shdetail.style.height=shdheight+"px";
			}
			lbox.setHeight(ht-51);
			areaht=ht;
		}
		if (wd!=areawd) {
			shdwidth = wd-divwd-(window.ieLT7 ? 16 : 24);
			if (detailMode) {
				shdetail.style.width=shdwidth+'px';
				ITEMPAGE.setWidth(shdwidth);
			} else {
				lbox.setWidth(wd, -1);
			}
			areawd=wd;
		}
	};
	this.turnOn=function() {
		lbox.turnOn();
		if (detailMode) {
			shdetail.style.display=shdetclose.style.display='block';
		}
	};
	this.turnOff=function() {
		lbox.turnOff();
		shdetail.style.display=shdetclose.style.display='none';
	};
	this.setBackspace=function(v) {respectBackspace=v;};
	lbox.setKeyCB(function(k) {
		if (k==27 || (k==8 && respectBackspace)) {
			if (!detailMode) endfn();
			else endDetailMode();
			return false;
		}
		return (k!=13);
	});
	schobj.setClearDataCB(endDetailMode);
	this.txtupdate=schobj.txtupdate;
}

