// fancybox ===============================================================
/* This is basic - uses default settings */
//$(".lightbox").fancybox();

function pageLoad(sender, args) {
    if ($('.lightbox').length) { //only process if we actually have a lightbox
        $('.lightbox').fancybox({
            'autoScale': false,
            'scrolling': 'no',
            'titleShow': false,
            'overlayColor': '#000',
            'overlayOpacity': 0.7
        });

        $('a#close-lb').click(function() {
            $.fancybox.close();
            return false;
        });
    }
}

$(document).ready(function() {
    // ===============================================================================

    if ($('#extraText').length) {
        var adjustHeight = (($('#extraText').height() + 60) + "px");
        //$('div.withSideNav').css({ paddingBottom: adjustHeight });
        $('div#indexPage').css({ paddingBottom: adjustHeight });
    }

    //===============================================================

    if ($('.basketOptions').length)
        $('.basketOptions .sliderPanel').not(':first').hide();
    if ($('.sliderButton').length)
        $(".sliderButton").click(function() {
            $(this).parent().find(".sliderPanel").stop(true, true).slideToggle();
            $(this).toggleClass("open");
        });

    //===============================================================
    /*=basketPage*/
    if ($('#detailsPanel').length) {
        $('#detailsPanel').hide();

        $("#showPanel").toggle(function() {
            $("#detailsPanel").stop(true, true).slideToggle();
            $(this).html("- hide cost detail");
            return false;
        }, function() {
            $("#detailsPanel").stop(true, true).slideToggle();
            $(this).html("+ show cost detail");
            return false;
        });
    }

    /*=checkoutPage*/
    if ($('#createAccount').length) {
        $("#showAccount").click(function() {
            $("#createAccount").slideDown();
            $("#showAccount").hide();
            $("#wrapper").removeClass('noborder');
            return false;
        });
    }

    // FAQs slide toggle panels ===============================================================
    if ($('ul.questionsList').length) { //we only care about doing the following if we are on a questions page
        if (location.hash != '') {
            $('ul.questionsList :not(' + location.hash + ')  .sliderPanel').hide();
        }
        else {
            $('ul.questionsList .sliderPanel').hide();
        }

        $('ul.questionsList li.trigger').click(function() {
            if ($(this).hasClass('open')) {
                $('ul.questionsList li.trigger .sliderPanel').slideUp();
                $('ul.questionsList li.trigger').removeClass('open');
            }
            else {
                $('.sliderPanel').slideUp();
                $('ul.questionsList li.trigger').removeClass('open');
                $(this).addClass('open');
                $(this).find('.sliderPanel').slideDown();
            }
        });
        if (location.hash != '') { //opens the relevant question and scrolls to the title of the section
            $('ul.questionsList li.trigger').removeClass('open');
            $('ul.questionsList ' + location.hash).addClass('open');
            $('html').animate({ scrollTop: jQuery(location.hash).parent().prev('h3').offset().top }, 20);
        }
    }



    if ($('ul.tabs li:nth-child(2)').hasClass('current')) {
        $('.tabContent:not(:nth-child(2))').hide(); // hides all tab content EXCEPT the first child element 
        $('ul.tabs li:nth-child(2)').addClass('current').show(); // activate first tab link
    }
    else {
        $('.tabContent:not(:nth-child(1))').hide(); // hides all tab content EXCEPT the first child element 
        $('ul.tabs li:nth-child(1)').addClass('current').show(); // activate first tab link
    }

    $('ul.tabs li').click(function() {
        $('ul.tabs li').removeClass('current');
        $(this).addClass('current');
        $('.tabContent').hide();

        var activeTab = $(this).find('a').attr('href'); //Find the href attribute value to identify the active tab + content
        $(activeTab).show();
        return false;
    });


    // Subcat sidebar tooltip ===============================================================
    if ($('.sidebarFilters .moreInfo').length) {
        $('.moreInfo .btn-openBubble').click(function() {
            var closebtn = $(this).parent().find('.bubble');

            $('.bubble').not(closebtn).fadeOut();
            $(this).parent().find('.bubble').fadeIn();
        });

        $('.moreInfo .btn-closeBubble').click(function() {
            $(this).parents().find('.bubble').fadeOut();
        });
    }



    // Product page added to basket notify ===============================================================

    if ($('#purchaseOptions').length) {
        //$('div#btn-BuyNow').click(function() {
        //	$('#notifyBasketWrapper').fadeIn().delay(7000).fadeOut();
        //});

        $('a#btn-close').click(function() {
            $('#notifyBasketWrapper').stop(false, false).fadeOut();
            return false;
        });
    }



    // special order tooltip ==================================
    if ($('.stockIndicator.specialOrder').length) {
        $('.stockIndicator.specialOrder').hover(function() {
            $('div.tooltip').stop(true, true).slideDown('slow');
        }, function() {
            $('div.tooltip').fadeOut();
        });
    }

    //===============================================================
});      /* end document.ready */
