$(document).ready(function(){

	$("#PrimaryMenu > ul > li:last-child").addClass("last");
	$(".SubCategoryListGrid ul li.RowDivider").remove();
	$(".SubCategoryListGrid ul li:last-child").remove();
	
	$('#SideCategoryList').bcNav({
		inserttree: false,
		classify: true
	});
	$('#SideCategoryList ul').not('ul.trunk').find('ul').hide();
	
	/*
		This is a short and simple script that will create an Active class for your custom pages menu links(if you have to use stuff like Category pages for your main navigation).
		Keep in mind that this will also work for any other list (like custom Side Vendors, Side Categories, or Side Brands) by just changing the ID Selector. **Credit to Krystin Rice
	*/
	var loc_href = window.location;
		$('#PrimaryMenu a').each(function () {
		var l = document.createElement('a');
		l.href = $(this).attr('href');
		
		if ((loc_href.pathname + loc_href.hash) == (l.pathname + l.hash)) {
			$(this).parent("li").addClass('ActivePage');
		}
	});
	
	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"));
	
	// -n- Guest is logged in Script
	if ($.trim($('#AreYouGuest').html())!="") {
		$('#loginButton').hide();
		$('#logoutButton').show();		
	}
	
	// -n- Cart Items Script
	var cartItems = $('#TopMenu .CartLink a span');
	var numOfitems = (cartItems.text().length<3) ? "0" : cartItems.text().match(/[0-9]/g).join("");
	cartItems.html("("+numOfitems+")").css('visibility','visible');
	
	
	// // loads the cycle or whatever on specific url in this case the home page
	// //GET URL	
	// var url = window.location.pathname;
	// url = url.toLowerCase();
	// //READ URL
	// // uncomment alert to see what the url is in browser if needed
	// //alert(url);
	// if (url == '/' || url == "/index.php") {
	// //RUN CYCLE
		// $("#cycle").cycle({
			// fx: "fade"
		// });
	// };
	
	// loads only if the cycle selector exists
	if ($("#cycle").length > 0){	
		$("#cycle").cycle({
			fx: "fade"
		});
	};


	//	jCarouselLite example -- you will need to add a <div class="ProductListContainer"> around the <ul>
	//	in the HomeFeaturedProducts Panel

	if ($('#SideProductRelated .ProductListContainer').length>0) {
		$("#SideProductRelated .ProductListContainer").jCarouselLite({
			  btnNext: "#related-next",
			  btnPrev: "#related-prev",
			  visible: 4,
			  scroll: 1,
			  speed: 100
		});	
		if ($('#SideProductRelated li').length < 5) {
			$('#SideProductRelated').remove();
		}
	}
	
	if ($('#HomeFeaturedProducts .ProductListContainer').length>0) {
		$("#HomeFeaturedProducts .ProductListContainer").jCarouselLite({
			  btnNext: "#related-next",
			  btnPrev: "#related-prev",
			  visible: 3,
			  scroll: 1,
			  speed: 100
		});	
		if ($('#SideProductRelated li').length < 5) {
			$('#SideProductRelated').remove();
		}
	}
	
});
