$(document).ready(function(){
	
//bcNav

	$('#SideCategoryList').bcNav({
		classify: true,
		replaceheader: false,
		inserttree: false
	});

	$("#PrimaryMenu > ul > li:last-child").addClass("last");
	//$(".SubCategoryListGrid > ul > li:last-child").addClass("last");

	$("#cycle").cycle({
		fx: "fade",
		pager:  '#cycle-nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#cycle-nav li:eq(' + (idx) + ') a';
        }
	});

	function textReplacement(input) {
		var originalvalue = input.val();
		input.focus(function() {
			if($.trim(input.val()) == originalvalue){ input.val(""); }
		});
		input.blur(function() {
			if($.trim(input.val()) == ""){ input.val(originalvalue); }
		});
	}

	textReplacement($("#search_query"));
	textReplacement($("#nl_first_name"));
	textReplacement($("#nl_email"));
	
	// REWRITE THE OUTPUT OF THE "(X ITEMS)" FIELD TO MATCH THEME
	var cartValue = $("#crt").html();
	var cartDigit;
	
	cartValue = jQuery.trim(cartValue); /Trim whitespace for IE/
	switch (cartValue)
	{
	case "":
	$("#crt").html("0");
	number = 0;
	break;
	case "(1 item)":
	$("#crt").html("1");
	number = 1 ;
	break;
	default:
	//cartDigit = 3;
	
	
	if(cartValue != ""){
	splitup=cartValue.split(" ");
	number = splitup[0].replace("(", "");
	$("#crt").html(number);
	}
	break;
	}

//	jCarouselLite example -- you will need to add a <div class="ProductListContainer"> around the <ul>
//	in the HomeFeaturedProducts Panel

	$("#HomeFeaturedProducts .ProductListContainer").jCarouselLite({
        btnNext: "#featured-next",
        btnPrev: "#featured-prev",
	      visible: 4,
	 	  scroll: 4,
		  speed: 800
   });
	
//Sticky Sidebar
//	$('#Wrapper').waypoint(function(event, direction) {
		
//	}).find('#product-side-box').waypoint(function(event, direction) {
//		$(this).toggleClass('sticky', direction === "down");
//		event.stopPropagation();
//	});
	
//Truncate Grid View Titles
	
	$(".ProductList .ProductDetails a").truncate( 55 );
	
//Cart Total
	
	var crtnumber =  ($("#crt-price strong").html())
	if ($("#crt-price").html() == "") {
		$("#crt-price").html("$0.00")
	}
	else {$("#crt-price").html(crtnumber)}
	
	$('a[href*="/categories/"]').each(function(){this.href +='?sort=priceasc'});
	
	$("a.fancybox").fancybox();
	
	$("a.fancyvideo").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 412,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

});
