var products = product.length; //product.length = 0; var currentNum = 0; var thumbnailImgPath = "images/"; function decodePrice(input) { var newPrice = ""; if (input.indexOf("&") >= 0) { var suffix = input.substring(input.indexOf("&") - 1); input = input.substring(0, input.indexOf("&") - 1); for (var i = 0; i < input.length; i++) { var tempChar = input.charAt(i); if (input.charCodeAt(i) > 255 || input.charCodeAt(i) == 160) { tempChar = '.'; } newPrice = newPrice + tempChar; } newPrice = newPrice + suffix; } else { newPrice = input; } return newPrice; } function showRecentlyAdded() { var prodName = document.getElementById('prodTitle'); var imageShot = getImageNode() var prodPrice = document.getElementById('prodPrice'); var prodQty = document.getElementById('prodQty'); var revPrice = document.getElementById('miniCartRevPrice'); var initPrice = document.getElementById('miniCartInitPrice'); currentNum = product.length - 1; prodName.innerHTML = product[currentNum].productName; prodPrice.innerHTML = decodePrice(product[currentNum].formattedCurrency); prodQty.innerHTML = "Qty: " + product[currentNum].qty; if (product[currentNum].revPrice != null && product[currentNum].revPrice != "null") { revPrice.innerHTML = decodePrice(product[currentNum].revPrice) + "
Subscription Service"; initPrice.innerHTML = decodePrice(product[currentNum].initPrice) + "
Initial Manual"; } else { revPrice.innerHTML = ""; initPrice.innerHTML = ""; } imageShot.src = thumbnailImgPath + product[currentNum].image; } function moveRight(e){ var prodName = document.getElementById('prodTitle'); var imageShot = getImageNode(); var prodPrice = document.getElementById('prodPrice'); var prodQty = document.getElementById('prodQty'); var revPrice = document.getElementById('miniCartRevPrice'); var initPrice = document.getElementById('miniCartInitPrice'); if(currentNum == product.length -1){ currentNum = 0; } else{ currentNum++; } prodName.innerHTML = product[currentNum].productName; prodPrice.innerHTML = decodePrice(product[currentNum].formattedCurrency); prodQty.innerHTML = "Qty: " + product[currentNum].qty; if (product[currentNum].revPrice != null && product[currentNum].revPrice != "null") { revPrice.innerHTML = decodePrice(product[currentNum].revPrice) + "
Subscription Service"; initPrice.innerHTML = decodePrice(product[currentNum].initPrice) + "
Initial Manual"; } else { revPrice.innerHTML = ""; initPrice.innerHTML = ""; } imageShot.src = thumbnailImgPath + product[currentNum].image; $E.stopEvent(e); } function moveLeft(e){ var prodName = document.getElementById('prodTitle'); var imageShot = getImageNode() var prodPrice = document.getElementById('prodPrice'); var prodQty = document.getElementById('prodQty'); var revPrice = document.getElementById('miniCartRevPrice'); var initPrice = document.getElementById('miniCartInitPrice'); if(currentNum == 0){ currentNum = product.length -1; } else{ currentNum--; } prodName.innerHTML = product[currentNum].productName; prodPrice.innerHTML = decodePrice(product[currentNum].formattedCurrency); prodQty.innerHTML = "Qty: " + product[currentNum].qty; if (product[currentNum].revPrice != null && product[currentNum].revPrice != "null") { revPrice.innerHTML = decodePrice(product[currentNum].revPrice) + "
Subscription Service"; initPrice.innerHTML = decodePrice(product[currentNum].initPrice) + "
Initial Manual"; } else { revPrice.innerHTML = ""; initPrice.innerHTML = ""; } imageShot.src = thumbnailImgPath + product[currentNum].image; $E.stopEvent(e); } function getImageNode() { var imageShot = document.getElementById('cartProd'); if(!imageShot) { var container = document.getElementById('imageBox'); imageShot = document.createElement('img'); imageShot.setAttribute('name', 'cartProd'); imageShot.setAttribute('id', 'cartProd'); imageShot.setAttribute('alt', ''); container.appendChild(imageShot); } return imageShot; } function closeCart(e){ var cartArea = $('productDetails'); if(!$D.hasClass(cartArea, 'hide')){ $D.addClass(cartArea, 'hide') $('closeCart').innerHTML = "open"; } else{ $D.removeClass(cartArea, 'hide'); $('closeCart').innerHTML = "close"; } $E.stopEvent(e); } function init(){ var subTotal = document.getElementById('subTotal'); if (!subTotal) {return false;} var cartSubTotal = 0; var numItems = 0; // total number of items to purchase for(var i=0; i < product.length; i++){ var price = parseFloat(product[i].price); var quantity = parseInt(product[i].qty); cartSubTotal += (price * quantity); numItems += quantity; } //subTotal.innerHTML = cartSubTotal.toFixed(2); if (product.length != 0) { subTotal.innerHTML = product[product.length-1].subTotal; } var itemCount = document.getElementById('itemCounter'); //assign variable to the clickable areas var right = document.getElementById('arrowRight'); var left = document.getElementById('arrowLeft'); var closer = document.getElementById('closeCart'); var cartDisplay = document.getElementById('cartTrigger'); if( product.length == 1){ var itemDetails = $('itemDetails'); var itemDesc = $('cartDesc'); $D.removeClass(cartDisplay, "hide"); var arwRight = document.getElementById('arrowRight'); var arwLeft = document.getElementById('arrowLeft'); arwRight.style.display = 'none'; arwLeft.style.display = 'none'; itemDetails.style.width= 210 + 'px'; itemDesc.style.width = 120 + 'px'; //itemCount.innerHTML = product.length; /*$D.removeClass(cartDisplay, "hide"); /*$D.addClass(right, "hide"); $D.addClass(left, "hide"); document.getElementById('arrowRight').style.background = "none"; document.getElementById('arrowLeft').style.background = "none"; itemCount.innerHTML = numItems;*/ } else if( product.length > 1 ){ //itemCount.innerHTML = numItems; $D.removeClass(cartDisplay, "hide"); // we may only have one product type, so no need to show arrows if (product.length == 1) { document.getElementById('arrowRight').style.background = "none"; document.getElementById('arrowLeft').style.background = "none"; } else { $D.removeClass(right, "hide"); $D.removeClass(left, "hide"); } } else if(numItems == 0){ var cartStatus = document.getElementById('cartStatus'); itemCount.innerHTML = 0; cartStatus.innerHTML = "Your shopping cart is empty! Go shopping!"; return; } showRecentlyAdded(); //attach event listeners to the clickable areas YAHOO.util.Event.addListener(right, "click", moveRight); YAHOO.util.Event.addListener(left, "click", moveLeft); YAHOO.util.Event.addListener(closer, "click", closeCart); } //run the init function YAHOO.util.Event.addListener(window, "load", init);