﻿
$(document).ready(function () {

    //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;
    });

    //JQ ZOOM STUFF 
    //$(".jqzoom").jqzoom();

    //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 .product-image img').attr('src', $(this).attr('href'));

        $('.focus-image').attr('href', $(this).attr('href').replace('/small/', '/large/'));

       //$('.jqzoom').attr('href', $(this).attr('href').replace('/small/', '/zoom/'));

    //    $('.jqzoom').jqzoom();
        return false;
    });

    $(".zoom").colorbox();
    $(".lightbox").colorbox({ iframe: true, innerWidth: 425, innerHeight: 344 });


    $(".OptionRadio").click(function () {

        $(".single-price").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?");
    });

    //Cufon

    Cufon.replace('h1', { fontFamily: 'Jura' });
    Cufon.replace('#banner .banner-left p', { fontFamily: 'Jura' });


    //Top menu System changes

    $('#top-nav ul li.main').hover(function () {
        $(this).addClass('hovered');
    }, function () {
        $(this).removeClass('hovered');

    });

    // Sub Menu Showing

    $('.fireplaces, .sub-nav').hover(function () {
        $('.sub-nav').addClass('active');
        $('.fireplaces').addClass('active');
    }, function () {
        $('.sub-nav').removeClass('active');
        $('.fireplaces').removeClass('active');
    });


    //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;
        }
    }

    // Add to Basket Button Submit
    $('.action-button a.red-button').click(function () {
        $('form').submit();
        return false;
    }); 

});
