﻿$(document).ready(function() {
    // Highlight navigation on hover
    $("#Nav li").mouseenter(function() {
        $(this).addClass("selected");
    });
    $("#Nav li").mouseleave(function() {
        $(this).removeClass("selected");
    });
    // Highlight shopping basket on hover
    $(".minicart").mouseenter(function() {
        $(this).addClass("minicarthl");
        $(".minicartline").addClass("minicartlinehl");
    });
    $(".minicart").mouseleave(function() {
        $(this).removeClass("minicarthl");
        $(".minicartline").removeClass("minicartlinehl");
    });
    // Click function on shopping basket
    $(".minicart").click(function() {
        window.location.href = "shoppingcart.aspx";
    });
    // Highlight search result cell on hover
    $(".resultcell").mouseenter(function() {
        $(this).addClass("resultcellhl");
    });
    $(".resultcell").mouseleave(function() {
        $(this).removeClass("resultcellhl");
    });
    // Highlight home category on hover
    $(".featuredcategory").mouseenter(function() {
        $(this).addClass("featuredcategoryhl");
    });
    $(".featuredcategory").mouseleave(function() {
        $(this).removeClass("featuredcategoryhl");
    });
    // Highlight home product on hover
    $(".featuredproducts").mouseenter(function() {
        $(this).addClass("featuredproductshl");
    });
    $(".featuredproducts").mouseleave(function() {
        $(this).removeClass("featuredproductshl");
    });
    // Highlight latest rss on hover
    $(".latestrss").mouseenter(function() {
        $(this).addClass("latestrsshl");
    });
    $(".latestrss").mouseleave(function() {
        $(this).removeClass("latestrsshl");
    });
    // Highlight social links on hover
    $(".sociallinks").mouseenter(function() {
        $(this).addClass("sociallinkshl");
    });
    $(".sociallinks").mouseleave(function() {
        $(this).removeClass("sociallinkshl");
    });
    // Highlight content box on hover
    $(".contentbox").mouseenter(function() {
        $(this).addClass("contentboxhl");
    });
    $(".contentbox").mouseleave(function() {
        $(this).removeClass("contentboxhl");
    });
    // Highlight long product display on hover
    $(".productcell").mouseenter(function() {
        $(this).addClass("productcellhl");
    });
    $(".productcell").mouseleave(function() {
        $(this).removeClass("productcellhl");
    });
    // Click function on long product display
    $(".productcell").click(function() {
        window.location.href = $(this).children().find("a").attr("href");
        return false;
    });
    // Click function on product display
    $(".productcell").click(function() {
        window.location.href = $(this).children().find("a").attr("href");
        return false;
    });
    // Highlight half product display on hover
    $(".lastproductcell").mouseenter(function() {
        $(this).addClass("lastproductcellhl");
    });
    $(".lastproductcell").mouseleave(function() {
        $(this).removeClass("lastproductcellhl");
    });
    // Click function on half product display
    $(".lastproductcell").click(function() {
        window.location.href = $(this).children().find("a").attr("href");
        return false;
    });
    // Search Website
    $("#Go").click(function() {
        window.location.href = "search.aspx?searchterm=" + $("#searchBox").val().replace("&", "");
        return false;
    });
    // Search Categories
    $("#GoCat").click(function() {
        if (!$("#manufactcat").val()) {
            window.location.href = "?searchterm=" + $(".searchcat").val().replace("&", "");
        } else {
        window.location.href = "?searchterm=" + $(".searchcat").val().replace("&", "") + "&ManID=" + $("#manufactcat").val();
        }
        return false;
    });
    // Disable Enterkey
    $('body').keypress(function(e) {
        var code = null;
        code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            if ($("#searchBox").val().length > 0) {
                window.location.href = "search.aspx?searchterm=" + $("#searchBox").val().replace("&", "");
                return false;
            } else if ($(".searchcat").val().length > 0) {
                if (!$("#manufactcat").val()) {
                    window.location.href = "?searchterm=" + $(".searchcat").val().replace("&", "");
                } else {
                window.location.href = "?searchterm=" + $(".searchcat").val().replace("&", "") + "&ManID=" + $("#manufactcat").val();
                }
                return false;
            }
            else {
                return false;
            }
        }
    });
    // Show Hide Upsell On Cart
    $("#togglecartextras").click(function() {
        $("#cartextras").slideToggle("slow");
    });
    // Set First Customer Testimonial
    $("#testimonials span:first").addClass("active");
    // Highlight .matrix on hover
    $(".matrix").mouseenter(function() {
        $(this).addClass("matrixhover");
    });
    $(".matrix").mouseleave(function() {
        $(this).removeClass("matrixhover");
    });
    // Super LightBox
    function launch() {
        $('#inStockInfo').lightbox_me({ centered: true });
    }
    $('.stockInfo').click(function(e) {
        $("#inStockInfo").lightbox_me({ centered: true });
        e.preventDefault();
    });
    $('.extra_info_pop').click(function(e) {
        $("#inStockInfo").lightbox_me({ centered: true });
        e.preventDefault();
    });
});
// Magic Zoom Options
MagicZoomPlus.options = {
    'zoom-position': 'right',
    'show-title': 'false',
    'zoom-fade': 'true',
    'smoothing-speed': '17',
    'selectors-effect': 'false'
}
// Autosuggest
function suggest(a) {
    if (a.length < 2) {
        $("#suggestions").stop(false, true).slideUp()
    } else {
        $.get("autosuggest.aspx", { queryString: "" + a + "" }, function(b) {
            if (b.length > 1) { $("#suggestions").stop(false, true).slideDown(); $("#suggestionsList").html(b) }
        })
    }
}
// Fill Autosuggest
function fill(a) {
    $("#searchBox").val(a); setTimeout("$('#suggestions').stop(false, true).slideUp();", 300)
};
// Text Slide Show Control
function textSlideSwitch() {
    var $active = $('#testimonials span.active');
    if ($active.length == 0) $active = $('#testimonials span:last');
    var $next = $active.next().length ? $active.next()
            : $('#testimonials span:first');
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
            .addClass('active')
            .animate({ opacity: 1.0 }, 1000, function() {
                $active.removeClass('active last-active');
            });
}
// Set Slide Show Times
$(function() {
    setInterval("textSlideSwitch()", 5000);
});
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
