
$(document).ready(function () {
    $productImage = $("#productImageHolder img")
    var showproductvalue = getQueryStringValue('showproduct');
    if (showproductvalue != null) {
        var link = $("#" + showproductvalue);
        if (link.length != 0) {

            if ((link.attr('data-rev') != null) && (link.attr('data-rev') != "")) {
                $productImage.attr('src', link.attr('data-rev'))
            }
        }
    }

    $("#productTree .productTreeRootLink").click(function (event) {
        $(this.hash).slideToggle("500");
        return false;
    });

    var originalImageSrc = $productImage.attr('src');

    $("#productTree .productTreeChildLink, #productTree .productTreeRootLink").mouseenter(function (event) {
        newSrc = $(this).attr('data-rev');
        if ((newSrc != null) && (newSrc != undefined) && (newSrc != "")) {
            $productImage.attr('src', newSrc).load(function () {
                $window = $(window);
                $lower = $('#touts');
                $parent = $('.first .rightcolumn');
                if ($window.scrollTop() > $parent.offset().top) {
                    var newOffset = $window.scrollTop() - $parent.offset().top;
                    if ($window.scrollTop() + $productImage.outerHeight() < $lower.offset().top) {
                        $productImage.css({ position: 'absolute' }).stop().animate({ top: newOffset });
                    } else {
                        $productImage.stop().animate({ top: ($lower.offset().top - $productImage.outerHeight() - $parent.offset().top) });
                    }
                } else {
                    $productImage.stop().animate({ top: 0 });
                }
            });
        }
    });

    $("#productTree .productTreeChildrenNodes, #productTree").mouseleave(function (event) {
        $productImage.attr('src', originalImageSrc);
    });

    $slider = $('.slider');
    $accordion = $(".accordion");
    $accordion.accordion({ fillSpace: true });
    $slider.each(function () { $(this).accordianScroller() });
    $slider.trigger('scroll:activate');
    $accordion.bind('accordionchange', function (e, ui) {
        ui.newContent.find('.slider').trigger('scroll:activate');
    });

    $(".question").bind('click', function (e) {
        $this = $(this);
        $('.answer').not($this.next('.answer')).addClass("hide");
        $this.next('.answer').toggleClass("hide");
        $this.closest('.PanelContent').find('.slider').trigger('scroll:adjust');
        e.preventDefault();
    });


    //Product tab control script-Benfits,Directions,Tips.//
    $('.frgcMistTabs li:first a').addClass('current');
    $('.frgcMistTabsContent div.tab-content').hide();
    $('.frgcMistTabsContent div:first').show();
    $('.frgcMistTabs li a span').each(function () {

        $(this).click(function () {

            $(".frgcMistTabs li a").removeClass('current');
            $(this).parent().toggleClass('current');
            var targetDiv = $(this).parent().attr("href");
            $('.frgcMistTabsContent div.tab-content').hide();
            $('[id=' + targetDiv + ']').show();
            return false;
        });
    });

});



