﻿jQuery(document).ready(function () {


    //******************************************Add active class on the current nav item ***************************

    var path = document.URL.replace(window.location.protocol + '//' + document.domain, ''); // Remove domain
    // Add active class to relevant menu item
    $("#nav a").each(function () {
        var target = $(this).attr('href');
        if (target == path) {
            $(this).parent().addClass("active");
        }
    });

    // Add active class to relevant submenu item
    $("#nav li #subnav a").each(function () {
        var subtarget = $(this).attr('href');
        if (subtarget == path) {
            $(this).parent().addClass("active");
            //add active class to the submenu parent
            $("#subnav").parent().addClass("active");
        }
    });

    // Add active class to "Discover Our Chocolates" if you are in the product range and product item pages

    var discoverPath = document.URL.replace(window.location.protocol + '//' + document.domain, ''); // Grab the URL and remove domain
    $("#nav li.our-chocolates a").each(function () {
        // in the discoverPath var, check if there is the value "our-chocolates"
        if (discoverPath.indexOf("our-chocolates") >= 0) {
            //add 'active' class
            $(this).parent().addClass("active");
        }
    });

    if ("#nav li.our-chocolates:not(.active)") {
        //Add the "active" class to /food-serveice which is technically a child of "our-chocolates" but has a different path which will make the previous js fail
        var liValue = $(".breadcrumb_item").text();

        $("#nav li.our-chocolates a").each(function () {
            if (liValue.indexOf("Discover Our Chocolates") >= 0) {
                $(this).parent().addClass("active");
            }
        });
    }

    //*************************************************
    //*************************************************



    //******************************Insert the current page URL into the Facebook like button for each item**********
    //var currentUrl = document.URL; // put the current url into a variable
    //$('#product_item .fb-like').attr('data-href', currentUrl);

    var rootUrl = document.domain; // put the root into a variable
    $('#footer_content .fb-like').attr('data-href', rootUrl);

    //*************************************************
    //*************************************************



    //******************************Refresh page when a Facebook 'like' button is clicked**********
    //FB.Event.subscribe('edge.create',
   // function (response) {
   //    window.location.reload();
   // });
    //*************************************************
    //*************************************************

});
