// JavaScript Document


var CART={ // v1.1
	anchors:[],
	div:null,
	addItem:function(partid){
		CART.div.innerHTML="<div class=\"loading\"><img src=\"/_img/anim-loading.gif\" /></div>";
		cartCode=SERVERREQUEST.get("/cart/cart-display.asp?m=0&p="+partid);
		CART.div.innerHTML=cartCode;
		BLOOMER.captureAnchors("cart");
		return false;
	},
	removeItem:function(partid){
		CART.div.innerHTML="<img src=\"/_img/anim-loading.gif\" />";
		cartCode=SERVERREQUEST.get("/cart/cart-display.asp?m=0&r="+partid);
		CART.div.innerHTML=cartCode;
		BLOOMER.captureAnchors("cart");
		return false;
	},
	init:function(){
		CART.div=$.getById("cart");
		CART.anchors=$.getByClass("cartadd",null);
		for(var i=0;i<CART.anchors.length;i++){
			CART.anchors[i].listitem=CART.anchors[i].parentNode;
			CART.anchors[i].actionlabel=$.getByTag("span",CART.anchors[i].listitem)[0];
			CART.anchors[i].partid=String(CART.anchors[i].id).replace(/[image|title]/gi,"");
			CART.anchors[i].onclick=function(){
				if(this.actionlabel.innerHTML=="remove from cart"){
					this.listitem.className="unselected";
					this.actionlabel.innerHTML="add to cart";
					return CART.removeItem(this.partid);
				} else {
					this.listitem.className="selected";
					this.actionlabel.innerHTML="remove from cart";
					return CART.addItem(this.partid);
				}
			}
		}
	}
};

GLOBALS.addOnload(CART.init);