// JavaScript Document
//var store = readCookie("storeCookie.storeId");
//var catalog = readCookie("storeCookie.catalogId");
//var lang = readCookie("storeCookie.languageId");
var persistentCartCommands = new Array(8);
persistentCartCommands[0] = 'CusaMiniShopCartDisplay?updatePrices=1&calculationUsageId=-1&catalogId=10051&storeId=10051&langId=-1&orderId=.';

/* Here is where you would add commands such as the following
To control when the persistent cart changes
persistentCartCommands[1] = 'checkout/add_item_pc.cmd';
persistentCartCommands[2] = 'checkout/add_items_pc.cmd';
persistentCartCommands[3] = 'checkout/delete_item_in_cart.cmd';
persistentCartCommands[4] = 'checkout/add_catalog_order_item_pc.cmd';
persistentCartCommands[5] = 'user/add_wishlist_item_to_basket_pc.cmd';
*/

var persistentCartContainerId = "#widget-ucart";
var persistentCartCloseButClass = ".widget-ucart-close-but";
var hideTimeOuts = new Array();

var cart_animationMethod = "chain";
var cart_animG;
var cart_newLeft = 0;
var cart_boxMixin = { duration: 1000 };

/* Function(s) to Show the Basket Layer */
/* Here is where you would call the various commands to load the cart such as add product, add kit, etc*/
function showBasket() {
	/* Positiion to put basket */
	var newPos = lib.utils.getPosition(".cart")[0];
   newPos[0] += 70;
   newPos[1] += 5;
  
	/* URL to call */
	requestURL = persistentCartCommands[0];
	requestURL = requestURL;
	
	/* Show Loading State */
	lib.layer.create(persistentCartContainerId, {
		url : requestURL,
		defaultContent : "<div class='layerTemplate2 loading ie6png'><img src='/wcsstore/eStore/images/loading.gif' alt='Loading...' /></div>",
		xPos : newPos[0],
		yPos : newPos[1],
		callback : function() { setupPersistentCartButtons(); }
	});	
};

//edit this function to update the setup
function setupPersistentCartButtons() {
	
	// draw focus near this
	window.location = "#";
	clearAllTimeouts();
	
	/* Setup the Close Button */
	dojo.query(".widget-ucart-close-but").connect("onclick", function(e) {
	    dojo.stopEvent(e);
	    hideBasket();
	});
	/* --------------- */
	
	/* Setup the Slider */
	new lib.obj.itemSlider({
		viewport: "#cart-items .viewport",
      content: "#cart-items .content",
      next: "#cart-items .button .js-buttonNext",
      prev: "#cart-items .button .js-buttonPrevious",
      item: "#cart-items .item",
      direction: "horizontal",
      showAmount: 1
   });
	/* ------------------ */
	
	/* Update the Item count */
	updateCount();
	//updateItemCount(dojo.query("#cart-items .item div").length);
	
};

//Edit this function if need to do something special on basket close.
function hideBasket() {
	lib.layer.remove(persistentCartContainerId);	
};

// Update the Item Count in the Cart and in the Header
function updateItemCount(count) {
	dojo.query(".cartItemCount").forEach(function( area ) { area.innerHTML = count; });
	dojo.query("a.cart").forEach(function( area ) {	area.innerHTML = count + " Items in Shopping Cart"; });
};

function clearAllTimeouts() {
    for (x = 0; x < hideTimeOuts.length; x++)
    { clearTimeout(hideTimeOuts[x]); }
};