﻿
$(document).ready(function () {

    settings = {
        tl: { radius: 100 },
        tr: { radius: 100 },
        bl: { radius: 5 },
        br: { radius: 5 },
        autoPad: true,

    }

    $('.bottom').corner(settings);

    settings = {
        tl: { radius: 5 },
        tr: { radius: 5 },
        bl: { radius: 5 },
        br: { radius: 5 },
        autoPad: true,
    }

    $('#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);
    });

    $('.rounded').corner(settings);


    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li a:first").addClass("active-tab").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li a").click(function () {
        $("ul.tabs li a").removeClass("active-tab"); //Remove any "active" class
        $(this).addClass("active-tab"); //Add "active-tab" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).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-extra-images a").click(function () {

        $('.main-image img').attr('src', $(this).attr('href'));

        $('.zoom').attr('href', $(this).attr('href').replace('/small/', '/large/'));
        return false;
    });

    $(".zoom").colorbox();

    $(".OptionRadio").click(function () {

        $(".Prices").html($(this).parent().parent().find(".sku-price").html());
    });



    //Search
    $("#search-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;
    });


    //Basket Page

    //Basket Page
    $('.DeletePerm').click(function () {
        return confirm("Are you sure you wish to delete this?");
    });


    //What do I Need Drop Down

    $('.drop-header').click(function () {
        $(this).parent().find('.suggestion-box').slideToggle();
        $(this).toggleClass('active');
        return false;
    });


    //Form Submission
    $('#add-to-basket').click(function() {
        $('#product-data form').submit();
        return false;
    });


    // Homepage Carousel

    if($('.jcarousel-skin-tango').length > 0)
    {
    jQuery('#mycarousel').jcarousel();
    }

    // Basket Page
    $('.btn-pay').click(function(){
    $('#basket-display form').submit();
    return false;
    });

    // Details Page
    $('.btn-pay').click(function(){
    $('#customer-details form').submit();
    return false;
    });

});
