 //GA setup.. so no errors occur.
 var _gaq = _gaq || [];
 
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

// public method for encoding
encode : function (input) {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;

    input = Base64._utf8_encode(input);

    while (i < input.length) {

        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);

        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }

        output = output +
        Base64._keyStr.charAt(enc1) + Base64._keyStr.charAt(enc2) +
        Base64._keyStr.charAt(enc3) + Base64._keyStr.charAt(enc4);
    }

    return output;
},

// public method for decoding
decode : function (input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    while (i < input.length) {

        enc1 = Base64._keyStr.indexOf(input.charAt(i++));
        enc2 = Base64._keyStr.indexOf(input.charAt(i++));
        enc3 = Base64._keyStr.indexOf(input.charAt(i++));
        enc4 = Base64._keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    }

    output = Base64._utf8_decode(output);

    return output;
},

// private method for UTF-8 encoding
_utf8_encode : function (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }
    }

    return utftext;
},

// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
    var string = "";
    var i = 0;
    var c = 0, c1 = 0, c2 = 0;

    while ( i < utftext.length ) {

        c = utftext.charCodeAt(i);

        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else if((c > 191) && (c < 224)) {
            c1 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c1 & 63));
            i += 2;
        }
        else {
            c1 = utftext.charCodeAt(i+1);
            c2 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));
            i += 3;
        }
    }
    return string;
}
};


 (function($, exports){
	exports.updateImage = function(url, label, el) {
		  
		imageTag = '<img src='+url+' longdesc='+url+'>';
		$('#main-image').html(imageTag);
		var options = {
				xzoom:290,
				yzoom:272,
				offset:5,
				position:"left",
				preload:1,
                xOffset:-199,
				lens:1
			};
		
		$('#main-image').unbind();
		$('#main-image').jqueryzoom(options);
		el = $(el);
		$('main-image').attr('longdesc', url);
		$('main-image').attr('src', url);
		$('.image-label').html(label);
		var active = $('#mycarousel').find('.active-image');
		active.removeClass('active-image');
		el.addClass('active-image');
	}

	exports.updateVideo = function($container, videoUrl, width, height) {
		video = '<iframe width="'+width+'" height="'+height+'" src="'+videoUrl+'?autoplay=1" frameborder="0" allowfullscreen></iframe>';
		$container.html(video);
		return false;
	}
}(jQuery, window));

/*globals jQuery, ND, window */
(function(ND, $){

	Bonds = {
	
		animFactor:  100,
		
		initialize: function(){
			
			var bonds = Bonds,
			
				factor = bonds.animFactor,	
				
				
				/*
				 * Check the element exists then load the init.
				 * Pass the collection for performance
				 */
				load = function( selector, init ) {
					selector = $( selector );
					if( selector.size() && init ) {
						init.apply( bonds, [ selector, factor ] );
					};
				};
			
			load("#banner", bonds.bannerInit );
			load(".footer-container", bonds.footerMoreinfo );
			load(".header-container", bonds.floatingHeaderFooter );
			load(".accordian", bonds.accordian );
			load("#narrow-by-list2", bonds.navAccordian );
			load(".about-us", bonds.navHover );	
			load("#search_mini_form", bonds.searchDrop );
			load("#mycarousel li a", bonds.thumbnailPrevent);
			load(".inline-size", bonds.colorBox);
			load(".onestepcheckout-enterprise", bonds.oneStepCheckout);
			load("#messages_product_view", bonds.messages);
			load(".product-view", bonds.productDetail);
			load(".product-view", bonds.analytics.productPage);
			load("#banner", bonds.analytics.homePage);
			load("ul.social", bonds.analytics.youtube);
			load(".shipping-options", bonds.cartUpdate);
			load(".cart-qty", bonds.cartUpdateQty);
			load(".no-results-found a", bonds.noSearchResultsFound);
			load(".checkout-cart-index ul.messages", bonds.checkoutMessage);
			load(".customer-account-login ul.messages", bonds.signInMessage);

			var str = Base64.encode(location.href);
			str = str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
			$('form,a').each(function(i,element){
				var href = '';
				var attr_name = '';
				if (element.tagName =='FORM') {
					attr_name = 'action';
				}
				else {
					attr_name = 'href';
				}
				href = jQuery(element).attr(attr_name);

				if (undefined == href || href.indexOf('/uenc/') < 0) return;
			
				href = href.replace(/\/uenc\/[^\/]+\//g, '\/uenc\/'+str + '\/');
				href = href.replace(/\/b64\/[^\/]+\//g, '\/b64\/' + str + '\/');
			
				$(element).attr(attr_name, href);
			});
		},
		
		checkoutMessage: function($message) {
			$message.clone().appendTo('.checkout-messages');
		},
		
		signInMessage: function($message) {
			$message.clone().appendTo($('#pass').parent());
		},
		
		analytics: {
			
			member: 'guest',
			action: 'checkout',
			
			checkoutAnalytics: function(typeOfMember, action) {
				
				
				if(action != undefined) {
					_gaq.push(['_trackPageview','/onestepcheckout/'+typeOfMember+'/'+action])
				}
				else {
					_gaq.push(['_trackPageview','/onestepcheckout/'+typeOfMember])
				}
					
			},
			
			setMember: function(typeOfMember) {
				
				if(typeOfMember != undefined) {
					this.member = typeOfMember;
				}
			},
			
			setAction: function(actionType) {
				if(actionType != undefined) {
					this.action = actionType;
				}
			},
			
			getMember: function() {
				return this.member;
			},
			
			getAction: function() {
				return this.action;
			},
			
			homePage: function($banner) {
				$banner.find('a').click(function(){
					
					var $this = $(this);
					var href = $this.attr('href');
					var $img = $this.find('img');
					var title = $img.attr('title');
					
					_gaq.push(['_trackEvent','Homepage Ad Tiles', title, href])
					
				});
			},
			
			productPage: function() {
				$product = $('.product-essential');
				var productName = $product.find('.product-name h1').html();
				
				// tracking when swatches have been clicked
				$product.delegate('.colorswatches-items .colorSwatch-sprite', 'click', function() {
					var colour = $product.find('p.swatch-label').html();
					var label = 'Colour - '+productName+' - '+colour;
					_gaq.push(['_trackEvent','Product Tool Interaction', 'Colours', label])
				});
				
				$product.find('#attribute142').change(function(){
					// tracking for the size chart
					var sizeSelected = $('option:selected',this).text();
					var label = 'Size - '+productName+' - '+sizeSelected;
					
					_gaq.push(['_trackEvent','Product Tool Interaction', 'Size Chart', label])
				});
				
				//This will not run the description tab
				$product.find('#collateral-tabs dt').not(':first-child').click(function(){
					
					var $currentItem = $(this);
					// This will not send if class is open as the accordian function will run first and remove the active class
					// So at time of click items that are 'closed' will have a class active by the time this fires
					if($currentItem.hasClass('active')) {
						
						var text = $('span', this).html();
						var text = text.replace('&amp;', '&');
						var accordianLabel = 'View '+text+' - '+productName;
						_gaq.push(['_trackEvent','Product Tool Interaction', text, accordianLabel])
					}	
				});				
			},
			
			youtube: function($social) {
				//Youtube analytics
				$social.find('li.first a').click(function(){
					 _gaq.push(['_trackSocial', 'Youtube', 'Video']);
				});
				
			}
		
		},
		
		oneStepCheckout: function() {
			
			//check if the membertype is member on page load....if so run the analytics call
			var memberStatus = Bonds.analytics.getMember();
			if(memberStatus == 'member') {
				Bonds.analytics.checkoutAnalytics(memberStatus);
			}
			
			//$('.cvv-what-is-this').attr('href', 'what-is-this');
			
			$(".cvv-what-is-this").colorbox({ inline:true, href:"#what-is-this"});
			
						
			function adjustColHeight() {
				
				var middleCol = $('.onestepcheckout-column-middle');
				var rightCol = $('.onestepcheckout-column-right');
				
				var middheHeight = middleCol.height();
				var rightHeight = rightCol.height();
				
				if(rightCol.height() > middleCol.height()) {
					middleCol.css('height', rightHeight)
				}
			}
			
			// Change the middle column height when selecting and deselecting the add new address
			$('#billing-address-select, #shipping-address-select').change(function(){
				var $changed = $(this);
				
				if($changed.attr('id') == 'billing-address-select') {
					var $list =  $('#billing_address_list');
				}
				else {
					var $list =  $('#shipping_address_list');
				}
				
				var $middleCol = $('.onestepcheckout-column-middle');
				var middleHeight = $middleCol.height();
				var listHeight = $list.height();
				
				if($list.css('display') !== 'none') {
					var newMiddleHeight = middleHeight + 300;
					$middleCol.css('height', newMiddleHeight);
				}
				else {
					var newMiddleHeight = middleHeight - 300;
					$middleCol.css('height', newMiddleHeight);
				}
				
				
			});
			
			
			function changeAddressHeight($selector) {
				var $billing_address_list = $('#billing_address_list');
				if($billing_address_list.css('display') == 'block') {
					
					var $middleCol = $('.onestepcheckout-column-middle');
					
					var middleHeight = $middleCol.height();
					var billingAddressHeight = $billing_address_list.height();
					var newMiddleHeight = (middleHeight + billingAddressHeight) - 150;
					
					$middleCol.css('height', newMiddleHeight);
					
				}
			}
			
			
			adjustColHeight();
			
			var inputValues = Array();
			// Take the IDs and store in array
			$('#checkout-payment-method-load dt input').each(function(index){
				inputValues[index] = $(this).attr('id');
			});
			// find the tabs and assign them the classes from the array
			$('ul.payment-methods li').each(function(index){
				$(this).addClass(inputValues[index]);
			});			
			
			
			$(".payment-methods.tab li").click(function(){
				
				adjustColHeight();
				
				var thisItem = $(this);
				if(thisItem.hasClass('currentTab')) {
					
				}
				else {
					if(thisItem.hasClass('p_method_paypal_standard')) {
						$('#onestepcheckout-place-order').html('Pay with Paypal');
					}
					else {
						$('#onestepcheckout-place-order').html('Submit My Order');
					}
					var paymentType = thisItem.attr('class');
					$('#checkout-payment-method-load #'+paymentType).attr('checked', true);
					$('#'+paymentType).click();
					
					$('.payment-methods').find('.currentTab').removeClass('currentTab');
					thisItem.addClass('currentTab');
					
					
				}
								
				
			});
		},
		
		productDetail: function() {
			$("#qty").change(function() {
				var qty = $(this).val();
				
				//$(".add-to-cart #qty").val(qty);
				// Have changed id qty to select in the selector because of issue with IE7
				// This is because there are two identical id's on the page. Need to change
				$(".add-to-cart select").val(qty);
			});
			
			
			// Cache the moreviews jquery object
			// check if there is a class active-image
			// if not assign first item to have the active-item class
			var $currentSelected,
				$moreViews = $(".product-img-box .more-views");
			function firstImage() {
				if($moreViews.find('.active-image').length == 0) {
				$currentSelected = $moreViews.find('li:first-child a');
				$currentSelected.addClass('active-image');
				}
			}
			
			firstImage();			
			// Click event to remove active-item class
			// Add class to the clicked anchor
			
			$moreViews.delegate('li a', 'click', function(){
				$currentSelected.removeClass('active-image');
				$current = $(this);
				$current.addClass('active-image');
				$currentSelected = $current;
			});
			
			$('.colorswatches-items').delegate('span', 'click', function(){
				firstImage();
			})
			
			
		},
        cartUpdate: function() {
            $('.shipping-options').change(function() {
                var url = $(this).attr('href');
                
		$('body').append('<form id="form-shipping-options-submit"></form>');
		$('#form-shipping-options-submit').append('<input type="hidden" name="estimate_method" value="' + $(this).val() + '" />');
		$('#form-shipping-options-submit').attr('method','post');
		$('#form-shipping-options-submit').attr('action',url);
		$('#form-shipping-options-submit').submit();
                
		/* location.reload sometimes load the data from the cache. 
		$.ajax({
                    type: 'POST',
                    url: url,
                    data: "estimate_method="+$(this).val(),
                    success: location.reload()
                });*/
            });
        },
        cartUpdateQty: function() {
            $('.cart-qty').change(function() {
               $('#btn-update-cart').click();
            });
        },
		
		colorBox: function() {
			$(".inline-size").colorbox({ inline:true, href:"#sizechart"});
		},
		
		messages: function() {
			 
			var messagesDiv = $("#messages_product_view");
			
			// Check if the div has children
			// if so, append the close element
			
			if(messagesDiv.children().size() > 0) {
				messagesDiv.append('<div class=\"close\"></div>');
				messagesDiv.css({'display' : 'block'});	
			}
			
			
			// create the close event using delegate
			messagesDiv.delegate(".close", "click", function(){
				messagesDiv.hide();
			});
			
		},
		
		thumbnailPrevent: function() {
			$(".more-views li a").click(function(event) {
				event.preventDefault();
			});
		},
		
		/*
		 * Homepage banner
		 */
		bannerInit: function( $banner, animFactor ){
			
			var fadeInSpeed = animFactor * 10,
				
				delayTime = animFactor * 5,
			
				$items = $banner
							.find(".item")
							.each(function(index){
								$(this).delay(index*(fadeInSpeed/4)).fadeIn(fadeInSpeed);
							}),
				
				$bannerContent = $("#banner-content"),
				
				$more = $("div.loadmore-inner").first(),
				
				opts = {
					offset: '100%'
				},

				last = 0,

				$rows;
			
			
			
			if( $bannerContent.size() && $more.size() ) {
				
				
				
				$rows = $( $bannerContent.html() );

				$more.waypoint(function(event, direction){
					
					
					
					$more.waypoint("remove");
						
					setTimeout( function () {
						
						var next = last + 1,
							$next = $rows.slice(last, next),
							childrenContent = $next.html();

						$rows = $rows.slice(next);
												
						if(childrenContent != null){
							$next.find('div').css("display","block");
							$next.hide().delay( delayTime ).appendTo($banner).fadeIn(fadeInSpeed);
						
						}
						
						if($rows.size()){
							$more.waypoint(opts);
						}
						else{
							$more.parent().delay(delayTime).fadeOut(10); // Do delay instead of straight hide to prevent scroll position bouncing
						}					
						
					}, delayTime);
				
				},opts);
			}
		},
		navHover: function(){
			var parentItem = $(".about-us > li");
			parentItem.hover(
				function(){
					$(this).children("ul").css("left","0px");
				},
				function(){
					$(this).children("ul").css("left","-99999px");
				}
			);
			
			$("li", parentItem).hover(
				function(){
					$(this).children("ul").css("left","159px");
				},
				function(){
					$(this).children("ul").css("left","-99999px");
				}
			);
			
		},
		
		footerMoreinfo: function( $footerContainer, animFactor ){
			var speed = animFactor,
				$supplement = $footerContainer.find(".supplement"),
				delayTime = animFactor * 50,
				timing = null; // Use this to delay the fade operation for a short time, to prevent blinking
		
			$footerContainer.hover(
				function () {
					if (timing !== null) {
						clearTimeout(timing);
						timing = null;
					}
					else {
						$supplement.stop(true,true).fadeIn( speed );
					}
				},
				function () {
					if (timing == null) {
						timing = setTimeout(function(){
							$supplement.stop(true,true).fadeOut( speed );
							timing = null;
						}, speed * 50); // Delays for 5000 milliseconds.
					}
				}
			);					
		},
		
		/* On Page load */
		getLoader: function() {
			
			var speed = this.animFactor * 2;
			
			return function() {
				
				var $body = $('body'), 
					$fWrap = $('.footer-wrap');
				
				if( $body.height() > $(window).height() ) {
					$body.addClass('pagelong');
				} else {
					$fWrap.fadeIn( speed );		
				}
			}
			
		},
		
		//The scrolling event
		_headerWaypoints: function( model ) {
			
			return function(event, direction) {
				
				//delete the height value that created by animate below
				model.fixHeader.css("height","").toggleClass("fix-slimheader");

				//Toggle Sticky 
				model.sticky.toggleClass("sticky", direction === "down");		
									
				//Is in slim mode
				model.isSlim = model.fixHeader.hasClass( "fix-slimheader" );		
				
				// Reset all header styles to the collapsed state
				if (model.isExpanded) {
					model.mask.css("opacity",0);
					model.searchIcon.removeClass("hover");
					if (model.isSlim) {
						model.fixHeader.css("height", "42px");
						model.extras.removeAttr("style");
						model.isExpanded = !model.isExpanded;
					}
					
				}
				
				//Stop
				event.stopPropagation();
			};
		},
		
		/* The slim header mouse enter - leave handler */
		_headerHandler: function( model, opacity, height ) {
				
			return function( event ) {
				
				if( !model.isSlim ) { return; }
				
				model.isExpanded = !model.isExpanded;
				model.searchIcon.toggleClass("hover");
				model.mask[ opacity ? 'show' : 'hide' ]()
				model.mask.stop()
					.animate({ opacity: opacity }, 2 * model.speed);
				
				model.fixHeader
					.stop()
					.animate({ height: height}, model.speed)
					.css("overflow","");
					
				opacity ? model.extras.fadeIn(model.speed) : model.extras.removeAttr("style");
				
			};
		},		
		
		/* Do stuff on window resize */
		_pageResizer: function( model ) {
			
			function multiPurposeWidth( width, type ) {
				if( width !== type.lastWidth ) {
					type.elem[ width ? 'addClass' : 'removeClass']( type.classname );
					type.lastWidth = width;
				}		
			}
			
			var arr = [ 
				{elem: model.footer, classname: 'shown', check: function( width ) { return width >= 1200; } },
				{elem: model.headerContainer, classname: 'fixed',  check: function( width ) { return width <= 1068; } }
			];
			
			var timer = 1, count = 0;;
			
			return function() {				
				var currentWidth = model.window.width();
				$.each( arr, function(i, type) {
					multiPurposeWidth( type.check( currentWidth ), type );
				});
				
				if( count < 3 ) {
					clearTimeout( timer )
				} else {
					count = 0;
				}
				count++;
				timer = setTimeout( function() {
					
					if( model.body.height() > model.window.height() ) {
						model.body.addClass('pagelong');
					} else {
						model.body.removeClass('pagelong');
					};
				}, 70 );
			}
		},
		
		/* FKA, floatHeader */
		floatingHeaderFooter: function( $headerContainer, animFactor ){
				
			var bonds = this,
				$fixHeader = $headerContainer.find(".fix-header"),
				model = {
					speed : animFactor,
					isSlim : false,
					isExpanded : false,
					fixHeader : $fixHeader,
					footer : $('.footer'),
					sticky : $headerContainer.parent(),
					extras : $fixHeader.find(".branding, .searchbar, .user-panel, .quick-access"),
					mask : $("#mask"),
					searchIcon : $("#nav LI.level-top.search-icon"),
					window : $(window),
					doc : $(document),
					body : $('body'),
					headerContainer : $headerContainer
				};

			//Handle Window Resizing
			var pageResizer = bonds._pageResizer( model );
			model.window.resize( pageResizer );
			pageResizer();
		
			//Handle the mouse in the Header
			$fixHeader.bind("mouseenter" , bonds._headerHandler( model, 0.7, '130') );
			$fixHeader.bind("mouseleave" , bonds._headerHandler( model, 0, '42') );
			
			//Handle Scrolling
			$headerContainer.waypoint( bonds._headerWaypoints( model ) , {
				offset: function() {
					var headerHeight = $(this).height();
					return -headerHeight;
				}
			});			

		},
		
		searchDrop: function(animFactor){
			// Keeping selectors dry
			var $categoryLink = $("#category-link");
			var $searchCategoryDrop = $("#search_categoryautocomplete");
			var $searchAutoComplete = $("#search_autocomplete");
			var $catField = $("#cat");
			var $catNameText = $("#category-name-text");
			var $catNameRemove = $("#category-name-remove");
			var $catNameBox = $(".category-name-box");
			var $searchCategoryDropUL = $searchCategoryDrop.find("ul");
			var $mask = $("#mask");
			var $searchItems = $("#search, #category-link, #search_mini_form button");
			var speed = animFactor;
			
			var dropListCombinedPadding = 20;
			
			$searchItems.focus(function(){
				$mask
					 .css("top","120px")
					 .css("opacity","0.7")
					 .show();
					 
			}).blur(function(){
				$mask.stop()
					 .hide();
			});
			
			
			// Anchor the width of the dropdowns to the new drop button position (last integer is combined left/right padding)
			var updateDropdownWidths = function() {
				var newWidth = $searchCategoryDropUL.width() + $catNameBox.width() + dropListCombinedPadding;
				$searchCategoryDropUL.width(newWidth);
				$searchAutoComplete.width(newWidth);
			};
			// Reset the width of the dropdowns to the original position (last integer is combined left/right padding)
			var resetDropdownWidths = function() {
				var newWidth = $searchCategoryDropUL.width() - $catNameBox.width() - dropListCombinedPadding;
				$searchCategoryDropUL.width(newWidth);
				$searchAutoComplete.width(newWidth);
			}
			
			// Event listeners
			$categoryLink.click(function(e) {
				// Prevent link following
				e.preventDefault();
				
				// If drop box is open, hide it
				if ($categoryLink.hasClass("category-drop-active")){
					$searchCategoryDrop.hide();
					$categoryLink.removeClass("category-drop-active");
				}
				
				// Show drop box
				else {
					$categoryLink.addClass("category-drop-active");
					$searchCategoryDrop.show();
				}
			 });
			 
			$searchCategoryDrop.find('a').click(function(e) {
				e.preventDefault();
				
				// Reset the existing width of the dropdown boxes
				if ($catNameBox.css("display") == "block") {
					resetDropdownWidths();
				}
				
				// Hide the drop box and set all category values
				$searchCategoryDrop.hide();
				$catField.attr('value', $(this).attr('name'));
				$catNameText.text($(this).find("span.catname").text());
				
				// Show selected category box
				$catNameBox.show();
				$categoryLink.removeClass("category-drop-active");
				
				// Anchor the width of the dropdowns to the new drop button position (last integer is combined left/right padding)
				updateDropdownWidths();
			});
			
			$catNameRemove.click(function(e){
				e.preventDefault();
				
				// Re-anchor the width of the dropdowns to the original position (last integer is combined left/right padding)
				resetDropdownWidths();
				
				// Clear all category values
				$catField.val("");
				$catNameText.text("");
				
				// Hide the name box
				$catNameBox.hide();
			});
			
			$(window).click(function(e){
				var elem = e.target;
				
				// If category drop box is visible, hide it.
				if ($searchCategoryDrop.css("display") == "block" && !$(elem).hasClass("category-link")) {
					$searchCategoryDrop.hide();
					$categoryLink.removeClass("category-drop-active");
				}
			});
		},
		accordian: function( $accordian, animFactor ){
			var speed = animFactor * 3;
			$accordian.find(".tab-content").hide();
			$accordian.find(".tab:first").addClass("active");
			$accordian.find(".tab-content:first").show();
			$accordian.find(".action").click(function(e){
				var currentItem = $(this),
					currentContent = currentItem.next().children(),
					activeItem;
					e.preventDefault();
				if ( currentItem.hasClass("active") ){
					currentItem.removeClass("active");
					currentContent.slideUp( speed );
				} else {
					activeItem = $accordian.find("dt.active");
					activeItem.removeClass("active");
					activeItem.next().children().slideUp();
					currentItem.addClass("active");
					currentContent.slideDown( speed );
				}		
				
				return false;
				
			});
			
		},
		navAccordian: function( $navAccordian, animFactor ){
			var speed = animFactor * 2;
			$navAccordian.find("ul, ol, .shop-by").hide();
			/*$navAccordian.find("li:first").addClass("active");*/
			$(".current", $navAccordian).find("ul, .shop-by, ol").show();
			$navAccordian.find(".expandable a.plus-sign").click(function(e){
				e.preventDefault();
				var currentItem = $(this).parent(),
					currentContent = currentItem.find("ul, div, ol"),
					activeItem;
				if ( currentItem.hasClass("active") ){
					//currentItem.removeClass("active");
					//currentContent.slideUp( speed );
				} else {
					activeItem = $navAccordian.find("li.active");
					activeItem.removeClass("active");
					activeItem.find("ul, div, ol").slideUp(speed);
					currentContent.slideDown( speed);
					currentItem.addClass("active");
					
				}					
				return false;
			});
			
			if ($navAccordian.find('.current').length == 0) {
				
				$current = $('.expandable:first-child', $navAccordian);
				$current.find('a.plus-sign').click();
				
			}
			
		},
		noSearchResultsFound: function(selector) {
			selector.each(function(){
				$(this).click(function(){
					return false;
				});
			});
		}
		
		
	}

	$(document).ready( Bonds.initialize );
	$(window).load( Bonds.getLoader() );
	
	
}(window.ND || {}, jQuery));


