$(document).ready(function(){

	$(".various").fancybox({
		width	: 560,
		height	: 315
		
	});

	$("#ProductReviews > a > img").replaceWith("write a review");
	$("#ProductReviews > a").addClass("button");

	$("#PrimaryMenu > ul > li:last-child").addClass("last");
	
	// 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 == '/') {
	// //RUN CYCLE
		// $("#cycle").cycle({
			// fx: "fade"
		// });
	// };
	
	//loads only if the cycle selector exists
	if ($("#cycle").length > 0){	
		$("#cycle").cycle({
			fx: 'fade',
			timeout:7500,
			speed:300,
			pager:'#slideNav'
		});
	};

	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"));	

//	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: 5,
//	 	  scroll: 5,
//		  speed: 800
//   });


	/*
		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.pathname;
		$('#PrimaryMenu a').each(function () {
		if (loc_href == $(this).attr('href')) {
			$(this).addClass('activePageLink');
		}
		});*/
	
	
	/* -n- Classic Category List
	var c = $('#SideCategoryList .SideCategoryListClassic > ul > li').clone();
	if (c.length > 0) {
		productLi = $('#PrimaryMenu li.products');
		productLi.addClass('hasSubmenu');
		productLi.append('<ul>');
		productLi.children('ul').append(c);
		$('.home #SideCategoryList').remove();
	}*/
	
	var c = $('#SideCategoryList .SideCategoryListFlyout > ul > li').clone();
	if (c.length > 0) {
		c.children('ul').remove();
		productLi = $('#PrimaryMenu li.products');
		productLi.addClass('HasSubMenu');
		productLi.append('<ul>');
		productLi.children('ul').append(c);
		$('.home #SideCategoryList').remove();
	}
	
	// -n- every 3rd product li of .CustProdList has no right margin and new line
	$('#LayoutColumn2 .ProductList.CustProdList li:nth-child(3n+4)').addClass('noRightMargin newline');
	
	// -n- Remove all but 3 of the products from SideProductRelated
	var relatedProducts = $('#SideProductRelated .ProductList li');
	if (relatedProducts.length > 3) {
		var n = [];
		for (a=0; a<3; a++) {
			n.push("<li>" + $(relatedProducts[a]).html() + "</li>");
		}
		$('#SideProductRelated .ProductList').html(n.join(''));
	}
	
	
	
	
});
