// fancybox ===============================================================
/* This is basic - uses default settings */
//$(".lightbox").fancybox();
//function pageLoad(sender, args) {


//function pageLoad(sender, args) {
$(window).load(function(){
    if ($('.lb-trigger').length) { //only process if we actually have a lightbox
        $('.lb-trigger').fancybox({
            'autoScale': true,
            '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#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;
        });
    }
	
	
	//===============================================================
    /*=product page - LB fabric swatches*/
	if ($('#lb-fabricSwatches .content').length) {
		$('#lb-fabricSwatches .slidingPanel').not(':first').hide();
		
		$('#lb-fabricSwatches .accordionTrigger').click(function() {
			var self = $(this).parent().find('.slidingPanel');
			$('.slidingPanel').not(self).hide();
			$('.accordionTrigger').not(this).removeClass('open');
			self.show();
			$(this).addClass('open');
		});
	}
    
	
	// 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 h2').click(function() {
            if ($(this).parent().hasClass('open')) {
                $('ul.questionsList .sliderPanel').slideUp();
                $('ul.questionsList li').removeClass('open');
            }
            else {
                $('.sliderPanel').slideUp();
                $('ul.questionsList li').removeClass('open');
                $(this).parent().addClass('open');
                $(this).parent('li').find('.sliderPanel').slideDown();
            }
        });
        if (location.hash != '') { //opens the relevant question and scrolls to the title of the section
            $('ul.questionsList > li').removeClass('open');
            $('ul.questionsList ' + location.hash).addClass('open');
            //$('html').animate({ scrollTop: jQuery(location.hash).parent().prev('h3').offset().top }, 20);
        }
    }




    $('.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();
//		});
//	}



    // special order tooltip ==================================
    if ($('.stockIndicator.specialOrder').length) {		
		$('.stockIndicator.specialOrder').hover(function() {
			$('div.tooltip').stop(true, true).slideDown('slow');
		}, function(){
			$('div.tooltip').fadeOut();
		});
	}
	
	// newsletter signup ==================================
    if ($('fieldset.newsletterSignup').length) {
		var signupTrigger = $('fieldset.newsletterSignup p.textField, fieldset.newsletterSignup p.btn-signup');
		$('#newsletterForm').hide();
		$(signupTrigger).click(function() {
			$('#newsletterForm').fadeIn();
			//$('#newsletterForm input:first').focus();
			$('#submitClose').click(function() {
				$(this).parents().find('#signupIntro').hide();
				$(this).parents().find('.thanks').show();				
				$(this).parents().find('#newsletterForm')/*.delay(1000)*/.fadeOut();
				return false;
			});
		});
	}
	
	
	
	if ($('#btn-liveHelp').length) {
		$('#btn-liveHelp').click(function(e) {
			$('#whoson_chat_link').trigger('click')
			return false;
		});
	}


    

//===============================================================
});/* end document.ready */
