var minicart = new Object();
minicart.quantity  = 0;
minicart.store_id  = "*1c21b9f5f00a3846f0dc17ef60750158";
minicart.serialno  = "0001236872";
minicart.cookie_name_string = "ss_cart_" + minicart.serialno;
minicart.div_id = '';
minicart.add = function(item) {	
this.cookie_value = util.readCookie(this.cookie_name_string);
updateShopSite(item.item_number);
item_price  = parseFloat(item.price.replace(/^\$/, ''));
item_name   = item.cart_name;
item_number = item.item_number;
if (this.cookie_value) { 
var parts = this.cookie_value.split("|");
this.lineCount = parts[1].substring(parts[1].indexOf(":")+1);
this.quantity  = parts[2].substring(parts[2].indexOf(":")+1);
this.subtotal  = parts[3].substring(parts[3].indexOf(":")+2); 
this.prodcuts = new Array();
var product_index = 0;
for (var i=4; i<parts.length; i++) { if (parts[i].length > 0) {    		var vals = parts[i].split(":");
this.prodcuts[product_index++] = {'qty':vals[0], 'price':vals[1], 'name':vals[2]};}}
var already_line = false;
for (i=0; i<this.prodcuts.length; i++) { if (this.prodcuts[i]['name'] == item_name) {  			this.prodcuts[i]['qty']++;
already_line = true;
break;}}
if (!already_line) {  		this.lineCount++;
this.prodcuts[this.prodcuts.length] = {'qty':1, 
'price':'$'+item_price, 
'name':item_name};} 
this.quantity++;
this.subtotal += item_price;
var new_cookie_value = "|LineCnt:" + this.lineCount + 
"|QntyTotal:" + this.quantity + 
"|SubTotal:$" + this.subtotal + "|";
for (i=0; i<this.prodcuts.length; i++) {new_cookie_value  += this.prodcuts[i]['qty'] + ":" +
this.prodcuts[i]['price'] + ":" +
this.prodcuts[i]['name'] + "|";}} else {var new_cookie_value = "|LineCnt:1" + 
"|QntyTotal:1" +
"|SubTotal:$" + item_price + "|" +
"1:" + item_price + ":" + item_name + "|";}
document.cookie = this.cookie_name_string + "=" + new_cookie_value +
"; path=/";
this.update();}
minicart.getQuantity = function() {		this.cookie_value = util.readCookie(this.cookie_name_string);
if (this.cookie_value) {	    var parts = this.cookie_value.split("|");
this.quantity = parts[2].substring(parts[2].indexOf(":")+1);}}
function initializeMiniCart(div_id) {	minicart.div_id = div_id;
minicart.showCart(); }
function isMiniCartOnPage() {	return ($('minicart'));}
minicart.showCart = function() {	var cart_div = $(this.div_id);
this.getQuantity();
cart_div.innerHTML  = "|" + this.quantity + "|&nbsp;";
cart_div.innerHTML += '<a href="/cgi-bin/sc/order.cgi?storeid=*1c21b9f5f00a3846f0dc17ef60750158&function=show">checkout</a>';}
minicart.update = function() {	this.showCart();
new Effect.Highlight(this.div_id, {startcolor:'#FFFFFF', endcolor:'#93ADBA', duration: 1.5});}
function updateShopSite(itemNum) {	var url  = "/cgi-bin/sc/order.cgi";
var pars = "storeid=*1c21b9f5f00a3846f0dc17ef60750158&dbname=products&itemnum=" +
itemNum + "&function=add";
new Ajax.Request(url + '?' + pars, {    method: 'get',
onComplete: function(request) { }});}
