    var whizcart_items = 0;
    var whizcart_expand_content = '';
    $('document').ready( function () {
    
        var whizcart_open = 0;
        go_away_gadget_whizcart = function () {
            $('#livecart_content').slideUp('slow');
            $('#whizcart_compact').remove();
            if (whizcart_expand_content) $('#livecart_expanderhook').html(whizcart_expand_content);
            $('#whizcart_expand').click( function () { go_go_gadget_whizcart(); });
            whizcart_expand_content = false;
        }
        
        go_go_gadget_whizcart = function (haltslide){   
           var itemCount = 0;

           var lookup_url = ('https:' == document.location.protocol) ? 'https://secure.potn.com/~potncom/' : '';
           if ( typeof(lookup_url_overide)!='undefined') lookup_url = lookup_url_overide; 

           $.ajax({
               url: lookup_url + 'includes/functions/whiz_cart_ajax.php' +whizcart_force_site_id,
               type: 'POST',
               data: "imagesize=65&reverse=1",
               dataType: 'json',
               success: function(result){
                   var mother = document.getElementById('livecart_content');
                   whizcart_open = 0;
                   whizcart_items = -1; 

//                   mother.innerHTML = "<div class='whizcart_image'><img src='"+whizcart_bag_image+"' alt='"+whizcart_bag_item+"'/></div>";
//                   mother.innerHTML += "<div class='whizcart_items whizcartexpanded' style='cursor:pointer' onclick='go_away_gadget_whizcart()'>Your basket contains</div>";
//                   mother.innerHTML += "<div style='clear:both'></div>";
                    mother.innerHTML = "<div style='height:10px'></div>";
                   
                   for (var item in result){
                       if (result[item]['name'] && result[item]['qty'] && result[item]['price']){
                           itemCount = itemCount + 1;
                           if (item > whizcart_items) whizcart_items = item;
                           
                           var daughter = document.createElement('div');
                           daughter.setAttribute('id','whizcart_item_'+item);

                           var image = document.createElement('div');
                           image.setAttribute('id','whizcart_item_image_'+item);
                           image.innerHTML = result[item]['image'];

                           if (whizcart_editable) {
                               var deleteline = document.createElement('div');
                               deleteline.setAttribute('id','whizcart_line_remove_'+item);
                               deleteline.setAttribute('line',item);
                               deleteline.style.fontSize = '12px';
                               deleteline.style.fontWeight = 'bold';
                               deleteline.style.cursor = 'pointer';
                               deleteline.style.display = 'inline-block';
                               deleteline.style.marginTop = '-2px';
                               deleteline.style.marginLeft = '10px';
                               deleteline.style.color = 'red';
                               deleteline.innerHTML = 'x';
                           
                               var remove = document.createElement('div');
                               remove.setAttribute('id','whizcart_item_remove_'+item);
                               remove.innerHTML = '<img src='+whizcart_minus_image+' alt="-"/>';
                           }

                           var qty = document.createElement('div');
                           qty.setAttribute('id','whizcart_item_qty_'+item);
                           qty.innerHTML = result[item]['qty'];

                           if (whizcart_editable) {
                               var add = document.createElement('div');
                               add.setAttribute('id','whizcart_item_add_'+item);
                               add.innerHTML = '<img src='+whizcart_plus_image+' alt="+"/>';
                           }
                           
                           var name = document.createElement('div');
                           name.setAttribute('id','whizcart_item_name_'+item);
                           name.innerHTML = "<a href='"+whizcart_domain+"_p"+result[item]['id']+".htm'>"+result[item]['name']+"</a>";
                            
                           var price = document.createElement('div');
                           price.setAttribute('id','whizcart_item_price_'+item);
                           price.innerHTML = '<br>'+whizcart_currency_symbol+result[item]['price'];

                           var productid = document.createElement('div');
                           productid.setAttribute('id','whizcart_item_id_'+item);
                           productid.innerHTML = result[item]['id'];
                            
                           var eol = document.createElement('div');
                           eol.setAttribute('id','whizcart_item_eol_'+item);
 
                           var quantity_container = document.createElement('div');
                           quantity_container.style.clear='right';
                           if (whizcart_editable) quantity_container.appendChild(deleteline);
                           if (whizcart_editable) quantity_container.appendChild(remove);
                           quantity_container.appendChild(qty);
                           if (whizcart_editable) quantity_container.appendChild(add);

                           daughter.appendChild(image);
                           daughter.appendChild(name);
                           daughter.appendChild(quantity_container);
                           daughter.appendChild(price);
                           daughter.appendChild(productid);
                           daughter.appendChild(eol);
                           mother.appendChild(daughter);

                           $('#whizcart_item_'+item).addClass('whizcart_item_line');
                           $('#whizcart_item_image_'+item).addClass('whizcart_image');
                           $('#whizcart_item_name_'+item).addClass('whizcart_item_description');
                           $('#whizcart_item_remove_'+item).addClass('whizcart_item_less_button');
                           $('#whizcart_item_qty_'+item).addClass('whizcart_item_qty');
                           $('#whizcart_item_add_'+item).addClass('whizcart_item_more_button');
                           $('#whizcart_item_price_'+item).addClass('whizcart_item_price');
                           $('#whizcart_item_id_'+item).css('display','none');
                           $('#whizcart_item_eol_'+item).css('clear','both');
                           $('#whizcart_line_remove_'+item).addClass('whizcart_deleteline');
                       }
                   }
                   
                   if (itemCount>0) {
                        $('#livecart_checkout_button').children('img').each( function () {
                            $(this).attr('src',livecart_checkout_btn_image);
                        });
                        $('#livecart_checkout_button').attr('href',livecart_checkoutpageurl);
                        $('.livecart_top').css('background','url('+livecart_active_back_whole+')');
                        $('.livecart_content').css('background','url('+livecart_active_back_middle+')');
                        $('.livecart_middle').css('background','url('+livecart_active_back_whole+') repeat bottom');
                   }
                   else {
                        if ( typeof(livecart_loginpageurl)!='undefined' ) {               
                            $('#livecart_checkout_button').children('img').each( function () {
                                $(this).attr('src',livecart_login_btn_image);
                            });
                            $('#livecart_checkout_button').attr('href',livecart_loginpageurl);
                        }
                        $('.livecart_top').css('background','url('+livecart_back_whole+')');
                        $('.livecart_content').css('background','url('+livecart_back_middle+')');
                        $('.livecart_middle').css('background','url('+livecart_back_whole+') repeat bottom');
                   }
                        
                   var totals = document.createElement('div');
                   totals.setAttribute('id','whizcart_total_line');
                                           
                   var description = document.createElement('div');
                   description.setAttribute('id','whizcart_total_description');
                   description.innerHTML = 'Total';
                        
                   var text = (result['total_items'] == 1) ? '&nbsp;piece' : '&nbsp;pieces';
                   var items = document.createElement('div');
                   items.setAttribute('id','whizcart_total_items');
                   items.innerHTML = result['total_items']+text;
                        
                   var finalPrice = document.createElement('div');
                   finalPrice.setAttribute('id','whizcart_total_price');
                   finalPrice.innerHTML = whizcart_currency_symbol+result['total_price'];
                   
                   var newline = document.createElement('div');
                   newline.setAttribute('id','whizcart_newline');
                   
                   if (!whizcart_expand_content) {
                        $('#whizcart_expand').css('display','block');
                        whizcart_expand_content = $('#livecart_expanderhook').html();
                        document.getElementById('whizcart_expand').innerHTML = '';
                        var contract = document.createElement('div');
                        contract.setAttribute('id','whizcart_compact');
                        contract.innerHTML = "<img src='"+whizcart_collapse_icon+"' alt=''/>Close Basket";
                        document.getElementById('livecart_expanderhook').appendChild(contract);
                   }
                   
                   totals.appendChild(description);
                   totals.appendChild(items);
                   totals.appendChild(finalPrice);
                   totals.appendChild(newline);
                   mother.appendChild(totals);

                   $('#whizcart_total_line').addClass('whizcart_total_line');
                   $('#whizcart_total_description').addClass('whizcart_total_description');
                   $('#whizcart_total_items').addClass('whizcart_total_information');
                   $('#whizcart_total_price').addClass('whizcart_total_price');
                   $('#whizcart_newline').css('clear','both');
                   $('#whizcart_compact').addClass('whizcart_expand');
                   $('#whizcart_compact').click( function () { go_away_gadget_whizcart() });

                    switch (parseInt(whizcart_items)) {
                        case -1:
                            $('#whizcart_items').html('No items');
                            $('#whizcart_expand').css('display','none');
                            break;
                        case 0:
                            $('#whizcart_items').html('1 item');
                            break;
                        default:
                            $('#whizcart_items').html(itemCount+' items');
                            break;
                    }
                    document.getElementById('whizcart_price').innerHTML = whizcart_currency_symbol+result['total_price'];


                   $('#whizbang_cart').ready( function (){
                  
                       $('.whizcart_deleteline').click( function () {
                          $('#whizcart_item_qty_'+$(this).attr('line')).html(1);
                          $('#whizcart_item_remove_'+$(this).attr('line')).trigger('click');
                       });
                  
                       $('.whizcart_item_less_button').click( function () {
                           for (var item=0; item<=whizcart_items; item++){
                               if ( $(this).attr('id') == 'whizcart_item_remove_'+item){
                                    var productid = document.getElementById('whizcart_item_id_'+item).innerHTML;
                                    var qty = parseInt(document.getElementById('whizcart_item_qty_'+item).innerHTML)-1;
                                    document.getElementById('whizcart_item_qty_'+item).innerHTML='&nbsp;';

                                    if (qty == parseInt(qty) && qty!='NaN'){
                                        if (qty == 0){
                                            $.ajax({
                                                url: whizcart_remove_url,
                                                type: 'POST',
                                                data: "cart_delete=1&customer_id="+whizcart_custid+"&products_id="+productid,
                                                dataType: 'html',
                                                success: function(result){
                                                    go_go_gadget_whizcart();
                                                    if (typeof(update_shopping_cart)=='function') update_shopping_cart();
                                                }
                                            });                                    
                                        }
                                        else {
                                            $.ajax({
                                                url: whizcart_remove_url,
                                                type: 'POST',
                                                data: "customer_id="+whizcart_custid+"&products_id="+productid+"&qtyupd="+qty,
                                                dataType: 'html',
                                                success: function(result){
                                                    go_go_gadget_whizcart();
                                                    if (typeof(update_shopping_cart)=='function') update_shopping_cart();
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                       });

                       $('.whizcart_item_more_button').click( function () {
                           for (var item=0; item<=whizcart_items; item++){
                               if ( $(this).attr('id') == 'whizcart_item_add_'+item){
                                    var productid = document.getElementById('whizcart_item_id_'+item).innerHTML;
                                    var qty = parseInt(document.getElementById('whizcart_item_qty_'+item).innerHTML)+1;
                                    document.getElementById('whizcart_item_qty_'+item).innerHTML='&nbsp;';

                                    if (qty == parseInt(qty) && qty!='NaN'){
                                        $.ajax({
                                            url: whizcart_remove_url,
                                            type: 'POST',
                                            data: "customer_id="+whizcart_custid+"&products_id="+productid+"&qtyupd="+qty,
                                            dataType: 'html',
                                            success: function(result){
                                                go_go_gadget_whizcart();
                                                if (typeof(update_shopping_cart)=='function') update_shopping_cart();
                                            }
                                        });
                                    }
                                }
                            }
                       });
                   });
                   
                   if(!haltslide) $('#livecart_content').slideDown('slow');                       
               }
           });
        }
        
        $('#whizcart_expand').click( function () {
            $('#livecart_content').slideUp('slow', function () {
                go_go_gadget_whizcart();
            });
        });
    });

