
$(document).ready(function() {

    $('#service-menu li:last,#breadcrumbs li:last,#other-ingredients li:last,.related-products li:last,#podcasts li:last,.news-media #main-content article:last,#faqs dd:last,#nearby-stores li:last,#slider li:last').addClass('last');
    $('#other-ingredients li:odd').addClass('even');
    var element19 = document.getElementById("splite");
    if (element19 != null) {
        $('.product-range-list').easyListSplitter({
            colNumber: 2
        });
    }


    $('.hidden-cont').hide();
    $('<a href="#" class="read-more">Click here to read more</a>').appendTo('#professional-advice .visible-cont')

    $('#professional-advice .read-more').click(function() {

        $(this).parent().next('.hidden-cont').slideToggle().prev().find('.read-more').toggleClass('open');
        if ($(this).hasClass('.open')) {
            $(this).html('Click here to collapse');
        } else {
            $(this).html('Click here to read more');
        }
        return false;
    });

    var element11 = document.getElementById("thankyou");
    if (element11 != null) {
        window.location.hash = "thanks";
    }



    // ---- PreFilled   ----------------------------------------------------------------------------------------------------------

    $.fn.preFilled = function() {
        $(this).focus(function() {
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function() {
            if (!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    };

    //    $("#Email").preFilled();


    // ---- Slider   ----------------------------------------------------------------------------------------------------------
    var elementCanSlider = document.getElementById("CanSlider");
    if (elementCanSlider != null) {
        var itemMarginR = parseInt($('#slider li').css('margin-right'));
        var itemFullWidth = ($('#slider li').width() + itemMarginR) * ($('#slider li').size()) - itemMarginR;
        $('#slider #slider-cont').width(itemFullWidth);
        $('#slider').jScrollPane({ showArrows: true });
    }


    // ---- Tooltip   ----------------------------------------------------------------------------------------------------------

    $(function() {
        $('.bubbleInfo').each(function() {
            var distance = 10;
            var time = 0;
            var hideDelay = 100;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function() {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        bottom: 150,
                        left: -100,
                        display: 'block'
                    }).animate({
                        bottom: '-=' + distance + 'px',
                        opacity: 1,
                        'filter': ''
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function() {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function() {
                    hideDelayTimer = null;
                    info.animate({
                        bottom: '-=' + distance + 'px',
                        opacity: 0,
                        'filter': ''
                    }, time, 'swing', function() {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });


});


function WaterMark(txt, evt) {

    if (txt.value.length == 0 && evt.type == "blur") {

        txt.style.color = "gray";

        txt.value = defaultText;

    }

    if (txt.value == defaultText && evt.type == "focus") {

        txt.style.color = "black";

        txt.value = "";

    }

}

