function pageload(hash) {
    var link;
    if (hash) {
        if (hash.match(/^faq[0-9]+$/)) {
            $("div.active").removeClass("active");
            $("div.faqwrapper img").css({
                visibility: 'hidden'
            });
            $("div.faqwrapper .faqlink").css({
                backgroundImage: "url(/images/arrow-right.png)"
            }, 100);
            $(".faqitem:visible:not(#"+ hash +"-body)").slideUp();
            link = $(".faqlink[data-href]");
            link.attr("href", link.attr("data-href"));
            link.removeAttr("data-href");
            $("#"+ hash +"-body").slideDown();
            $("#"+ hash +"-wrapper").addClass("active");
            window.setTimeout(function() {
                $("#"+ hash +"-wrapper img").css({
                    visibility: 'visible'
                });
            }, 100);
            $("#"+ hash +"-wrapper .faqlink").css({
                backgroundImage: "url(/images/arrow-down.png)"
            });
            link = $(".faqlink[href=#" + hash + "]");
            link.attr("data-href", link.attr("href"));
            link.attr("href", "#faq0");
            if (hash != "faq0") {
                var wt_ti = $("body").attr("id").toUpperCase() + " - " + hash.toUpperCase() + " - "+ $("#"+ hash +"-wrapper .faqlink").text().replace(/%/, " percent").replace(/[^a-zA-Z0-9 ?]/g, "");
                if (typeof dcsMultiTrack == "function") {
                    dcsMultiTrack('DCS.dcsuri', window.location.pathname + "/" + hash, 'WT.ti', wt_ti);
                }
                else if (navigator.userAgent.search(/gecko/i) != -1) {
                    console.log("Tracked title: " + wt_ti);
                }
            }
        }
        else if(hash == "germany" || hash == "sweden" || hash == "gibraltar" || hash == "nocountry") {
            $("div.active a.switchlink").css({
                backgroundImage: "url(/images/arrow-right.png)"
            });
            $("div.active").removeClass("active");
            $(".switchitem:visible:not(#"+ hash +"-body)").slideUp();
            link = $(".switchlink[data-href]");
            link.attr("href", link.attr("data-href"));
            link.removeAttr("data-href");
            $("#"+ hash +"-body").slideDown();
            $("#"+ hash +"-wrapper").addClass("active");
            $("div.active a.switchlink").css({
                backgroundImage: "url(/images/arrow-down.png)"
            });
            link = $(".switchlink[href=#" + hash + "]");
            link.attr("data-href", link.attr("href"));
            link.attr("href", "#nocountry");
        }
        else if (hash == "nutritional-info" || hash == "gda" || hash == "ingredients" || hash == "notab") {
            $(".tab").stop(true, true);
            $("div#subcontent a.active").removeClass("active");
            $(".tab:visible:not(#"+ hash +"-tab)").hide();
            link = $(".tablink[data-href]");
            link.attr("href", link.attr("data-href"));
            link.removeAttr("data-href");
            $("#"+ hash +"-tab").slideDown();
            $("a[href=#"+ hash +"]").addClass("active");
            link = $("a[href=#" + hash + "]");
            link.attr("data-href", link.attr("href"));
            link.attr("href", "#notab");
            $("div#subcontent a img").attr("src", "/images/arrow-right.png");
            $("div#subcontent a.active img").attr("src", "/images/arrow-down.png");
            if (hash == "notab") {
                $("#content").animate({
                    height: '470px'
                });
            }
            else {
                var wt_ti = hash.toUpperCase();
                if (wt_ti == "NUTRITIONAL-INFO") {
                    wt_ti = "Nutritional Info";
                }
                else if (wt_ti == "INGREDIENTS") {
                    wt_ti = "Ingredients";
                }
                wt_ti = $("body").attr("id").toUpperCase() + " - " + wt_ti;
                if (typeof dcsMultiTrack == "function") {
                    dcsMultiTrack('DCS.dcsuri', window.location.pathname + "/" + hash, 'WT.ti', wt_ti);
                }
                else if (navigator.userAgent.search(/gecko/i) != -1) {
                    console.log("Tracked title: " + wt_ti);
                }
                $("a[href=#"+ hash +"]").attr("src", "/images/arrow-down.png");
                $("#content").animate({
                    height: '700px'
                });
            }
        }
    }
}

$(document).ready(function() {
    $(".faqitem").hide();
    window.setTimeout(function () {
        $(".faqwrapper img").css({
            visibility: 'hidden'
        });
    }, 20);
    $(".switchitem").hide();
    $("div#subcontent .tab").hide();
    $("#b11110 div#content, #b11120 div#content, #b11130 div#content, #b11210 div#content, #b11220 div#content, #b11230 div#content, #b12100 div#content, #b12200 div#content, #b12300 div#content, #b13000 div#content").css({
        height: '470px'
    });

    $.historyInit(pageload, "jquery_history.html");
    $("a[rel='history']").click(function () {
        var hash = this.href;
        hash = hash.replace(/^.*#/, '');
        $.historyLoad(hash);
        this.blur();
        return false;
    });
    $("a[href^=http://]").click(function () {
        var wt_ti = "External Link";
        if (this.href.search(/^http:\/\/www\.facebook\.com/) != -1) {
            wt_ti = "Facebook Link";
        }
        else if (this.href.search(/^http:\/\/www\.chocolatesdirect\.co\.uk/) != -1) {
            wt_ti = "Ext. Buy Online Link";
        }
        if (typeof dcsMultiTrack == "function") {
            dcsMultiTrack('DCS.dcsuri', '/link/'+this.href.substr(7), 'WT.ti', wt_ti);
        }
        else if (navigator.userAgent.search(/gecko/i) != -1) {
            console.log("Tracked title: " + wt_ti);
        }
        return true;
    });
});