/**
 *
 * @access public
 * @return void
 **/
 /**
  *
  * @access public
  * @return void
  **/
 function updateShoppingListContent(responseText){
						var response = $(responseText).clone();

						$("#shoppingListLeft").remove();
						$("#shoppingListRight").remove();
						$(".shoppingListProductCarousel").replaceWith(response);

						jQuery('#mycarousel').jcarousel({visible:3});
						jQuery('#mycarousel2').jcarousel({visible:3});
						$(".processShoppingListChange").ajaxForm({
      				dataType:"html",
      				data: {type:1},
          url: ROOT_PAGE_PATH+"AJAX_shoppingList.php",
										success: updateShoppingListContent
						});
						$("input[type=checkbox]").attr('checked',false);

						$(".quickBuy").click(function() {

         var idString;
         idString = $(this).children("img").attr('id');

         idParts = idString.split("~~");
         var id = idParts[0];
         var type = idParts[1];
         $.get(ROOT_PAGE_PATH+"getVersionsAjax.php", {"id": id,"productType":type},
         function(data)
         {
             var title = data.versions[0].title;
             var shortDescription = data.versions[0].shortDescription;
             var form;
             form="<div id='oneClickContainer'><div id='oneClickHeader'><h1>Buy Product</h1><span class='close'><a href='#' class='closeOneClick'><img src='"+ROOT_PAGE_PATH+"images/mainSite/close.jpg'/></a></span></div><div id='oneClickSlice'><h1>"+title+"</h1>"+shortDescription+"<br /><br /><table style='width:250px;margin-left:auto;margin-right:auto;' cellspacing='10px'>";

             //For each array row returned. There should be only one in this case
             $.each(data.versions,function(index,item){
                  var versionID;
                 var productID;
                 var priceRetail;
                 var priceMember;
                 var priceWholesale;
                 var weightGrammes;
                 var customerType;
                 var minWholesale;

                 customerType = item.customerType;
                 versionID = item.versionID;
                 productID = item.productID;
                 weightGrammes = item.weightGrammes;
                 versionPrice = item.versionPrice;
                 priceMember = item.priceMember;
                 priceWholesale = item.priceWholesale;
                 minWholesale = item.minWholesaleOrder;

                 form = form+"<tr><td>"+weightGrammes+"</td><td>&pound;"+versionPrice+"</td><td><form action='' method='post' class='itemAddForm'><input type='hidden' name='productType' value='"+type+"' /><input type='hidden' name='cartOperation' value='true' /><input type='hidden' name='versionID' value='"+versionID+"' /><input type='hidden' name='productID' value='"+productID+"' /><input type='text' size='1' maxlength='3' name='quantity' value='1' />&nbsp;<input type='image' class='addToCart' src='"+ROOT_PAGE_PATH+"images/mainSite/basket_addv3.jpg' name='submit' style='width: 50px; position:relative;top:3px;' /><input type='hidden' name='addItem' value='true' /></form></td></tr>";
                 //alert(customerType);
                 if(customerType=="MEMBER"||customerType=="RETAIL"){
                     form = form+"<tr style='color:red'><td colspan='3'>Member Price: &pound;"+priceMember+"</td></tr>";
                 }
                 if(customerType=="WHOLESALE"){
                     if(type=="PRODUCT"){
																									form = form+"<tr style='color:red'><td colspan='3'>Wholesale Price: &pound;"+priceWholesale+" ["+minWholesale+"]</td></tr>";
                 				}
																	}
             });
             form = form+"</table></div><div id='oneClickFooter'></div></div>";
             //REMOVE EXISTING QUICKBUY FORM
             $("#oneClickContainer").remove();
             $("body").append(form);
             $("#oneClickContainer").hide();



             $.blockUI({
                 message: $("#oneClickContainer"),
                 //message: "<p>Hello World</p>",
                 css: {cursor:null, background: 'transparent'},
                 overlayCSS: { backgroundColor: '#ffffff',cursor:null}
             });

             $('.itemAddForm').ajaxForm({
                 dataType:null,
                 success: function(responseText, statusText) {
                     $.unblockUI();

                     $(".basketPreview").show();
                     $(".totalBox").html("Updating");

                     //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA
                     $.post(ROOT_PAGE_PATH+"getShoppingCartAjax.php",null,function(data){
                         //now update basket preview

                         //remove all rows
                         $(".basketPreview table").empty();

                         //now loop over all items in data
                         $.each(data.items,function(index,item){
                             var row = "<tr><td style='text-align:right;'>"+item.quantity+"x</td><td style='text-align:left;'>"+item.name+"</td><td style='text-align:left;'>&pound;"+item.subTotal+"</td></tr>";
                             $(".basketPreview table").append(row);
                         });


                         //now update total
                         // $(".basketPreview .totalBox .middleBar").html("Total &pound;"+data.total);
                         $(".totalBox").html("&pound;"+data.total);

                         $(".basketEmptyText").empty();

                         //now update basket count
                         $('.cartText').html(data.cartText);

                         /* Not required now
                         $(".basketLink").click(function(){
                              $(".basketPreview").slideToggle(500);
                              return false;
                         });*/

                     },"json");
                 }
             });


             $(".closeOneClick").click(function() {
                $.unblockUI();
             });


         }, "json");
         return false;
     });
			}

function addFavSwitch(responseText, statusText) {
    //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA
    //alert(responseText.count);

    if(responseText.error!=null){
        alert(responseText.error);
    }
    else{
        //alert(responseText.count)
        $("#favouriteCounter").html(responseText.count);

        var removeFavForm = "<div class='removeFromFavouritesCategories'><form action='' method='post' class='swapFavouriteForm'><input type='hidden' name='productID' value='"+responseText.id+"' /><input type='hidden' name='productType' value='"+responseText.productType+"' /><input type='hidden' name='addRemove' value='REMOVE' /><input type='hidden' name='customerID' value='"+responseText.customerID+"' /><input type='image' style='position:relative;top:3px;' name='submit' src='"+ROOT_PAGE_PATH+"images/mainSite/cart_minus.gif' alt='Remove from favourites' />&nbsp;&nbsp;Remove from favourites</form></div>";
        $("#favouriteCounter").html(responseText.count);
        $('input[name|=productID][value|='+responseText.id+']').closest("div.addToFavouritesCategories").replaceWith(removeFavForm);

        $('.swapFavouriteForm').ajaxForm({
            dataType:"json",
            url: ROOT_PAGE_PATH+"removeFavAJAX.php",
            success: swapFavSwitch
        });

        /*$('.swapFavouriteForm').ajaxForm({
            dataType:"json",
            url: ROOT_PAGE_PATH+"removeFavAJAX.php",
            success: swapFavSwitch
      });*/

    }
}

/**
 *
 * @access public
 * @return void
 **/
function swapFavSwitch(responseText, statusText) {
    //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA

    var addFavForm = "<div class='addToFavouritesCategories'><form action='' method='post' class='addFavouriteForm'><input type='hidden' name='productID' value='"+responseText.id+"' /><input type='hidden' name='productType' value='"+responseText.productType+"' /><input type='hidden' name='addRemove' value='ADD' /><input type='hidden' name='customerID' value='"+responseText.customerID+"' /><input type='image' style='position:relative;top:3px;' name='submit' src='"+ROOT_PAGE_PATH+"images/mainSite/cart_plus.gif' alt='Add to regular buys' />&nbsp;&nbsp;Add to regular buys</form></div>";
    $("#favouriteCounter").html(responseText.count);
    $('input[name|=productID][value|='+responseText.id+']').closest("div.removeFromFavouritesCategories").replaceWith(addFavForm);

    $('.addFavouriteForm').ajaxForm({
        dataType:"json",
        url: ROOT_PAGE_PATH+"addToFavAJAX.php",
        success: addFavSwitch
    });
}

function removeListItem(){
    $.post(ROOT_PAGE_PATH+"getShoppingListAjax.php",null,function(data){
        //now update basket preview

        //remove all rows
        $(".paperSlice table tr").remove();

        //now loop over all items in data
        if(data.items.length>0){
            $.each(data.items,function(index,item){
                var row = '<tr><td width="330">'+item+'</td><td width="50"><form class="removeListItem" action="" method="post"><input type="hidden" name="removeKey" value="'+index+'" /><input type="hidden" name="removeValue" value="'+item+'" /><input type="submit" class="submitButton" value="Remove" /></form></td></tr>';
                $(".paperSlice table").append(row);
            });
        }
        else{
            var row ="<tr><td>Please add you product in the box above and click add to list.</td></tr>";
            $(".paperSlice table").append(row);
        }

        $(".removeListItem").ajaxForm({
            success: removeListItem
        });
    },"json");
}

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = 0;
  });
};

//delcare promt function
//presents a carousel which posts to the index page
function promptForHubSelection(errors)
{
   errorText = "";

			if(errors.length>0){
    			errorText = "<p class='errorDisplay' style='width:390px;'>";

    			for(var i=0; i<errors.length; i++){
        			errorText += errors[i]+"<br/>";
    			}

    			errorText += "</p>";
			}

   $.get(ROOT_PAGE_PATH+"AJAX_getHubSelectionPrompt.php", {"errorText":errorText},
   function(data)
   {

       $.blockUI({
       message: data,
       css: {background:'none',border:'none',/*textAlign:'center',width:'690px',*/top: ($(window).height()-690)/2 + 'px',  left:($(window).width()-690)/2 + 'px'},
       focusInput:false,
       overlayCSS: {background:'#FFF'}});

       /*Hub bselection dialog box*/
       $('#hubCarousel').jcarousel({scroll:1});


       //alert($('#carouselContainer').html());

       $('#postcodeInput').focus(function(){
          if($(this).val()=='postcode')
          {
            this.value=''
          }
        });
        $('#emailInput').focus(function(){
          if($(this).val()=='email')
          {
            this.value=''
          }
        });
        $('#passwordInput').focus(function(){
          if($(this).val()=='password')
          {
            this.value=''
          }
        });
       $('a#closeLink ').click(function(){
       $.unblockUI();});

    },"html");

}



$(function(){
     $('#hubCarousel').jcarousel({scroll:1});
    (jQuery)(".productDetailsTabsTable").fadeIn(2000);
    (jQuery)(".additionalImagesText").fadeIn(2000);
    (jQuery)("#tickerTapeWrapper").show();
    /*$(".subCat").hide();

    $(".sideNav .topLevel").click(function(e){
        $(this).next(".subCat").slideToggle(300);
        $(".subsubCat").hide();
        e.stopImmediatePropagation();
          $(".nextLevel").click(function(f){
            if($(this).next(".subsubCat").length>0){
                $(this).next(".subsubCat").slideToggle(300);
                f.stopImmediatePropagation();
                return false;
            }
          });
        return true;
    });*/

    $("#datepicker").datepicker({
    dateFormat: 'yy-mm-dd'
    /*beforeShowDay: function(date){
       if (date.getDay() == 1)
       {
          return [false,''];
       }
       else
       {
          return [true, ''];
       }
    }*/
    });

    $(".addToCart").click(function(){

        var quantity = $("input[name=quantity]").val();

        if (quantity > 0)
        {
            $(".addedToBasketText").hide();
            $(".basketPreview").show();
        }
        else
        {
            $(".addedToBasketText").hide();
            //$(this).closest("td").next("td").children(".addedToBasketText").html("Quantity must be at least 1").fadeIn(200);
        }
    });

    var defaultTabSRC = ROOT_PAGE_PATH+'images/mainSite/product_tab_bg.gif';
    var activeTabSRC = ROOT_PAGE_PATH+'images/mainSite/product_tab_active_bg.gif';
    $(".supplierInformation").show();
    $(".supplierInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
    $(".showSupplierInformation").css("color","#FFF");
    $(".showNutritionalInformation").css("color","#000");
    $(".showCustomerReviews").css("color","#000");

    /*
    $(".myDetailsInformation").show();
    $(".myDetailsInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
    $(".showMyDetailsInformation").css("color","#FFF");
    $(".showMyOrdersInformation").css("color","#000");
    $(".showMyRegularBuysInformation").css("color","#000");
    */

    $('#emailAddress').focus(function(){
          if(this.value=='Enter Email Address')
          {
            this.value=''
          }
    });

    $('#searchShop').focus(function(){
          if(this.value=='Search Food')
          {
            this.value=''
          }
    });

    $("#suggestionList").hide();
    $("#viewAllSuggestions").click(function(){
        $('#suggestionList').slideToggle(300);
        return false;
    });

    /*$("#advancedOptions").hide();
    $("#viewAdvancedOptions").click(function(){
        $('#advancedOptions').slideToggle(300);
        return false;
    });*/


   $.blockUI.defaults.message ='<img src="images/loading.gif" />';
			$.blockUI.defaults.css.border = '0px solid #aaa';
			$.blockUI.defaults.css.width = '300px';
			$.blockUI.defaults.css.textAlign = 'center';
			$.blockUI.defaults.css.background = 'white';



    /* ADD TO CART AJAX*/
    $('.itemAddForm').ajaxForm({
         dataType:null,
         success: function(responseText, statusText) {
             $.unblockUI();

             $(".basketPreview").show();
             $(".totalBox").html("Updating");

             //REMOVE EXISTING QUICKBUY FORM
             $("#oneClickContainer").remove();

             //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA
             $.post(ROOT_PAGE_PATH+"getShoppingCartAjax.php",null,function(data){
                 //now update basket preview

                 //remove all rows
                 $(".basketPreview table").empty();

                 //now loop over all items in data
                 $.each(data.items,function(index,item){
                     var row = "<tr><td style='text-align:right;'>"+item.quantity+"x</td><td style='text-align:left;'>"+item.name+"</td><td style='text-align:left;'>&pound;"+item.subTotal+"</td></tr>";
                     $(".basketPreview table").append(row);
                 });

                 //now update total
                 // $(".basketPreview .totalBox .middleBar").html("Total &pound;"+data.total);
                 $(".totalBox").html("&pound;"+data.total);
                 //now update basket count
                 $('.cartText').html(data.cartText);

                 $(".basketEmptyText").empty();

                 /* Not required now
                 $(".basketLink").click(function(){
                      $(".basketPreview").slideToggle(500);
                      return false;
                 });*/

             },"json");
         }
     });




     $(".quickBuy").click(function() {

         var idString;
         idString = $(this).children("img").attr('id');

         idParts = idString.split("~~");
         var id = idParts[0];
         var type = idParts[1];
         $.get(ROOT_PAGE_PATH+"getVersionsAjax.php", {"id": id,"productType":type},
         function(data)
         {
             var title = data.versions[0].title;
             var shortDescription = data.versions[0].shortDescription;
             var form;
             form="<div id='oneClickContainer'><div id='oneClickHeader'><h1>Buy Product</h1><span class='close'><a href='#' class='closeOneClick'><img src='"+ROOT_PAGE_PATH+"images/mainSite/close.jpg'/></a></span></div><div id='oneClickSlice'><h1>"+title+"</h1>"+shortDescription+"<br /><br /><table style='width:250px;margin-left:auto;margin-right:auto;' cellspacing='10px'>";

             //For each array row returned. There should be only one in this case
             $.each(data.versions,function(index,item){
                 var versionID;
                 var productID;
                 var priceRetail;
                 var priceMember;
                 var priceWholesale;
                 var weightGrammes;
                 var customerType;
                 var minWholesale;

                 customerType = item.customerType;
                 versionID = item.versionID;
                 productID = item.productID;
                 weightGrammes = item.weightGrammes;
                 versionPrice = item.versionPrice;
                 priceMember = item.priceMember;
                 priceWholesale = item.priceWholesale;
                 minWholesale = item.minWholesaleOrder;

                 form = form+"<tr><td>"+weightGrammes+"</td><td>&pound;"+versionPrice+"</td><td><form action='' method='post' class='itemAddForm'><input type='hidden' name='productType' value='"+type+"' /><input type='hidden' name='cartOperation' value='true' /><input type='hidden' name='versionID' value='"+versionID+"' /><input type='hidden' name='productID' value='"+productID+"' /><input type='text' size='1' maxlength='3' name='quantity' value='1' />&nbsp;<input type='image' class='addToCart' src='"+ROOT_PAGE_PATH+"images/mainSite/basket_addv3.jpg' name='submit' style='width: 50px; position:relative;top:3px;' /><input type='hidden' name='addItem' value='true' /></form></td></tr>";
                 //alert(customerType);
                 if(customerType=="MEMBER"||customerType=="RETAIL"){
                     form = form+"<tr style='color:red'><td colspan='3'>Member Price: &pound;"+priceMember+"</td></tr>";
                 }
                 if(customerType=="WHOLESALE"){
                     if(type=="PRODUCT"){
																									form = form+"<tr style='color:red'><td colspan='3'>Wholesale Price: &pound;"+priceWholesale+" ["+minWholesale+"]</td></tr>";
                 				}
                 }
             });
             form = form+"</table></div><div id='oneClickFooter'></div></div>";
             //REMOVE EXISTING QUICKBUY FORM
             $("#oneClickContainer").remove();
             $("body").append(form);
             $("#oneClickContainer").hide();



             $.blockUI({
                 message: $("#oneClickContainer"),
                 //message: "<p>Hello World</p>",
                 css: {cursor:null, background: 'transparent'},
                 overlayCSS: { backgroundColor: '#ffffff',cursor:null}
             });

             $('.itemAddForm').ajaxForm({
                 dataType:null,
                 success: function(responseText, statusText) {
                     $.unblockUI();

                     $(".basketPreview").show();
                     $(".totalBox").html("Updating");

                     //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA
                     $.post(ROOT_PAGE_PATH+"getShoppingCartAjax.php",null,function(data){
                         //now update basket preview

                         //remove all rows
                         $(".basketPreview table").empty();
                         //alert("Removed - add from adv search or view cat page");

                         //now loop over all items in data
                         $.each(data.items,function(index,item){
                             var row = "<tr><td style='text-align:right;'>"+item.quantity+"x</td><td style='text-align:left;'>"+item.name+"</td><td style='text-align:left;'>&pound;"+item.subTotal+"</td></tr>";
                             $(".basketPreview table").append(row);
                         });

                         //now update total
                         // $(".basketPreview .totalBox .middleBar").html("Total &pound;"+data.total);
                         $(".totalBox").html("&pound;"+data.total);
                         //now update basket count
                         $('.cartText').html(data.cartText);

                         $(".basketEmptyText").empty();

                         /* Not required now
                         $(".basketLink").click(function(){
                              $(".basketPreview").slideToggle(500);
                              return false;
                         });*/

                     },"json");
                 }
             });


             $(".closeOneClick").click(function() {
                $.unblockUI();
             });


         }, "json");
         return false;
     });




    $('.addFavouriteForm').ajaxForm({
          dataType:"json",
          url: ROOT_PAGE_PATH+"addToFavAJAX.php",
          success: addFavSwitch
      });

      $('.removeFavouriteForm').ajaxForm({
          dataType:"json",
          url: ROOT_PAGE_PATH+"removeFavAJAX.php",
          success: function(responseText, statusText) {
              //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA

              $("#favouriteCounter").html(responseText.count);
              $('input[name|=productID][value|='+responseText.id+']').closest(".productDisplay3").remove();

          }
      });


      $('.swapFavouriteForm').ajaxForm({
          dataType:"json",
          url: ROOT_PAGE_PATH+"removeFavAJAX.php",
          success: swapFavSwitch
      });



    	$('#searchResetButton').click(function(){
           $('#advancedSearchForm').clearForm();
     });

    //Apply behaviour to hub change link
    $('#hubChangeLink').click(function(){

        //empty string added to signify no errors
        promptForHubSelection('');
        //stop default behaviour
        return false;
    });



    /*******************************
    *          BASKET PREVIEW      *
    *******************************/
    $(".basketLink").click(function(event){
         event.stopImmediatePropagation();
         /*$(".basketPreview").slideToggle(500);*/
         /*return false;*/
    });

    // Product page javacript functions
  		$(".showSupplierInformation").click(function(){
  		    $(".supplierInformation").fadeIn(300);
  		    $(".nutritionalInformation").hide();
  		    $(".customerReviews").hide();
  		    $(".supplierInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')');
  		    $(".nutritionalInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".customerReviewsHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

        $(".showSupplierInformation").css("color","#FFF");
        $(".showNutritionalInformation").css("color","#000");
        $(".showCustomerReviews").css("color","#000");
  		 });

  		// Product page javacript functions
  		$(".showNutritionalInformation").click(function(){
  		    $(".nutritionalInformation").fadeIn(300);
  		    $(".supplierInformation").hide();
  		    $(".customerReviews").hide();
  		    $(".nutritionalInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
  		    $(".supplierInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".customerReviewsHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

  		    $(".showSupplierInformation").css("color","#000");
        $(".showNutritionalInformation").css("color","#FFF");
        $(".showCustomerReviews").css("color","#000");
  		});

  		// Product page javacript functions
  		$(".showCustomerReviews").click(function(){
  		    $(".customerReviews").fadeIn(300);
  		    $(".supplierInformation").hide();
  		    $(".nutritionalInformation").hide();
  		    $(".customerReviewsHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
  		    $(".supplierInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".nutritionalInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

    $(".showSupplierInformation").css("color","#000");
        $(".showNutritionalInformation").css("color","#000");
        $(".showCustomerReviews").css("color","#FFF");
  		});

  		//##########################################################################


  		// My Account page javacript functions
  		/*$(".showMyDetailsInformation").click(function(){
  		    $(".myDetailsInformation").fadeIn(300);
  		    $(".myOrdersInformation").hide();
  		    $(".myRegularBuysInformation").hide();
  		    $(".myDetailsInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')');
  		    $(".myOrdersInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".myRegularBuysInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

        $(".showMyDetailsInformation").css("color","#FFF");
        $(".showMyOrdersInformation").css("color","#000");
        $(".showMyRegularBuysInformation").css("color","#000");
  		 });

  		// My Account page javacript functions
  		$(".showMyOrdersInformation").click(function(){
  		    $(".myOrdersInformation").fadeIn(300);
  		    $(".myDetailsInformation").hide();
  		    $(".myRegularBuysInformation").hide();
  		    $(".myOrdersInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
  		    $(".myDetailsInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".myRegularBuysInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

  		    $(".showMyDetailsInformation").css("color","#000");
        $(".showMyOrdersInformation").css("color","#FFF");
        $(".showMyRegularBuysInformation").css("color","#000");
  		});

  		// My Account page javacript functions
  		$(".showMyRegularBuysInformation").click(function(){
  		    $(".myRegularBuysInformation").fadeIn(300);
  		    $(".myDetailsInformation").hide();
  		    $(".myOrdersInformation").hide();
  		    $(".myRegularBuysInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')', 'no-repeat');
  		    $(".myDetailsInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".myOrdersInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

    $(".showMyDetailsInformation").css("color","#000");
        $(".showMyOrdersInformation").css("color","#000");
        $(".showMyRegularBuysInformation").css("color","#FFF");
  		});

  		// My Account page javacript functions
  		$("#viewOrders").click(function(){
  		alert('hi');
  		    $(".myOrdersInformation").fadeIn(300);
  		    $(".myDetailsInformation").hide();
  		    $(".myRegularBuysInformation").hide();
  		    $(".myOrdersInformationHeader").css("backgroundImage",'url(' + activeTabSRC + ')');
  		    $(".myDetailsInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');
  		    $(".myRegularBuysInformationHeader").css("backgroundImage",'url(' + defaultTabSRC + ')', 'no-repeat');

        $(".showMyOrdersInformation").css("color","#FFF");
        $(".showMyDetailsInformation").css("color","#000");
        $(".showMyRegularBuysInformation").css("color","#000");
  		 });*/


  		$(".productImage").load(function(){
        $(".slideshow").cycle({
            fx:'scrollRight',
            next: ".slideshow",
            timeout: 0
        });
    });




    jQuery(document).ready(function() {
        jQuery('#mycarousel').jcarousel({visible:3});
        jQuery('#mycarousel2').jcarousel({visible:3});

        //Hide (Collapse) the toggle containers on load
       	$(".toggle_container").hide();

       	// FAQ Toggle
       	$(".trigger").toggle(function(){
       		$(this).addClass("active");
       		}, function () {
       		$(this).removeClass("active");
       	});

       	// FAQ Toggle
       	$(".trigger").click(function(){
       		$(this).next(".toggle_container").slideToggle("slow");
       	});

       	$(".toggle_containerSL").hide();

       	// Shopping List Toggle
       	$("h2.triggerSL").toggle(function(){
       		$(this).addClass("active");
       		}, function () {
       		$(this).removeClass("active");
       	});

       	// Shopping List Toggle
       	$("h2.triggerSL").click(function(){
       		$(".toggle_containerSL").slideToggle("slow");
       	});


    });


    $("#addToShoppingList").ajaxForm({
        success: function(){
            //alert("done");

            //now get all items
            $.post(ROOT_PAGE_PATH+"getShoppingListAjax.php",null,function(data){
                //now update basket preview

                //remove all rows
                $(".paperSlice table tr").remove();

                //now loop over all items in data
                $.each(data.items,function(index,item){
                    var row = '<tr><td width="330">'+item+'</td><td width="50"><form class="removeListItem" action="" method="post"><input type="hidden" name="removeKey" value="'+index+'" /><input type="hidden" name="removeValue" value="'+item+'" /><input type="submit" class="submitButton" value="Remove" /></form></td></tr>';
                    $(".paperSlice table").append(row);
                });

                $(".removeListItem").ajaxForm({
                    success: removeListItem
                });

                //now update total


            },"json");

            //blank out input
            $(".shoppingListAddToList").val("").focus();
        }

     });

     $(".removeListItem").ajaxForm({
         success: removeListItem
     });

      $(".processShoppingListChange").ajaxForm({
      				dataType:"html",
      				data: {type:1},
          url: ROOT_PAGE_PATH+"AJAX_shoppingList.php",
										success: updateShoppingListContent
						});

						$('#SL_searchBoxText').focus(function(){
          if(this.value=='Enter Item Name or Keyword')
          {
            this.value=''
          }
    });

    $(".discountForm").hide();

    $(".applyDiscountCodeLink").click(function(){

        $(".discountForm").toggle();

    });

    $("#holidayOrder").change(function(){

        if($("#holidayOrder").val()==0){
            $(".mainHolRow").hide();
            $(".otherRow").hide();
            $(".holCotRow").hide();
            $(".deliveryRow").show();
        }
        else{
            $(".mainHolRow").show();
            $(".deliveryRow").hide();

            //now check whether we need to show other rows
            if ($('#holCotCompany').val()!="") {
        				    $('.holCotRow').show();
            }
        				else{
        				    $('.holCotRow').hide();
        				}

        				if($('#holCotCompany').val()=="OTHER"){
    												$('.otherRow').show();
    												$('.holCotRow').show();

    												//make text field visible
    												$('#holidayCottage').show();
    												$("#holCotSelect").hide();

    												$("input[name|=delivery_address1]").val("");
        								$("input[name|=delivery_address2]").val("");
        								$("input[name|=delivery_town]").val("");
        								$("input[name|=delivery_postcode]").val("");
    								}
    								else if($('#holCotCompany').val()!=""){
    												//alert("got val");
    												var id = $(this).val();
    												$('.holCotRow').show();
    												$('.otherRow').hide();

    												//find holiday cottages
   												 $.get(ROOT_PAGE_PATH+"AJAX_holidayCottages.php", { "id": id },
   												   function(data)
   										     {
   									      				$("#holCotSelect").children().remove();
   									      				$("#holCotSelect").append("<option value=''>Please Select...</option>");
   																			if(data.items.length>0){
   																							for(var i = 0; i < data.items.length; i++){

   																											$("#holCotSelect").append("<option class='"+data.items[i].id+"' value='"+data.items[i].name+"'>"+data.items[i].name+"</option>");
   																							}
   																							$("#holCotSelect").show();
   																							//$("#holCotSelect").val(holCotName);
   																							/*$(data.items).each(function(item){
   																											$("#holCotSelect").append("<option value='"+item.id+"'>"+item.name+"</option>");
   																							});*/
   																							$("#holidayCottage").hide();
   																			}
   																			else{
   																							//make text field visible
   																							$('#holidayCottage').show();
   																							//$("#holidayCottage").val(holCotName);
   																							$("#holCotSelect").hide();

   																							$("input[name|=delivery_address1]").val("");
                  								$("input[name|=delivery_address2]").val("");
                  								$("input[name|=delivery_town]").val("");
                  								$("input[name|=delivery_postcode]").val("");
   																			}
   										     }, "json");
    								}
    								else{
    												//alert("no val");
    												$('.holCotRow').hide();
    												$('.otherRow').hide();
    								}
								}
    });

    if($("#holidayOrder").val()==0){
        $(".mainHolRow").hide();
        $(".otherRow").hide();
        $(".holCotRow").hide();
        $(".deliveryRow").show();
    }
    else{
        $(".mainHolRow").show();
        $(".deliveryRow").hide();

        //now check whether we need to show other rows
        if ($('#holCotCompany').val()!="") {
    				    $('.holCotRow').show();
        }
    				else{
    				    $('.holCotRow').hide();
    				}

    				if($('#holCotCompany').val()=="OTHER"){
												$('.otherRow').show();
												$('.holCotRow').show();

												//make text field visible
												$('#holidayCottage').show();
												$("#holCotSelect").hide();

												$("input[name|=delivery_address1]").val("");
    								$("input[name|=delivery_address2]").val("");
    								$("input[name|=delivery_town]").val("");
    								$("input[name|=delivery_postcode]").val("");
								}
								else if($('#holCotCompany').val()!=""){
												//alert("got val");
												var id = $(this).val();
												$('.holCotRow').show();
												$('.otherRow').hide();

												//find holiday cottages
											 $.get(ROOT_PAGE_PATH+"AJAX_holidayCottages.php", { "id": id },
											   function(data)
									     {
								      				$("#holCotSelect").children().remove();
								      				$("#holCotSelect").append("<option value=''>Please Select...</option>");
																		if(data.items.length>0){
																						for(var i = 0; i < data.items.length; i++){

																										$("#holCotSelect").append("<option class='"+data.items[i].id+"' value='"+data.items[i].name+"'>"+data.items[i].name+"</option>");
																						}
																						$("#holCotSelect").show();
																						//$("#holCotSelect").val(holCotName);
																						/*$(data.items).each(function(item){
																										$("#holCotSelect").append("<option value='"+item.id+"'>"+item.name+"</option>");
																						});*/
																						$("#holidayCottage").hide();
																		}
																		else{
																						//make text field visible
																						$('#holidayCottage').show();
																						//$("#holidayCottage").val(holCotName);
																						$("#holCotSelect").hide();

																						$("input[name|=delivery_address1]").val("");
              								$("input[name|=delivery_address2]").val("");
              								$("input[name|=delivery_town]").val("");
              								$("input[name|=delivery_postcode]").val("");
																		}
									     }, "json");
								}
								else{
												//alert("no val");
												$('.holCotRow').hide();
												$('.otherRow').hide();
								}
				}

    $("#holCotSelect").change(function(){
        $("input[name|=delivery_address1]").val("");
								$("input[name|=delivery_address2]").val("");
								$("input[name|=delivery_town]").val("");
								$("input[name|=delivery_postcode]").val("");
        var id =$('#holCotSelect :selected').attr("class");
        //alert(id);
        //populate address details
        $.get(ROOT_PAGE_PATH+"AJAX_holidayCottageDetails.php", { "id": id },
					   function(data)
			     {
		      				//alert("in");
            //$("#holCotSelect").children().remove();
		      				//$("#holCotSelect").append("<option value=''>Please Select...</option>");
												if(data.items.length>0){
																for(var i = 0; i < data.items.length; i++){
                    $("input[name|=delivery_address1]").val(data.items[i].addressLine1);
            								$("input[name|=delivery_address2]").val(data.items[i].addressLine2);
            								$("input[name|=delivery_town]").val(data.items[i].addressLine3);
            								$("input[name|=delivery_postcode]").val(data.items[i].postcode);
																}
												}

			     }, "json");

    });

    $("#changeAddress").click(function(){
        $("input[name|=delivery_address1]").val("");
								$("input[name|=delivery_address2]").val("");
								$("input[name|=delivery_town]").val("");
								$("input[name|=delivery_postcode]").val("");
    });

    //******************************************
    //css menu
    //$('div.navBarSubList').css({'opacity':0.95});
    //$('div.navBarSubListRight').css({'opacity':0.95});

    /*Use hover intent to govern menu action*/
    /*$("ul#navBar a.topLevelLinks").bind("hover",{speed:10,delay:200},
    function(){
        $("div.navBarSubList").fadeOut(100);
        $("div.navBarSubListRight").fadeOut(100);
        $(this).next().show(500);
    });

    $("div#navbarArea").mouseleave(
    function(){
    $("div.navBarSubList").slideUp(500);
    $("div.navBarSubListRight").slideUp(500);
    });*/

    //remove automatic display on hover when js enabled. Handled by delay above.
    //$('div.navBarSubList,div.navBarSubList').hide();
    //$('div.navBarSubListRight,div.navBarSubListRight').hide();



    /* ADD TO CART AJAX*/
    $('#addRecipeToCartButton').click(function(){

       $('#addRecipeToCartForm input[type=hidden]').each(function(index){

                   var itemString = $(this).val();
                   itemArray = itemString.split('|');

                   //alert(itemArray[0]+itemArray[1]+itemArray[2]+itemArray[3]);
                   //cartOperation -> addItem
                   //quantity|productType|versionID|productID

                   //Fire off request to cart - For each item
                   $.post(ROOT_PAGE_PATH+'index.php',
                          {cartOperation:'true',
                           addItem:'true',
                           quantity:itemArray[0],
                           productType:itemArray[1],
                           versionID:itemArray[2],
                           productID:itemArray[3]});

                });//Enf of .each

          //Populate respones
          $.post(ROOT_PAGE_PATH+"getShoppingCartAjax.php",null,function(data){
              //now update basket preview

              //remove all rows
              //$(".basketPreview table tr").remove();
              $(".basketPreview table").empty();
              //alert("Recipe added - remove all rows");

              //now loop over all items in data
              $.each(data.items,function(index,item){
                  var row = "<tr><td style='text-align:right;'>"+item.quantity+"x</td><td style='text-align:left;'>"+item.name+"</td><td style='text-align:left;'>&pound;"+item.subTotal+"</td></tr>";
                  $(".basketPreview table").append(row);
                  //alert(row);
              });

              //now update total
              //$(".basketPreview .totalBox .middleBar").html("Total &pound;"+data.total);
              $(".totalBox").html("&pound;"+data.total);
              //now update basket count
              //$('.cartText').html(data.cartText);

              $(".basketEmptyText").empty();

              /* Not required now
              $(".basketLink").click(function(){
                   $(".basketPreview").slideToggle(500);
                   return false;
              });*/

              $(".basketPreview").css('z-index',500).slideDown(500);

          },"json");

          return false;
    });

    $('.askSuzi').css("display","block");

				if(!needOtherRow){
    $('.otherRow').hide();
    }

				if ($('#holCotCompany').val()!="") {
				$('.holCotRow').show();
    }
				else{
				$('.holCotRow').hide();
				}

    $('#holCotCompany').change(function(){
								if($(this).val()=="OTHER"){
												$('.otherRow').show();
												$('.holCotRow').show();
												//make text field visible
												$('#holidayCottage').show();
												//$("#holidayCottage").val(holCotName);
												$("#holCotSelect").hide();
												$("input[name|=delivery_address1]").val("");
    								$("input[name|=delivery_address2]").val("");
    								$("input[name|=delivery_town]").val("");
    								$("input[name|=delivery_postcode]").val("");
								}
								else if($(this).val()!=""){
												//alert("got val");
												var id = $(this).val();
												$('.holCotRow').show();
												$('.otherRow').hide();

												//find holiday cottages
												 $.get(ROOT_PAGE_PATH+"AJAX_holidayCottages.php", { "id": id },
												   function(data)
										     {
									      				$("#holCotSelect").children().remove();
									      				$("#holCotSelect").append("<option value=''>Please Select...</option>");
																			if(data.items.length>0){
																							for(var i = 0; i < data.items.length; i++){

																											$("#holCotSelect").append("<option class='"+data.items[i].id+"' value='"+data.items[i].name+"'>"+data.items[i].name+"</option>");
																							}
																							$("#holCotSelect").show();
																							//$("#holCotSelect").val(holCotName);
																							/*$(data.items).each(function(item){
																											$("#holCotSelect").append("<option value='"+item.id+"'>"+item.name+"</option>");
																							});*/
																							$("#holidayCottage").hide();
																			}
																			else{
																							//make text field visible
																							$('#holidayCottage').show();
																							//$("#holidayCottage").val(holCotName);
																							$("#holCotSelect").hide();
																							$("input[name|=delivery_address1]").val("");
               								$("input[name|=delivery_address2]").val("");
               								$("input[name|=delivery_town]").val("");
               								$("input[name|=delivery_postcode]").val("");
																			}
										     }, "json");

								}
								else{
												//alert("no val");
												$('.holCotRow').hide();
												$('.otherRow').hide();
								}
				});

});

/**
 *
 * @access public
 * @return void
 **/



