﻿
$(function () {

    //settings = {
   //     tl: { radius: 5 },
    //    tr: { radius: 5 },
    //    bl: { radius: 5 },
    //    br: { radius: 5 },
    //    autoPad: true,
    //    validTags: ["div"]
    //}

    //$('.Rounded').corner(settings);



    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function () {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });


    //Hide Menu


    $(".btnSearch").click(function () {

        if ($('#depth').val() == "" || $('#widthatfront').val() == "" || $('#widthatback').val() == "") {
            alert("Please populate all fields");
            return false
        }
        return true;
    });

    $(".product-images a").click(function () {

        $('.image-holder .ProductImage img').attr('src', $(this).attr('href'));

        $('.Zoom').attr('href', $(this).attr('href').replace('/small/', '/large/'));

        $(".jqzoom").jqzoom();
        return false;
    });

    $(".Zoom").colorbox();
    $(".leave-review").colorbox({ iframe: true, width: "490px", height: "460px" });

    $(".OptionRadio").click(function () {

        $(".Prices").html($(this).parent().parent().find(".sku-price").html());
    });



    //Search
    $("#seach-btn").click(function () {
        if ($('#search-name').val() != "") {

            $("#Loading").show();
            var SearchStr = $('#search-name').val();
            var Search = "/Search/" + encodeURIComponent(SearchStr);

            top.location.href = Search;
            return false;
        } else {
            alert("Please Enter Search Term");
        }
    });

    $("#search-name").keypress(function (event) {
        if (event.keyCode == 13) {
            if ($('#search-name').val() != "") {
                $("#Loading").show();

                var SearchStr = $('#search-name').val();
                var Search = "/Search/" + encodeURIComponent(SearchStr);

                top.location.href = Search;
                return false;
            } else {
                alert("Please Enter Search Term");
            }
        }

    });

    //category sort
    $('.Sort').change(function () {
        $("#Loading").show();
        var SortMode = $(this).val();
        var pathname = window.location.pathname;

        location.href = pathname + "?sort=" + SortMode;
    });

    //category sort
    $('.Manufacturer').change(function () {
        $("#Loading").show();
        var FilterMode = $(this).val();
        var pathname = window.location.pathname;

        location.href = pathname + "?filter=" + FilterMode;
    });


    //Basket Page

    //Basket Page
    $('.DeletePerm').click(function () {
        return confirm("Are you sure you wish to delete this?");
    });

    //Banners

    var CurBannerItem = 1;
    var CanClick = true;
    var MaxBannerCount = $('#banner .banner-item').length;

    //Set up the auto-rotate
    var intervalID = window.setInterval(function () {
        MoveBanner(CurBannerItem + 1);
    }, 5000);

    $('.banner-controls a').click(function () {
        window.clearInterval(intervalID);
        MoveBanner($(this).attr('rel'));
        return false;
    });

    function MoveBanner(RelVal) {
        if (CanClick == true) {
            if (RelVal > MaxBannerCount) {
                RelVal = 1;
            }

            CanClick = false;
            $('.banner-controls a').removeClass('active');      //Remove class from other buttons

            $('a[rel=' + RelVal + ']').addClass('active');         //Add Class to the clicked button

            $('.banner-name a').hide();
            $('.banner-name .text-' + RelVal).show();

            $('#banner .item-' + CurBannerItem).fadeOut('medium', function () {
                $('#banner .item-' + RelVal).fadeIn('medium');
                CanClick = true;
            });

            CurBannerItem = RelVal;
        }
    }

    //$('.group-header').click(function (e) {
    //    var id = $(e.target).attr('id').substring(13);
    //    $('.group-item').each(function () {
    //        if ($(this).hasClass('item-' + id)) {
    //            //Matched ID now check if already open
    //            slideToggle($(this), !$(this).is(":visible"));
    //        }
    //        else {
    //            slideToggle($(this), false);
    //        }
    //    });
    //});

    // Bakset image click chnages payment method
    $('#sagepay-img').click(function () {
        var checkoutInputs = $('#checkout-area input');
        checkoutInputs.attr('checked', false);

        $('#checkout-area input[value="sage"]').attr('checked', true);
    });
    $('#paypal-img').click(function () {
        var checkoutInputs = $('#checkout-area input');
        checkoutInputs.attr('checked', false);

        $('#checkout-area input[value="paypal"]').attr('checked', true);
    });

});




function slideToggle(el, bShow) {
    var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");

    if (arguments.length == 1) bShow = !visible;

    if (!height) {

        height = $el.show().height();

        $el.data("originalHeight", height);

        if (!visible) $el.hide().css({ height: 0 });
    }

    if (bShow == visible) {
        return false;
    } 

    if (bShow) {
        $el.show().animate({ height: height }, { duration: 550 });
    } else {
        $el.animate({ height: 0 }, { duration: 550, complete: function () {
            $el.hide();
        }
        });
    }
}

