//drop down menu on scroll
jQuery(window).scroll(function () {
    if (jQuery(window).width() > 767) {
        if (jQuery(this).scrollTop() > 50) {
            // jQuery('#sdnav').addClass("down");
            // hideSuggestions();
            jQuery('body').addClass('fixed');
        } else {
            //jQuery('#sdnav').removeClass("down");
            jQuery('body').removeClass('fixed');
        }
    }
    if (jQuery('#stickycart').length) {
        var scwidth = jQuery('#stickycart').width();
        if (jQuery(window).width() > 676) {
            if (jQuery(this).scrollTop() > 270) {
                jQuery('#stickycart').addClass("down");
                jQuery('#stickycart').css("width", scwidth);
                hideSuggestions();
            } else {
                jQuery('#stickycart').removeClass("down");
            }
        }
    }

});
jQuery(window).load(function () {
    jQuery('.at-svc-twitter').attr("tw:counturl", window.location.href);

});
//disabled tool tips display
jQuery('.disabled').mouseenter(function () {
    jQuery(this).addClass("dopop");
});
jQuery('.disabled').mouseleave(function () {
    jQuery(this).removeClass("dopop");
});
jQuery('.printfield').mouseenter(function () {
    jQuery(this).addClass("dopop");
});
jQuery('.printfield').mouseleave(function () {
    jQuery(this).removeClass("dopop");
});
//mobile search popout
jQuery('#mobile-search').click(function () {
    jQuery('#topbar #search-top').slideToggle('fast');
});
//login popout
jQuery('.loginbutton').click(function () {
    jQuery('#popout').toggleClass('open');
    jQuery('#overlay').toggle();
});
jQuery('#mobile-actions').click(function () {
    jQuery('#mobile-actionmenu').slideToggle()
});
jQuery('.closebutton').click(function () {
    jQuery('#popout').toggleClass('open');
    jQuery('#overlay').toggle();
});
//toggles
jQuery('#b1').click(function () {
    jQuery('#t1').slideToggle('slow');
    jQuery('#b1 .bmessage').fadeToggle('slow');
    jQuery('#t1b').fadeToggle('slow');
});
jQuery('#t1 .close').click(function () {
    jQuery('#t1').slideToggle('slow');
    jQuery('#b1 .bmessage').fadeToggle('slow');
    jQuery('#t1b').slideToggle('slow');
});
jQuery('#b2').click(function () {
    jQuery('#t2').slideToggle('slow');
    jQuery('#b2 .bmessage').fadeToggle('slow');
    jQuery('#t2b').slideToggle('slow');
});
jQuery('#t2 .close').click(function () {
    jQuery('#t2').slideToggle('slow');
    jQuery('#b2 .bmessage').fadeToggle('slow');
    jQuery('#t2b').slideToggle('slow');
});
jQuery('#b3').click(function () {
    jQuery('#t3').slideToggle('slow');
    jQuery('#b3 .bmessage').fadeToggle('slow');
    jQuery('#t3b').slideToggle('slow');
});
jQuery('#t3 .close').click(function () {
    jQuery('#t3').slideToggle('slow');
    jQuery('#b3 .bmessage').fadeToggle('slow');
    jQuery('#t3b').slideToggle('slow');
});
jQuery('.nav-tabs a').click(function (e) {
    e.preventDefault();
    jQuery('.nav-tabs a[href="#basic"]').tab('show');
    jQuery('.nav-tabs a[href="#advanced"]').tab('show');
})
jQuery('.mainmenu > li').click(function () {
    jQuery(this).addClass('firstclick');
})
jQuery('#mobileaccounttabs').click(function () {
    jQuery('#mobileaccounttabs li').removeClass('active');
})
jQuery('#mobileyearnav').click(function () {
    jQuery('#mobileyearnav li').removeClass('active');
})
jQuery('#mobileaccounttabs #dropdownMenu1').click(function () {
    jQuery('#mobileaccounttabs .dropdown-menu').slideToggle('fast');
})
jQuery('#mobileaccounttabs a').click(function () {
    jQuery('#mobileaccounttabs .dropdown-menu').slideToggle('fast');
})
jQuery('.icon-customlists > span').click(function (e) {
    var p = jQuery(this).parent();
    jQuery('.customlists:visible').stop(true, true).hide();
    jQuery(p).find('.customlists').fadeToggle('fast');
    e.stopPropagation();
})
jQuery('.customlists').click(function (e) {
    e.stopPropagation();
})
jQuery('body').click(function () {
    jQuery('.customlists:visible').stop(true, true).hide();
});
function AppPopup(delay) {
    var w = jQuery(window).width();
    setTimeout(function () {
        jQuery('#AppPopup').animate({ opacity: 1 });
    }, delay);
    if (w > 767) { //desktop
        setTimeout(function () {
            jQuery('#AppPopup .aone .RoundImg').animate({
                top: '0px',
                opacity: 1
            });
            jQuery('#AppPopup .aone .RoundImg span').delay(250).animate({ opacity: 1 });
            jQuery('#AppPopup .aoneb').delay(500).animate({ opacity: 1 });
        }, delay + 1000);
        setTimeout(function () {
            jQuery('#AppPopup .atwo .RoundImg').animate({
                top: '0px',
                opacity: 1
            });
            jQuery('#AppPopup .atwo .RoundImg span').delay(250).animate({ opacity: 1 });
            jQuery('#AppPopup .atwob').delay(500).animate({ opacity: 1 });
        }, (delay + 2500));
        setTimeout(function () {
            jQuery('#AppPopup .athree .RoundImg').animate({
                top: '0px',
                opacity: 1
            });
            jQuery('#AppPopup .athree .RoundImg span').delay(250).animate({ opacity: 1 });
            jQuery('#AppPopup .athreeb').delay(500).animate({ opacity: 1 });
        }, (delay + 4000));
        setTimeout(function () {
            jQuery('#AppPopup .afour').animate({ opacity: 1 });
        }, (delay + 6000));
        setTimeout(function () {
            jQuery('#AppPopup .afive').animate({ opacity: 1 });
        }, (delay + 6750));
        setTimeout(function () {
            jQuery('#AppPopup .asix').animate({ opacity: 1 });
        }, (delay + 7250));
        setTimeout(function () {
            jQuery('#AppPopup #ClosePopup').animate({ opacity: 1 });
        }, (delay + 9000));
    } else { // mobile
        setTimeout(function () {
            jQuery('#AppPopup .afour').animate({ opacity: 1 });
        }, (delay + 750));
        setTimeout(function () {
            jQuery('#AppPopup .afive').animate({ opacity: 1 });
        }, (delay + 1250));
        setTimeout(function () {
            jQuery('#AppPopup .asix').animate({ opacity: 1 });
        }, (delay + 1750));
        setTimeout(function () {
            jQuery('#AppPopup #ClosePopup').animate({ opacity: 1 });
        }, (delay + 2500));
    }
}
function closePopup() {
    jQuery('#AppPopup').animate({ opacity: 0, bottom: '-500px' });
    setTimeout(function () {
        jQuery('#AppPopup').remove();
    }, 1500);
}
function setPSRowWidths(t) {
    var ww = jQuery(window).width(),
        vars = {},
        p = jQuery('ul.ps-row'),
        add = 0;
    if (ww > 500) {
        for (x = 1; x < 5; x++) {
            if (t = 1) {
                p.each(function () {
                    jQuery(this).find('li:nth-of-type(' + x + ')').css('width', 'auto');
                });
            }
            value = 'pscol' + x;
            vars[value] = 0;
            p.each(function () {
                var thisWidth = jQuery(this).find('li:nth-of-type(' + x + ')').outerWidth();
                if (thisWidth > vars[value]) {
                    vars[value] = thisWidth;
                }
            });
            if (ww > 989 || (ww < 768 && ww > 500)) {
                add = 10;
            }
            p.each(function () {
                jQuery(this).find('li:nth-of-type(' + x + ')').css('width', (vars[value] + add) + 'px');
            });
        }
    }
}
setPSRowWidths(0);
jQuery('.morelocations').click(function (e) {
    e.preventDefault();
    jQuery(this).closest('.stockblock-details').find('.exmorelocations').slideToggle();
    jQuery(this).toggleClass('rotate', '');
    setWidths();
});
function setWidths() {
    widths = new Array();
    classes = new Array();
    jQuery('.exmorelocations th:visible').each(function () {
        widths.push(jQuery(this).outerWidth());
        classes.push(jQuery(this).attr('class'));
    });
    jQuery('.subtable tr').each(function () {
        var i = 1;
        do {
            jQuery(this).find('td:nth-of-type(' + i + ')').width(widths[(i - 1)] + 'px');
            jQuery(this).find('td:nth-of-type(' + i + ')').addClass(classes[(i - 1)]);
            i++;
        }
        while (i <= 6)
    });
}
function hideSuggestions() {
    jQuery('div#asSuggest').animate({ opacity: 0 });
    setTimeout(function () {
        jQuery('div#asSuggest').hide();
    }, 250);
}
jQuery('.ec-trigger').click(function (e) {
    e.preventDefault();
    if (!jQuery(this).hasClass('open')) {
        jQuery('.ec-target').each(function () {
            jQuery(this).hide();
        })
        jQuery('.ec-trigger.open').removeClass('open');
    }
    jQuery(this).toggleClass('open', '');
    var parent = jQuery(this).closest('.subtable');
    jQuery(parent).find('.ec-target').each(function () {
        jQuery(this).toggle();
    });
});

//ready functions
jQuery(document).ready(function () {
    $('#mmt,#mmc').click(function (e) {
        e.preventDefault();
        $('.mainmenu').slideToggle(50);
    });
    $('.stoggle').click(function (e) {
        e.preventDefault();
        $('#headersearch').toggleClass('open');
    });
    $('.ex .readmore').click(function (e) {
        e.preventDefault();
        var t = $(this),
            p = t.closest('.ex'),
            target = p.find('p');
        if (p.hasClass('open')) {
            p.removeClass('open');
            target.css('max-height', '100px');
            t.text("more");
        } else {
            p.addClass('open');
            target.css('max-height', target.prop('scrollHeight') + 'px');
            t.text("less");
        }
    });
    $('.ex').each(function () {
        if ($(this).find('p').prop('scrollHeight') < 100) {
            $(this).find('.bg').remove();
            $(this).find('.readmore').remove();
        }
    });
    $('.ex-search a').click(function (e) {
        e.preventDefault();
        var t = $(this),
            p = t.closest('.ex-search'),
            target = p.find('.ex-content');
        if (p.hasClass('open')) {
            p.removeClass('open');
            t.removeClass('opened').addClass('closed');
            target.css('max-height', '0px').fadeOut();
        } else {
            p.addClass('open');
            t.removeClass('closed').addClass('opened');
            target.fadeIn().css('max-height', target.prop('scrollHeight') + 'px');
        }
    });

    $('.activate').click(function () {
        $(this).find('i').addClass('fa-spin');
    });
    //prep top menu etc
    var menu = jQuery('.mainmenu').clone();
    jQuery('#sdmenu').html(menu);
    var actions = jQuery('.getmobileactions').clone();
    jQuery('#mobile-actionmenu').html(actions);
    var search = jQuery('#search-top').clone();
    jQuery('#sdsearch').html(search);
    jQuery('#sdsearch #search-top').removeClass('col-md-3 col-xs-4');
    var socials = jQuery('#social-top .socials').clone();
    jQuery('#mobile-socials').html(socials);
    jQuery('.carousel').carousel()
    //initialize sliders if present
    if (jQuery('#slider').length) {
        jQuery('.carousel').carousel({
            interval: 4000,
            pause: "hover",
            wrap: true
        })
    }
    //display buy agains
    jQuery('#displayallbuyagains').click(function (e) {
        e.preventDefault();
        jQuery('#allbuyagains').slideToggle().css('display', 'inline-block');
    });
    jQuery('.sbox').customSelect({ customClass: 'csbox' });
    jQuery("[rel='tooltip']").tooltip();
    jQuery(function () {
        var hash = window.location.hash;
        hash && jQuery('ul.nav a[href="' + hash + '"]').tab('show');
        jQuery('.nav-tabs a').on('click', function (e) {
            var hash = this.hash;
            e.preventDefault();
            if (!$(this).hasClass('nohash')) {
                window.location.hash = hash;
            }
            var offset = 100;
            if ($(this).hasClass('offset150')) {
                offset = 150;
            }
            jQuery(this).tab('show');
            setTimeout(function (hash) {
                var el = jQuery(hash)[0];
                for (var lx = 0, ly = 0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
                jQuery('html, body').animate({
                    scrollTop: (ly - offset)
                }, 500);
            }.bind(this, hash), 250);
        });
    });

    jQuery('.agentspage .quicklinks a').on('click', function (g) {
        var hash = this.hash;
        g.preventDefault();
        //	window.location.hash = hash;
        setTimeout(function (hash) {
            var el = jQuery(hash)[0];
            for (var lx = 0, ly = 0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
            jQuery('html, body').animate({
                scrollTop: (ly - 65)
            }, 500);
        }.bind(this, hash), 50);
    });
    // reviews show/hide
    jQuery('.singlewineblock .reviews a').click(function (e) {
        e.preventDefault();
        var t = jQuery(this);
        var c = t.attr('data-show');
        if (c == 'noshow') { //hide it
            t.attr('data-show', 'yesshow').text('See Them All');
            jQuery('.singlewineblock .reviewblock').hide();
        } else { //show it
            t.attr('data-show', 'noshow').text('Hide Them All');
            jQuery('.singlewineblock .reviewblock').show();
        }
    });
    //search suggest popup
    //jQuery('#search-top input[type="text"]').one('keypress', function () {
    //    var div = jQuery(this).closest('#search-top').find('#asSuggest');
    //    div.show();
    //    setTimeout(function(){
    //        div.animate({opacity:1})
    //    }, 500)
    //});
    jQuery('#search-top input[type="text"]').keyup(function () {
        var div = jQuery(this).closest('#search-top').find('#asSuggest');
        alert(div.length());
        if (div.length == 0) {
            alert(jQuery(this).length);
            div.show();
            setTimeout(function () {
                div.animate({ opacity: 1 })
            }, 500)
        }
        jQuery('span#sText').text(jQuery(this).val());
    })
    jQuery('.closeSuggestions').click(function (e) {
        e.preventDefault();
        hideSuggestions();
    })
});
//tabs
+function ($) {
    'use strict';

    // TAB CLASS DEFINITION
    // ====================

    var Tab = function (element) {
        this.element = $(element)
    }

    Tab.prototype.show = function () {
        var $this = this.element
        var $ul = $this.closest('ul:not(.dropdown-menu)')
        var selector = $this.data('target')

        if (!selector) {
            selector = $this.attr('href')
            selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
        }

        if ($this.parent('li').hasClass('active')) return

        var previous = $ul.find('.active:last a')[0]
        var e = $.Event('show.bs.tab', {
            relatedTarget: previous
        })

        $this.trigger(e)

        if (e.isDefaultPrevented()) return

        var $target = $(selector)

        this.activate($this.parent('li'), $ul)
        this.activate($target, $target.parent(), function () {
            $this.trigger({
                type: 'shown.bs.tab',
                relatedTarget: previous
            })
        })
    }

    Tab.prototype.activate = function (element, container, callback) {
        var $active = container.find('> .active')
        var transition = callback
            && $.support.transition
            && $active.hasClass('fade')

        function next() {
            $active
                .removeClass('active')
                .find('> .dropdown-menu > .active')
                .removeClass('active')

            element.addClass('active')

            if (transition) {
                element[0].offsetWidth // reflow for transition
                element.addClass('in')
            } else {
                element.removeClass('fade')
            }

            if (element.parent('.dropdown-menu')) {
                element.closest('li.dropdown').addClass('active')
            }

            callback && callback()
        }

        transition ?
            $active
                .one($.support.transition.end, next)
                .emulateTransitionEnd(150) :
            next()

        $active.removeClass('in')
    }


    // TAB PLUGIN DEFINITION
    // =====================

    var old = $.fn.tab

    $.fn.tab = function (option) {
        return this.each(function () {
            var $this = $(this)
            var data = $this.data('bs.tab')

            if (!data) $this.data('bs.tab', (data = new Tab(this)))
            if (typeof option == 'string') data[option]()
        })
    }

    $.fn.tab.Constructor = Tab


    // TAB NO CONFLICT
    // ===============

    $.fn.tab.noConflict = function () {
        $.fn.tab = old
        return this
    }


    // TAB DATA-API
    // ============

    $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
        e.preventDefault()
        $(this).tab('show')
    })

}(jQuery);
//rewrite selects
(function (a) { a.fn.extend({ customSelect: function (c) { if (typeof document.body.style.maxHeight === "undefined") { return this } var e = { customClass: "customSelect", mapClass: true, mapStyle: true }, c = a.extend(e, c), d = c.customClass, f = function (h, k) { var g = h.find(":selected"), j = k.children(":first"), i = g.html() || "&nbsp;"; j.html(i); if (g.attr("disabled")) { k.addClass(b("DisabledOption")) } else { k.removeClass(b("DisabledOption")) } setTimeout(function () { k.removeClass(b("Open")); a(document).off("mouseup.customSelect") }, 60) }, b = function (g) { return d + g }; return this.each(function () { var g = a(this), i = a("<span />").addClass(b("Inner")), h = a("<span />"); g.after(h.append(i)); h.addClass(d); if (c.mapClass) { h.addClass(g.attr("class")) } if (c.mapStyle) { h.attr("style", g.attr("style")) } g.addClass("hasCustomSelect").on("render.customSelect", function () { f(g, h); g.css("width", ""); var k = parseInt(g.outerWidth(), 10) - (parseInt(h.outerWidth(), 10) - parseInt(h.width(), 10)); h.css({ display: "inline-block" }); var j = h.outerHeight(); if (g.attr("disabled")) { h.addClass(b("Disabled")) } else { h.removeClass(b("Disabled")) } i.css({ width: k, display: "inline-block" }); g.css({ "-webkit-appearance": "menulist-button", width: h.outerWidth(), position: "absolute", opacity: 0, height: j, fontSize: h.css("font-size") }) }).on("change.customSelect", function () { h.addClass(b("Changed")); f(g, h) }).on("keyup.customSelect", function (j) { if (!h.hasClass(b("Open"))) { g.trigger("blur.customSelect"); g.trigger("focus.customSelect") } else { if (j.which == 13 || j.which == 27) { f(g, h) } } }).on("mousedown.customSelect", function () { h.removeClass(b("Changed")) }).on("mouseup.customSelect", function (j) { if (!h.hasClass(b("Open"))) { if (a("." + b("Open")).not(h).length > 0 && typeof InstallTrigger !== "undefined") { g.trigger("focus.customSelect") } else { h.addClass(b("Open")); j.stopPropagation(); a(document).one("mouseup.customSelect", function (k) { if (k.target != g.get(0) && a.inArray(k.target, g.find("*").get()) < 0) { g.trigger("blur.customSelect") } else { f(g, h) } }) } } }).on("focus.customSelect", function () { h.removeClass(b("Changed")).addClass(b("Focus")) }).on("blur.customSelect", function () { h.removeClass(b("Focus") + " " + b("Open")) }).on("mouseenter.customSelect", function () { h.addClass(b("Hover")) }).on("mouseleave.customSelect", function () { h.removeClass(b("Hover")) }).trigger("render.customSelect") }) } }) })(jQuery);
