YAHOO.util.Dom.getElementsByExternal = function(root) {
	var method = function(el) { 
		if (el.href.indexOf(location.hostname) > -1 || el.href.indexOf(':') == -1) {
			return false;
		}
		return true;
	};
	return this.getElementsBy(method, 'a', root);
};
YAHOO.util.Dom.getElementsByInternal = function(root) {
	var method = function(el) { 
		if (el.href.indexOf(location.hostname) > -1 || el.href.indexOf(':') == -1) {
			return true;
		}
		return false;
	};
	return this.getElementsBy(method, 'a', root);
};
YAHOO.util.Dom.getElementsByAttribute = function(atr, val, tag, root) {
	var method = function(el) { 
		var re = new RegExp('(?:^|\\s+)' + val + '(?:\\s+|$)');
		if ( el.getAttribute(atr) && re.test(el.getAttribute(atr)) ) {
			return true;
		}
		return false;
	};
	return this.getElementsBy(method, tag, root);
};
	
YAHOO.widget.Effect = function(el) {
	this.objEl = YAHOO.util.Dom.get(el);
	this.height = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	this.width = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'width'));
};
YAHOO.widget.Effect.prototype.BlindUp = function(iTimer,hide) {
	var $D = YAHOO.util.Dom;
	var timer = iTimer || 1;
	this.objEl.style.overflow = 'hidden';
	
	var attrib = {
		height: { to:0 },
		paddingBottom: { to:0 }
	};
	
	var blind = new YAHOO.util.Anim(this.objEl, attrib, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	if ( hide ) {
		blind.onComplete.subscribe(
			function() {
				$D.addClass(hide,'hide');
			}
		);
	}
	blind.animate();
};

YAHOO.widget.Effect.prototype.CartDelete = function(iTimer,onComplete) {
	var $D = YAHOO.util.Dom;
	var timer = iTimer || 1;
	if (!this.objEl) return;
	this.objEl.style.overflow = 'hidden';

	var blind = new YAHOO.util.Anim(this.objEl, { height: { to:0 }, opacity: { to:0, from:1 } }, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	blind.onComplete.subscribe(
		function() {
			that.objEl.style.display = 'none';
			that.objEl.parentNode.removeChild(that.objEl);
			YAHOO.nubedo.reorderCart();
		}
	);
	blind.animate();
};
YAHOO.widget.Effect.prototype.BlindDown = function(iTimer,onComplete) {
	var $D = YAHOO.util.Dom;
	var timer = iTimer || 1;
	this.objEl.style.visibility = 'hidden';
	this.objEl.style.overflow = 'hidden';
	display = $D.setStyle(this.objEl,'display','block');
	this.objEl.style.height = '';
	var height = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	if (!height) var height = this.objEl.offsetHeight;
	if (!height) var height = 400;
	this.objEl.style.height = '0';
	this.objEl.style.visibility = 'visible';
	this.objEl.style.display = '';
	var attrib = {
		height: { to:height, from:0 },
		paddingBottom: { to:13, from:0 }
	};
	var blind = new YAHOO.util.Anim(this.objEl, attrib, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	blind.onComplete.subscribe(
		function() {
			if (onComplete) {
				onComplete();
			}
			that.objEl.style.height = '';
			that.objEl.style.visibility = 'visible';
			that.objEl.style.overflow = '';
		}
	);
	blind.animate();
};
YAHOO.widget.Effect.prototype.BlindDownPartial = function(iTimer,endHeight,onComplete) {
	var timer = iTimer || 1;
	var startHeight = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	if (!startHeight) var startHeight = this.objEl.offsetHeight;
	var endHeight = startHeight + endHeight;
	this.objEl.style.visibility = 'visible';
	this.objEl.style.display = '';
	var attrib = {
		height: { to:endHeight, from:startHeight},
		paddingBottom: { to:16, from:0 }
	};
	var blind = new YAHOO.util.Anim(this.objEl, attrib, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	blind.onComplete.subscribe(
		function() {
			if (onComplete) {
				onComplete();
			}
			that.height = '';
		}
	);
	blind.animate();
};
YAHOO.widget.Effect.prototype.FadeIn = function(iTimer,fadeTo,onComplete) {
	var timer = iTimer || 1;
	var timer = fadeTo || 1;
	YAHOO.util.Dom.setStyle(this.objEl,'opacity',0);
	this.objEl.style.display = '';
	var blind = new YAHOO.util.Anim(this.objEl, { opacity: { to: fadeTo } }, timer, YAHOO.util.Easing.easeOut);
	if ( onComplete ) {
		blind.onComplete.subscribe(onComplete);
	}
	blind.animate();
};
YAHOO.widget.Effect.prototype.FadeOut = function(iTimer,fadeTo,onComplete) {
	var timer = iTimer || 1;
	var timer = fadeTo || 1;
//	YAHOO.util.Dom.setStyle(this.objEl,'opacity',1);
	this.objEl.style.display = '';
	var blind = new YAHOO.util.Anim(this.objEl, { opacity: { to: fadeTo } }, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	blind.onComplete.subscribe(
		function() {
			YAHOO.util.Dom.setStyle(that.objEl,'display','none');
			YAHOO.util.Dom.setStyle(that.objEl,'opacity',1);
			onComplete();
		}
	);
	blind.animate();
};
YAHOO.widget.Effect.prototype.yoyo = function(iTimer,show,hide,onComplete) {
	var $D = YAHOO.util.Dom;
	this.objEl.style.overflow = 'hidden';
	var height = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	if (!height) var height = this.objEl.offsetHeight;
	var timer = iTimer || 1;
	var yoyo = new YAHOO.util.Anim(this.objEl, { height: { to:0} }, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	yoyo.onComplete.subscribe(
		function() {
		
			$D.addClass(hide,'hide');
			$D.removeClass(show,'hide');
		
			that.objEl.style.visibility = 'hidden';
			that.objEl.style.overflow = 'hidden';
			that.objEl.style.height = '';
			var height = parseInt(YAHOO.util.Dom.getStyle(that.objEl,'height'));
			if (!height) var height = that.objEl.offsetHeight;
			that.objEl.style.height = '0';
			that.objEl.style.visibility = 'visible';
			var blind = new YAHOO.util.Anim(that.objEl, { height: { to:height, from:0} }, timer, YAHOO.util.Easing.easeIn);
			if ( onComplete ) {
				blind.onComplete.subscribe(onComplete);
			}
			blind.animate();
		}
	);
	yoyo.animate();
};

YAHOO.nubedo = function() {
	var	$D = YAHOO.util.Dom,
		$E = YAHOO.util.Event,
		$M = YAHOO.util.Motion,
		$A = YAHOO.util.Anim,
		$ = $D.get,
		$JSON = YAHOO.lang.JSON.parse,
		ratingWidth,
		viewer,
		focused = false,
		img = false,
		parent = false,
		featurePause = false,
		timeoutID,
		updateTimeoutID,
		ratingUpdateID,
		btnadd,
		btnTimeoutID;

	return {
		init : function() {
			sq = $('searchQuery');
			$D.addClass(sq,'init');
			
			sq.value = 'search for keyword';
			$E.on(sq,'focus',this.clearSearch);
			$E.on(sq,'blur',this.checkSearch);
			
			var rateProduct = $D.getElementsByClassName('rateProduct');
			if (rateProduct) {
				YAHOO.nubedo.initProductHover(rateProduct);
			//	$E.on(rateProduct,'mouseover',this.rateProductOver);
				$E.on(rateProduct,'mouseout',this.rateProductOut);
			}
			
			if ($('nbp'))
				var tabView = new YAHOO.widget.TabView('nbp');
			
			if ($('nbc'))
				var tabView = new YAHOO.widget.TabView('nbc');
			
			var functions = $D.getElementsByClassName('functions');
			var fc = $('functionsContent');
			var fcC = fc.getElementsByTagName("INPUT");
			var btn = ['functionsCart','functionsAccount','functionsLogout','functionsSearch'];
			var closeB = $D.getElementsByClassName('btn_close','div',fc);
			$E.on([btn,closeB],'click',this.minicart);
			
			$E.on(fc,'mouseover',this.cancel);
			$E.on(fc,'mouseout',this.timeout);
			$E.on(fcC,'focus',this.setFocused);
			$E.on(fcC,'blur',this.unsetFocused);
			fc.style.display = 'none';		
			
			var updateCartQty = $D.getElementsByClassName('updateQty');
			var updateGiftWrap = $D.getElementsByClassName('updateGiftWrap');
			$E.on(updateCartQty,'keydown',this.updateTimeout); 
			$E.on(updateGiftWrap,'click',this.updateTimeout); 
			// make sure the minicart is always correct
			$E.onAvailable('miniCart-body',this.refreshCart);
			
			if ($('numCharCount')) {
				$E.on($('note'),'keydown',this.countChars);
				$E.on($('note'),'blur',this.countCharsFinal);
				$E.on($('note'),'keyup',this.countCharsFinal);
			}
			
			// featured box
			if ($('featuredBox')) {
				this.initFeatured();
			}
			
			// if it exists, remove catpcha
			if ($('registerUsername2'))
				$('registerUsername2').style.display = 'none';
				
			if ($('reviewForm')) {
				$E.on('reviewForm','submit',this.reviewForm);
			}
			
			var imageS = $D.getElementsByClassName('enlargeImage');
			$E.on(imageS,'click',this.enlargeImage);
			
			
			var notifications = $D.getElementsByClassName('notify');
			$E.on(notifications,'click',this.notify);
			
			
			var notifyText = $D.getElementsByClassName('notifyText');
			$E.on(notifyText,'click',this.notifyText);
									
			var updateCart = $D.getElementsByClassName('updatecart');
			$E.on(updateCart,'submit',this.modifyCart); 
			
			var checkOut = $D.getElementsByClassName('btn_checkout');
			$E.on(checkOut,'click',this.modifyCart); 
			
			var addCart = $D.getElementsByClassName('addcart');
			$E.on(addCart,'submit',this.addcart);
			if ($('priceChange')) {
				for (i in addCart) {
					for (ii in addCart[i].elements) {
						if (addCart[i].elements[ii].id.indexOf('option') != -1){
							var option = addCart[i].elements[ii];
							$E.on(option,'change',this.priceChange);
						}
					}
				}
			}
			
			if ($('swapShipping')) {
				$E.on($('swapShipping'),'change',this.swapShipping)
			}
			
		},
		initFeatured : function() {
			var	featured = $D.getElementsByClassName('featureNavItem'),
					feat = $('imageFeature'),
					kids = $D.getChildren(feat),
					first = true;
					
			$E.on(featured,'click',YAHOO.nubedo.featuredGoTo);
			
			for (i in kids) {
				if (first) {
					$D.setStyle(kids[i],'display','block');
					first = false;
				}else{
					$D.setStyle(kids[i],'display','none');
				}
			}
			
			$E.on('featureNext','click',YAHOO.nubedo.featuredNext);
			$E.on('featureBack','click',YAHOO.nubedo.featuredBack);
			$E.on('featurePause','click',YAHOO.nubedo.featuredPause);
			YAHOO.nubedo.featureReset();
		},
		featuredNext : function() {
			var current = $D.getElementsByClassName('currentFeat');
			var next = $D.getNextSibling(current[0]);
			if (!$D.hasClass(next,'featureNavItem')) {
				var next = $D.getFirstChild('featureNav');
			}
			YAHOO.nubedo.featuredGoTo(false,next);
		},
		featuredBack : function() {
			var current = $D.getElementsByClassName('currentFeat');
			var next = $D.getNextSibling(current[0]);
			
			if (!$D.hasClass(next,'featureNavItem')) {
				var next = $D.getLastChild('imageFeature1');
				next = $(next.id+'-nav');
			}
			YAHOO.nubedo.featuredGoTo(false,next);
		},
		featuredPause : function() {
			if (!featurePause) {
				$D.addClass('featurePause','play');
				if(typeof featTimeoutID == "number") {
					window.clearTimeout(featTimeoutID);
					featTimeoutID=null;
				}
				featurePause = true;
			}else{
				$D.removeClass('featurePause','play');
				featurePause = false;
				YAHOO.nubedo.featureReset();
			}
		},
		featuredGoTo : function(e, obj) {		
			var	obj = obj || this,
					num = obj.id.replace('-nav',''),
					current = $D.getElementsByClassName('currentFeat'),
					current = $(current[0].id.replace('-nav',''));
			
			if ($D.hasClass(obj,'currentFeat'))
				return;
		
			var feat = $('imageFeature');
			var kids = $D.getChildren(feat);
			
			var ab = new YAHOO.widget.Effect(num);
			ab.FadeIn(0.25,1);
			$D.setStyle(num,'display','block');
						
			for (i in kids) {
				if (kids[i].id != num) {
					if (kids[i] == current) {
						var b = new YAHOO.widget.Effect(kids[i]);
						b.FadeOut(0.25,0);
						$D.setStyle(kids[i],'display','block');
					}
				}
			}
			
			$D.addClass(obj, 'currentFeat');
			
			var featured = $D.getElementsByClassName('featureNavItem');
			for (x in featured) {
				if (featured[x].id != obj.id) {
					$D.removeClass(featured[x],'currentFeat');
				}
			}
			YAHOO.nubedo.featureReset();
		},
		featureReset : function() {
			if(typeof featTimeoutID == "number") {
				window.clearTimeout(featTimeoutID);
				featTimeoutID=null;
			}
			if (featurePause)
				return;
			featTimeoutID = window.setTimeout(YAHOO.nubedo.featuredNext,7500);
		},
		swapShipping : function(e) {
			$sS = $('swapShipping');
			$ship = $('cartShipping');
			$total = $('cartTotal');
			
			postBody = 'shippingService='+$sS.value;
			var callback = {
				success: function(o) {
					var resp = YAHOO.lang.JSON.parse(o.responseText);
					if (resp.shipping == 0) {
						$ship.innerHTML = 'FREE';
					}else{
						$ship.innerHTML = '$'+resp.shipping;
					}
					$total.innerHTML = '$'+resp.total;
				},
				failure: function(o) { },
				timeout: 5000
			}
			
			var transaction = YAHOO.util.Connect.asyncRequest('POST','/checkout/shipping/',callback,postBody);
		},
		reviewForm : function (e) {
			$E.stopEvent(e);
			YAHOO.util.Connect.setForm(this);
			
			var loading = document.createElement("div");
			loading.className = 'loading';
			loading.id = 'loading';
			document.body.appendChild(loading);
			
			var callback = {
				success: function(o) {
					document.body.removeChild(loading);
					var resp = YAHOO.lang.JSON.parse(o.responseText);
					if (resp.success) {
						var parent = $('reviewForm').parentNode;
						parent.removeChild($('reviewForm'));
						
						var para = document.createElement("p");
						para.innerHTML = 'Thank you for reviewing this product. Please note that your review may not show up immediately.';
						
						parent.appendChild(para);
					}else{
						if (resp.reviewTitle) {
							var parent = $('reviewTitle').parentNode;
							if (!$D.hasClass(parent,'error')) {
								$D.addClass(parent, 'error');
								parent.innerHTML += '<p class="error">'+resp.reviewTitle+'</p>';
							}else{
								$D.removeClass(parent,'error');
								pError = $D.getElementsByClassName('error','p',parent);
								parent.removeChild(pError);
							}
						}
						if (resp.reviewBody) {
							var parent = $('reviewBody').parentNode;
							if (!$D.hasClass(parent,'error')) {
								$D.addClass(parent, 'error');
								parent.innerHTML += '<p class="error">'+resp.reviewBody+'</p>';
							}else{
								$D.removeClass(parent,'error');
								pError = $D.getElementsByClassName('error','p',parent);
								parent.removeChild(pError);
							}
						}
					}
					
				},
				failure: function(o) {  },
				timeout: 5000
			}
			var post = 'url='+window.location.href;
			var transaction = YAHOO.util.Connect.asyncRequest('POST',this.action+'?output=json', callback, post);
		},
		priceChange : function (e) {
			var theForm = this.form,
				post = '&output=json';
				
			YAHOO.util.Connect.setForm(theForm);
			
			var loading = document.createElement("div");
			loading.className = 'loading';
			loading.id = 'loading';
			document.body.appendChild(loading);
			
			var callback = {
				success: function(o) {
					document.body.removeChild(loading);
					var resp = YAHOO.lang.JSON.parse(o.responseText);
					if (resp.price) {
						$('priceChange').innerHTML = '$'+resp.price
					}
					
				},
				failure: function(o) {  },
				timeout: 5000
			}
			var post = 'url='+window.location.href;
			var transaction = YAHOO.util.Connect.asyncRequest('POST','/cart/getPrice/',callback,post);
		},
		initProductHover : function(rpd) {
			for(ii in rpd) {
				var defaultRating = $D.getElementsByClassName('defaultRating','em',rpd[ii]);
				
				if ($D.hasClass(rpd[ii],'disabled'))
					return;
				
				for(i=1;i<6;i++) {
				
					var star = document.createElement("span");
					star.id = 'star'+ii+'_'+i;
					var txt = i>1 ? i+' stars.' : i+' star.';
					
					star.title='Rate this product '+txt;
					
					rpd[ii].appendChild(star);
					
					$E.on(star,'mouseover',YAHOO.nubedo.rateProductHover);
					$E.on(star,'click',YAHOO.nubedo.rateProduct);
				}
			}
		},
		rateProductHover : function (e,obj) {
			if(typeof ratingUpdateID == "number") {
				window.clearTimeout(ratingUpdateID);
				ratingUpdateID=null;
			}
			
			obj = obj || this;
			
			var numStars = obj.id.substr(obj.id.indexOf('_')+1,1);
			var theIDs = obj.id.substr(0,obj.id.indexOf('_')+1);
			
			for(i=1;i<6;i++) {
				var star = theIDs+i
				if (i<=numStars) {
					$D.replaceClass($(star),'starOff','starOn');
				}else{
					$D.replaceClass($(star),'starOn','starOff');
				}
			}
			
		},
		rateProductOut : function (e,obj) {
			
			obj = obj || this;
			var theIDs = obj.id.substr(0,obj.id.indexOf('_')+1);
			
			if(typeof ratingUpdateID != "number") {
				ratingUpdateID = window.setTimeout(function() {			
					for(i=1;i<6;i++) {
						var star = theIDs+i
						$D.removeClass($(star),'starOff');
						$D.removeClass($(star),'starOn');
					}
				},1000);
			}
		},
		rateProduct : function (e, obj) {
			obj = obj || this;
			var parent = obj.parentNode;
			
			var numStars = obj.id.substr(obj.id.indexOf('_')+1,1);
			var theIDs = obj.id.substr(0,obj.id.indexOf('_')+1);
			var postBody = 'score='+numStars;
			
			var loading = document.createElement("div");
			loading.className = 'loading';
			loading.id = 'loading';
			document.body.appendChild(loading);
			
			var callback = {
				success: function(o) {
					for(i=1;i<6;i++) {
						var star = theIDs+i
						$D.removeClass($(star),'starOff');
						$D.removeClass($(star),'starOn');
					}
					var rpd = $D.getElementsByClassName('rateProduct');
					for (i in rpd) {
						if (!$D.hasClass(rpd[i],'rated'))
							$D.addClass(rpd[i],'rated');
						
						if ($D.hasClass(rpd[i],'norating'))
							$D.removeClass(rpd[i],'norating');
						
						var newWidth = numStars*20;
						var defaultRating = $D.getElementsByClassName('defaultRating','em',rpd[i]);
						
						$D.setStyle(defaultRating,'width',newWidth+'px');
					}
					document.body.removeChild(loading);
					if ($D.hasClass(parent,'notifyRating')) {
						YAHOO.nubedo.quickNotify('Thank you for rating. <span class="notice">Please note that your rating will not count towards the public rating unless you write a review.</span>');
						$D.removeClass(parent,'notifyRating');
					}
					
				},
				failure: function(o) {  },
				timeout: 5000
			}
			
			var transaction =
				YAHOO.util.Connect.asyncRequest('POST', window.location+'/rate/', callback, postBody);
		
		},
		countChars : function (e) {
			len = $('note').value.length;
			if (len > 299) {
				$E.stopEvent(e);
				$('note').value = $('note').value.substr(0,300);
				len = $('note').value.length;
				$('numCharCount').innerHTML = len;
			}else{
				$('numCharCount').innerHTML = len;
			}
		},
		countCharsFinal : function (e) {
			len = $('note').value.length;
			if (len > 299) {
				$E.stopEvent(e);
				$('note').value = $('note').value.substr(0,300);
				len = $('note').value.length;
				$('numCharCount').innerHTML = len;
			}else{
				$('numCharCount').innerHTML = len;
			}
		},
		clearSearch : function () {
			sq = $('searchQuery');
				if ($D.hasClass(sq,'init')) {
				$D.removeClass(sq,'init');
				sq.value = '';
			}
		},
		checkSearch : function () {
			sq = $('searchQuery');
			if (sq.value == '') {
				$D.addClass(sq,'init');
				sq.value = 'search for keyword or item #';				
			}
		},
		refreshUpdate : function() {		
			var updateCartQty = $D.getElementsByClassName('updateQty');
			var updateGiftWrap = $D.getElementsByClassName('updateGiftWrap');
			YAHOO.util.Event.purgeElement(updateCartQty, false, "keydown"); 
			YAHOO.util.Event.purgeElement(updateGiftWrap, false, "click"); 
			$E.on(updateCartQty,'keydown',this.updateTimeout);
			$E.on(updateGiftWrap,'click',this.updateTimeout);
		},
		notify : function (e,obj) {
			$E.stopEvent(e);
			
			var scr = document.createElement("div");
			var a = new YAHOO.widget.Effect(scr);
			scr.className = 'screen';
			scr.id = 'screen';
			$D.setStyle(scr,'opacity',0);
			document.body.appendChild(scr);
			a.FadeIn(0.25,0.35);
			$E.on(scr,"click",YAHOO.nubedo.killNotify);
			
			viewer = document.createElement("div");
			var av = new YAHOO.widget.Effect(viewer);
			viewer.className = 'notification';
			viewer.id = 'notification';
			$D.setStyle(viewer,'opacity',0);
			document.body.appendChild(viewer);
			
			var loading = document.createElement("div");
			loading.className = 'loading';
			loading.id = 'loading';
			document.body.appendChild(loading);
			
			var callback = {
				success: function(o) {
					viewer.innerHTML = o.responseText;
					$E.on($('closeviewer'),"click",YAHOO.nubedo.killNotify);
					av.FadeIn(0.25,1, function() { document.body.removeChild($('loading')); });
					if ($('friend')) {
						$E.on($('friendForm'),'submit',YAHOO.nubedo.tellFriend);
					}
					
				},
				failure: function(o) {  },
				timeout: 5000
			}
			var post = 'url='+window.location.href;
			var transaction = YAHOO.util.Connect.asyncRequest('POST',this.href+'/pagesInline/',callback,post);
		},
		notifyText : function (e) {
			$E.stopEvent(e);
			
			var scr = document.createElement("div");
			var a = new YAHOO.widget.Effect(scr);
			scr.className = 'screen';
			scr.id = 'screen';
			$D.setStyle(scr,'opacity',0);
			document.body.appendChild(scr);
			a.FadeIn(0.25,0.35);
			$E.on(scr,"click",YAHOO.nubedo.killNotify);
			
			viewer = document.createElement("div");
			var av = new YAHOO.widget.Effect(viewer);
			viewer.className = 'notification';
			viewer.id = 'notification';
			$D.setStyle(viewer,'opacity',0);
			document.body.appendChild(viewer);
			
			var closeviewer = document.createElement("div");
			closeviewer.id = 'close';
			
			viewer.innerHTML = '<p>'+this.innerHTML+'</p>';
			
			$E.on(closeviewer,"click",YAHOO.nubedo.killNotify);
			
			viewer.appendChild(closeviewer);
			av.FadeIn(0.25,1, function() { document.body.removeChild($('loading')); });
		},
		killNotify : function(e) {
			$E.stopEvent(e);
			if ($('screen')) document.body.removeChild($('screen'));
			document.body.removeChild($('notification'));
		},
		quickCartNotify : function (e,type,id) {
						
			viewer = document.createElement("div");
			var av = new YAHOO.widget.Effect(viewer);
			viewer.className = 'quickNotify';
			viewer.id = 'notification';
			$E.on(viewer,"click",YAHOO.nubedo.killNotify);
			
			$D.setStyle(viewer,'opacity',0);
			document.body.appendChild(viewer);
			
			var loading = document.createElement("div");
			loading.className = 'loading';
			loading.id = 'loading';
			document.body.appendChild(loading);
			
			var callback = {
				success: function(o) {
					document.body.removeChild($('loading'));
					viewer.innerHTML = o.responseText;
					av.FadeIn(0.35,0.85);
					window.setTimeout(function() {						
						av.FadeOut(0.35,0,function () { document.body.removeChild(viewer);  });
					},2500);
					
				},
				failure: function(o) {  },
				timeout: 5000
			}
			
			var transaction = YAHOO.util.Connect.asyncRequest('GET','/cart/?type='+type+'&notify='+id,callback);
			
		},
		quickNotify : function (msg) {
						
			viewer = document.createElement("div");
			var av = new YAHOO.widget.Effect(viewer);
			viewer.className = 'quickNotify';
			viewer.id = 'notification';
			$E.on(viewer,"click",YAHOO.nubedo.killNotify);
			
			viewer.innerHTML = '<div class="notifyContainer"><p class="notify">'+msg+'</p></div>';
			$D.setStyle(viewer,'opacity',0);
			document.body.appendChild(viewer);
			av.FadeIn(0.35,0.85);
			window.setTimeout(function() {						
				av.FadeOut(0.35,0,function () { document.body.removeChild(viewer);  });
			},5000);
		
		},
		enlargeImage : function(e,obj) {
			if (e) {
				$E.stopEvent(e);
			}
			obj = obj || this;
			
			if (!$('loading')) {
				loading = document.createElement("div");
				loading.id = "loading";
				document.body.appendChild(loading);
			}
			
			if (!img) {
				img = new Image();
				img.src = obj.href;
			}else{
				if (!YAHOO.lang.isUndefined(obj.href)) {
					if (img.src != obj.href) {
						img = new Image();
						img.src = obj.href;
					}
				}
			}
			
			if (!parent) {
				parent = obj.parentNode;
			}
			if (img.complete) {
				
				if ($('imgViewer')) {
					parent = $('imgViewer').parentNode;
					parent.removeChild($('imgViewer'));
				}
				if ($('loading')) {
					d = $('loading').parentNode;
					d.removeChild($('loading'));
				}
				
				var viewer = document.createElement('div');
				var wrap = document.createElement('div');
				viewer.id = 'imgViewer';
				viewer.appendChild(wrap);
				var close = document.createElement('div');
				close.id = 'close';
				
				var image = document.createElement("img");
				var av = new YAHOO.widget.Effect(viewer);
				
				$D.setStyle(viewer,'position','absolute');
				$D.setStyle(viewer,'z-index','9999');
				
				image.src = img.src;
				wrap.appendChild(image);
				wrap.appendChild(close);
				document.body.appendChild(viewer);
				
				pX = $D.getX(parent) + (parent.offsetWidth/2);
				pY = $D.getY(parent) + (parent.offsetHeight/2);
				
				imgX = pX-(img.width/2);
				imgY = pY-(img.height/2);
				
				imgR = imgX+img.width;
				imgB = imgY+img.height;
				
				scTop = $D.getDocumentScrollTop();
				scBottom = scTop + $D.getViewportHeight();
				
				scLeft = $D.getDocumentScrollLeft();
				scRight = scLeft + $D.getViewportWidth();
							
				imgX = (imgX<scLeft) ? scLeft+10 : imgX;
				imgY = (imgY<scTop) ? scTop+10 : imgY;			
				imgX = (imgR>scRight) ? scRight-10-img.width : imgX;
				imgY = (imgB>scBottom) ? scBottom-10-img.height : imgY;
				
				imgX = (imgX<10) ? 10 : imgX;
				imgY = (imgY<10) ? 10 : imgY;
							
				$D.setXY(viewer,[imgX,imgY]);
				$D.setStyle(viewer,'visibility','visible');
				
				av.FadeIn(0.75,1);
				$E.on([image,viewer,close],"click",YAHOO.nubedo.killScreen);
				parent = false;
				return;
			}else{
				var test = function(e, obj) {
					YAHOO.nubedo.enlargeImage(e,obj,img);					
				}
				imgID = window.setTimeout(test,500);
			}
			
		},
		killScreen : function(e) {
			$E.stopEvent(e);
			if ($('imgViewer')) {
				var parent = $('imgViewer').parentNode;
				parent.removeChild($('imgViewer'));
			}
		},
		refreshCart : function() {
			mcb = $('miniCart-body').innerHTML;
				var callback = {
					success: function(o) {
						mcb = o.responseText },
					failure: function(o) {  },
					timeout: 5000
				};
			var transaction = YAHOO.util.Connect.asyncRequest('POST','/cart/minicart/',callback);
			
		},
		setFocused : function(e) {
			focused = true;	
		},
		unsetFocused : function(e) {
			focused = false;	
			YAHOO.nubedo.timeout();
		},
		timeout : function() {
			if (focused == true) return;
			if(typeof timeoutID != "number") {
				timeoutID = window.setTimeout(function() {
					af = $D.getElementsByClassName('activeFunction');
					te = new YAHOO.widget.Effect($('functionsContent'));
					te.BlindUp(0.5);
					$D.removeClass($('functionsContent'),'under');
					$D.removeClass(af,'activeFunction');
				},5000);
			}
		},
		updateTimeout : function(e) {
			that = this;
			YAHOO.nubedo.cancelUpdate();
			if(typeof updateTimeoutID != "number") {
				updateTimeoutID = window.setTimeout(function() {
					that.blur();
					YAHOO.nubedo.modifyCart(e,that);
				},2500);
			}
		},
		cancelUpdate: function() {
			if(typeof updateTimeoutID == "number") {
				window.clearTimeout(updateTimeoutID);
				updateTimeoutID=null;
			}
		},
		cancel: function() {
			if(typeof timeoutID == "number") {
				window.clearTimeout(timeoutID);
				timeoutID=null;
			}
		},
		minicart : function(e) {
			YAHOO.nubedo.cancel();
			var $CT = $D.getElementsByClassName('miniFunction');
			var $C = $('functionsContent');
			var a = new YAHOO.widget.Effect($C);
			var $aF = $D.getElementsByClassName('activeFunction');
			if($D.hasClass(this,'btn_close')) {
				show = this.parentNode;
			}else{
				show = String(this.id+'Content');
			}
			
			if ( $(show) ) {
			
				if ( !$D.hasClass($C,'under')) {
				
					$D.addClass($CT,'hide');
					$D.removeClass($(show),'hide');
					$D.addClass($C,'under');
					
					$D.addClass(this.childNodes[0],'activeFunction');
					
					a.BlindDown(0.5);
				}else{
					if ($D.hasClass(show,'hide')) {
						$D.removeClass($aF,'activeFunction');
						a.yoyo(0.5,$(show),$CT);
						$D.addClass(this.childNodes[0],'activeFunction');
					}else{
						a.BlindUp(0.5,$CT);
						$D.removeClass($C,'under');
						$D.removeClass(this.childNodes[0],'activeFunction');
					}
				}
				$E.stopEvent(e);
			}
		},
		showcart : function(e,newHeight) {
			YAHOO.nubedo.cancel();
			var $CT = $D.getElementsByClassName('miniFunction');
			var $CA = $('functionsCartContent');
			var $C = $('functionsContent');
			var a = new YAHOO.widget.Effect($C);
			$E.stopEvent(e);
			
			if ( !$D.hasClass($C,'under') ) {
				
				$D.addClass($CT,'hide');
				$D.removeClass($CA,'hide');
				$D.addClass($C,'under');
				
				a.BlindDown(0.5);
			
			}else{
				if ( $D.hasClass($CA,'hide') ) {
					a.yoyo(0.5,$CA,$C.getElementsByTagName("DIV"));
				}else{
					a.BlindDownPartial(0.5,newHeight);	
				}
			
			}
			YAHOO.nubedo.timeout();
		},
		modifyCart : function (e,obj) {
			var afterComplete = false;
			if (!obj) var obj = this;
			if (obj.tagName == 'FORM') {
				$E.stopEvent(e);
				theForm = obj;
			}else{
				forms = document.getElementsByTagName("FORM");
				for (i=0;i<forms.length;i++) {
					if ($D.isAncestor(forms[i],obj)) {
						theForm = forms[i];	
					}
				}
			}
			if ($D.hasClass(obj,'btn_checkout')) {
				$E.stopEvent(e);
				afterComplete = true;
				theForm = obj.parentNode.parentNode;
			}
			YAHOO.nubedo.cancel();
			YAHOO.nubedo.cancelUpdate();
			YAHOO.util.Connect.setForm(theForm);
			var callback = {
				success: function (o) {
					if (afterComplete == true) {
						window.location = '/checkout/step1';
						return;
					}
					YAHOO.nubedo.updateCart(o);
				},
				failure: function (o) {  },
				timeout: 5000
			}
			var connection = YAHOO.util.Connect.asyncRequest('POST','/cart/modInline/',callback);
			
		},
		notifyStock : function (e) {
			$E.stopEvent(e)
			qty = this.href.substr(this.href.lastIndexOf('/')+1,this.href.length-this.href.lastIndexOf('/')+1);
			tgz = this.href.substr(0,this.href.lastIndexOf('/'));
			id = tgz.substr(tgz.lastIndexOf('/')+1,tgz.length-tgz.lastIndexOf('/')+1);
			post = 'qty['+id+']='+qty;
			YAHOO.nubedo.cancel();
			YAHOO.nubedo.cancelUpdate();
			var connection = YAHOO.util.Connect.asyncRequest('GET','/notify/'+id+'/'+qty+'/');
			YAHOO.nubedo.killError(e);
			
		},
		directModifyCart : function (e) {
			$E.stopEvent(e)
			qty = this.href.substr(this.href.lastIndexOf('/')+1,this.href.length-this.href.lastIndexOf('/')+1);
			tgz = this.href.substr(0,this.href.lastIndexOf('/'));
			id = tgz.substr(tgz.lastIndexOf('/')+1,tgz.length-tgz.lastIndexOf('/')+1);
			post = 'qty['+id+']='+qty;		
			YAHOO.nubedo.cancel();
			YAHOO.nubedo.cancelUpdate();			
			var callback = {
				success: function (o) { YAHOO.nubedo.updateCart(o); },
				failure: function (o) {  },
				timeout: 5000
			}
			var connection = YAHOO.util.Connect.asyncRequest('POST','/cart/modInline/',callback,post);
			YAHOO.nubedo.killError(e);
		},
		addcart : function(e) {
			$E.stopEvent(e);
			YAHOO.nubedo.cancel();
			YAHOO.util.Connect.setForm(this);
			postBody = 'output=json';
			
			var callback = {
				success: function(o) {
					YAHOO.nubedo.updateCart(o);
				},
				failure: function(o) { },
				timeout: 5000
			};
			var transaction = YAHOO.util.Connect.asyncRequest('POST',this.action, callback, postBody);
		},
		reorderCart : function() {
			var $mc = $('miniCart-body');
			var $fc = $('fullCart-body');
			var rows = $mc.getElementsByTagName("TR");
			x=1;
			for(i=0;i<rows.length;i++) {
				if (rows[i].style.display != 'none') {
					$D.removeClass(rows[i],'even');
					$D.removeClass(rows[i],'odd');
					if (x  %2 == 0) { $D.addClass(rows[i],'even'); }else{ $D.addClass(rows[i], 'odd'); }
					if (!$D.hasClass(rows[i],'nogiftwrap'))
					x++;
				}
			}
			if ($fc) {
				var full = $fc.getElementsByTagName("TR");
				x=1;
				for(i=0;i<full.length;i++) {
					if (full[i].style.display != 'none') {
						if (x  %2 == 0) { full[i].className = 'even'; }else{ full[i].className = 'odd'; }
						x++;
					}
				}
			}
			
		},
		killError : function (e) {
			$E.stopEvent(e);
			document.body.removeChild($('screen'));
			document.body.removeChild($('mc-error'));
		},
		cartError : function (errorMsg) {
			
			var scr = document.createElement("div");
			var a = new YAHOO.widget.Effect(scr);
			scr.className = 'screen';
			scr.id = 'screen';
			$D.setStyle(scr,'opacity',0);
			document.body.appendChild(scr);
			a.FadeIn(0.75,0.35);
			$E.on(scr,"click",YAHOO.nubedo.killError);
			
			error = document.createElement("div");
			var av = new YAHOO.widget.Effect(error);
			error.className = 'error';
			error.id = 'mc-error';
			error.innerHTML = errorMsg;
			$D.setStyle(error,'opacity',0);
			av.FadeIn(0.25,1);
			document.body.appendChild(error);
			ids = [ 'continue-shopping', 'closeviewer', 'close'];
			$E.on(ids,"click",YAHOO.nubedo.killError);
			
			// check for options
			var addFull = $('addFull');
			if (addFull) {
				$E.on(addFull,"click",YAHOO.nubedo.directModifyCart);
			}
		},
		updateCart : function(o,type) {
			YAHOO.nubedo.cancel();
			var newHeight = 0;
			var coll ='';
			var $mc = $('miniCart-body');
			var $fc = $('fullCart-body');
			var $fcc = $('functionsCartContent');
			var $mcc = $('miniCart');
			
			var data = YAHOO.lang.JSON.parse(o.responseText);
			notified = false;
			
			if (!YAHOO.lang.isUndefined(data.error)) {
				notified = true;
				var str = '';
				for(i in data.error) {
					str = str+"\n"+data.error[i];	
				}
				YAHOO.nubedo.cartError(str);
			}
			
			if (!YAHOO.lang.isUndefined(data.changes)) {
			// process additions
			if (!YAHOO.lang.isUndefined(data.changes.add)) {
			
				var add = data.changes.add;
				if (add) {
					for (id in add) {				
						empty = $('miniCartEmpty');
						if (empty) {
							$mc.deleteRow(0);
						}
						
						qty = add[id].qty
						price = add[id].price;
						subtotal = add[id].subtotal;
						plink = add[id].link;
						title = add[id].title;
						index = add[id].index;
						giftwrap = add[id].giftWrapPrice ? add[id].giftWrapPrice : false;
						giftwrapA = add[id].giftWrap ? add[id].giftWrap : false;
						giftwrapA = giftwrapA ? ' checked="checked"' : '';
						
						
						row = $mc.insertRow(index);
						if (index  %2 == 0) { rowClass = 'even'; }else{ rowClass = 'odd' }
						$D.addClass(row,rowClass);
						
						row.id = 'miniCart_'+id;
						$D.setStyle('miniCart_'+id,'opacity',0);
						
						row2 = false;
						if (giftwrap) {
							ni = index+1;
							row2 = $mc.insertRow(ni);
							$D.addClass(row,'nogiftwrap');
							$D.addClass(row2,'giftwrap');
							$D.addClass(row2,rowClass);
							row2.id = 'miniCart-gc_'+id;
							
							giftWrapC = row2.insertCell(-1);
							giftWrapC.colSpan = 3;
							giftWrapC.className = 'giftwrap';
							giftWrapC.id = row.id+'-giftwrap';
							giftWrapC.innerHTML = '<label for="giftwrap'+id+'" class="giftwrap"><input value="1" class="updateGiftWrap" type="checkbox" name="giftwrap['+id+']" id="giftwrap'+id+'"'+giftwrapA+'>Gift wrap for ';
							giftWrapC.innerHTML += giftwrap > 0 ? '$'+parseFloat(giftwrap).toFixed(2) : 'FREE';
							giftWrapC.innerHTML += '</label>';
						}
						
						titleC = row.insertCell(-1);
						titleC.id = row.id+'-title';
						titleC.innerHTML = '<h4><a href="'+plink+'">'+title+'</a></h4>';
						
						priceC = row.insertCell(-1);
						priceC.id = row.id+'-price';
						priceC.className = 'price';
						priceC.innerHTML = '$'+parseFloat(price).toFixed(2);
						
						qtyC = row.insertCell(-1);
						qtyC.id = row.id+'-qty';
						qtyC.className = 'qty';
						qtyC.innerHTML = '<input autocomplete="off" class="updateQty" size="3" name="qty['+id+']" value="'+qty+'" type="text">';
						
						subtotalC = row.insertCell(-1);
						subtotalC.id = row.id+'-subtotal';
						subtotalC.className = 'subtotal';
						subtotalC.innerHTML = '$'+parseFloat(subtotal).toFixed(2);
						if (giftwrap) { subtotalC.rowSpan = 2; }
						
						newHeight = parseInt(newHeight) + parseInt(row.offsetHeight);
						
						rowA = new YAHOO.widget.Effect(row);
						rowA.FadeIn(0.5,1);
						if (row2) {
							rowB = new YAHOO.widget.Effect(row2);
							rowB.FadeIn(0.5,1);
						}

					}
					
					if (notified != true) {
						YAHOO.nubedo.quickCartNotify(o,'add', id);
						notified = true;
					}
				}
			}
			
			// process mod
			if (!YAHOO.lang.isUndefined(data.changes.modify)) {
			
				mod = data.changes.modify;
				if (mod) {
					for (id in mod) {
						cur = mod[id];
						
						$('miniCart_'+id+'-title').getElementsByTagName("A").item(0).innerHTML = cur.title;
						$('miniCart_'+id+'-qty').getElementsByTagName("INPUT").item(0).value = cur.qty;
						$('miniCart_'+id+'-subtotal').innerHTML = '$'+parseFloat(cur.subtotal).toFixed(2);
						$('miniCart_'+id+'-price').innerHTML = '$'+parseFloat(cur.price).toFixed(2);
						if ($fc) {
							$('fullCart_'+id+'-title').getElementsByTagName("A").item(0).innerHTML = cur.title;
							$('fullCart_'+id+'-qty').getElementsByTagName("INPUT").item(0).value = cur.qty;
							$('fullCart_'+id+'-subtotal').innerHTML = '$'+parseFloat(cur.subtotal).toFixed(2);
							$('fullCart_'+id+'-price').innerHTML = '$'+parseFloat(cur.price).toFixed(2);							
						}
					}
					if (notified != true) {
					  YAHOO.nubedo.quickCartNotify(o,'update', 'false');
						notified = true;
					}
				}
			}
			
			// process removals
			if (!YAHOO.lang.isUndefined(data.changes.remove)) {
				rem = data.changes.remove;
				if (rem) {
					for (id in rem) {
						index = rem[id].index
						row = $('miniCart_'+id);
						row2 = $('miniCart-gc_'+id);
						var a2 = new YAHOO.widget.Effect(row2);
						a2.CartDelete(0.5);
						var a = new YAHOO.widget.Effect(row);
						a.CartDelete(0.5);
						
						if ($fc) {
							rowFull = $('fullCart_'+id);
							var aN = new YAHOO.widget.Effect(rowFull);
							aN.CartDelete(0.5);
						}
					}
					if (notified != true) {
					  YAHOO.nubedo.quickCartNotify(o,'remove', id);
						notified = true;
					}
				}
			}
			
			// update the total
			$('miniCart-total').innerHTML = '$'+parseFloat(data.total).toFixed(2);
			$('miniCart-subtotal').innerHTML = '$'+parseFloat(data.subtotal).toFixed(2);
			$('miniCart-shipping').innerHTML = '$'+parseFloat(data.shipping).toFixed(2);
			
			if (data.empty) {
				$D.addClass($mcc,'empty');
				$D.addClass($fcc,'empty');
				
				var newRow = $mc.insertRow(-1);
				newRow.id = 'miniCartEmpty';				
				var newCell = newRow.insertCell(0);				
				var newText = document.createTextNode('Your cart is empty');
				newCell.appendChild(newText);
				$D.setStyle('mcCheckout','display','none');
				
			}else{
				$D.removeClass($mcc,'empty');	
				$D.removeClass($fcc,'empty');
				$D.setStyle('mcCheckout','display','block');
			}
			
			if ($fc) {
				$('fullCart-total').innerHTML = '$'+parseFloat(data.total).toFixed(2);
				$('fullCart-subtotal').innerHTML = '$'+parseFloat(data.subtotal).toFixed(2);
				$('fullCart-shipping').innerHTML = '$'+parseFloat(data.shipping).toFixed(2);
			}
			YAHOO.nubedo.reorderCart();
			YAHOO.nubedo.refreshUpdate();
			if (!$fc) {
				YAHOO.nubedo.showcart(o,newHeight);
			}
			}
			
		}
	};
}();

YAHOO.util.Event.onDOMReady(YAHOO.nubedo.init, YAHOO.nubedo, true);