$(document).ready(function(){

	$("#PrimaryMenu > ul > li:last-child").addClass("last");
	
	$("#TabPanels .ProductList li:nth-child(4n+4)").addClass("last");
	
	$(".product #SideProductRelated li:gt(2)").hide();
	
	//GET URL	
	var url = window.location.pathname;
	url = url.toLowerCase();
	//READ URL
	//alert(url);
	if (url == '/' || url == "/index.php") {
	//RUN CYCLE
		$('#cycle').after('<ul id="cycle-nav">').cycle({
			speed: '1000',
			timeout: '4000',
			fx: 'fade',
			pager: '#cycle-nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<li><a href="#">'+ $(slide).attr('title') +'</a></li>';
			},
			pause: true,
			paused: function(cont, opts, byHover) {
				!byHover && $('#cycle-toggle').html('Resume');
			},
			resumed: function(cont, opts, byHover) {
				!byHover && $('#cycle-toggle').html('Pause');
			}
		});
		$('#cycle-nav').after('<div id="cycle-toggle">Pause</div>');
		$('#cycle-toggle').click(function() {
			var paused = $('#cycle').is(':paused');
			$('#cycle').cycle(paused ? 'resume' : 'pause', true);
		});
		$('#cycle-toggle').click(function () {
			$(this).toggleClass('resume');
		});
		$('#cycle-nav li:last-child').addClass('last');
	};
	
	// remove the following membership conditional when ready to make the memberships avaialable
	if (url == '/copper-membership/' || url == "/gold-membership/" || url == "/silver-membership/") {
		//removes the quantity and add to cart button on the membership products
		$(".CartBtnRow, .PriceRow").addClass("visuallyhidden");	
	};
	
	$(".productAttributeLabel").remove();	
	if ($(".ProductDetailsGrid").length > 0) {
		var scope = $(".productOptionViewRadio").find("li").each(function() {
			var specific = $(this).find("span").html().split("|")
			//alert(specific)
			$(this).find("span").html("<span class='part1'>"+specific[0]+"</span><span class='part2'>"+specific[1]+"</span>")
		});
	};
	$('.productOptionViewRadio ul').before('<h3 class="options-heading"><span class="part1">Options</span> <span class="part2">Your Price</span></h3>');

	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"));
	
	// if user is signed in, show YouAreSignedIn menu, if user is signed out, show NotSignedIn menu
	if (
		$('#AreYouGuest').html() == '') {
			  $("#YouAreSignedIn").addClass('hidden');
			  $("#YouAreSignedIn").remove();
			  $("#NotSignedIn").show();
			}
			else {
			  $("#NotSignedIn").addClass('hidden');
			  $("#NotSignedIn").remove();
			  $("#YouAreSignedIn").show();
			}


	/*
		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');
		}
		});

});
