$j(function () {
	$j(document).ready(function () {

		// submenus dispay all by default, correcting this...
		$j(".category-list li.parent ul.level0").hide(); // hide all submenus
		
		saleitems = $j(".level0 a span:contains('Sale')").parent();
		saleitems.addClass("red");
		saleitems.parent().addClass("redp");
		
		$j("h1:contains('Sale')").addClass("red");
		if ($j(".breadcrumbs li a:contains('Sale')").size() > 0) {
			$j(".page-title h1").addClass("red");
		}
		
		
		
		$j(".category-list li.parent").each(function (i) { // show submenu for active parent
			if($j(this).hasClass("active")) {
				ff = $j.trim($j(this).find("a span").first().text().toUpperCase());
				if (ff  != "FAVORITES ON FIGURE") {
					$j(this).find("ul.level0").show(); // not for ff
				}
			}
		});
		
		// add the "View all" subcategory for only the shop by category section
		$j(".shopcat li.parent").each(function (i) {
			if($j(this).hasClass("active")) {
				var href = $j(this).find(" > a").attr("href");				
				if ($j(this).find("li.active").size() == 0) { // sub category not active						
					var li_html = "<li class='level1 active'><a href='" + href + "'><span> Viewing All</span></a></li>";
				}
				else {
					var li_html = "<li class='level1'><a href='" + href + "'><span> View All</span></a></li>";					
				}
				$j(this).find("ul.level0").prepend(li_html);
			}
		});
		
		/*	if ($j(".shopcat li.level0").hasClass("active parent"))
			{
				var href = $j(".category-list li.level0 > a").attr("href");
				// set up viewing all clone
				var li_html = "<li class='level1 active'><a href='" + href + "'><span> Viewing All</span></a></li>";
				$j("ul.level0", this).prepend(li_html);
				$j("ul.level0", this).show();
			} */
//		}
		
		var nav = $j("#nav-second");
		nav.find("li").each(function() {
			if ($j(this).find("ul").length > 0) {
					
					//$("<span>").text("^").appendTo($(this).children(":first"));
					//show subnav on hover
					$j(this).mouseenter(function() {
					$j("ul", this).addClass("shown-sub");
					$j(this).find("ul").stop(true, true).show();
					});
					//hide submenus on exit
					$j(this).mouseleave(function() {
					$j("ul", this).removeClass("shown-sub");	
					$j(this).find("ul").stop(true, true).hide();
					});
			} 
		});
		
		var jump=function(e)
		{
		       //prevent the "normal" behaviour which would be a "hard" jump
		       e.preventDefault();
		       //Get the target
		       var target = $j(this).attr("href");
		       //perform animated scrolling
		       $j('html,body').animate(
		       {
		               //get top-position of target-element and set it as scroll target
		               scrollTop: $j(target).offset().top
		       //scrolldelay: 2 seconds
		       }, 800,function()
		       {
		               //attach the hash (#jumptarget) to the pageurl
		               location.hash = target;
		       });

		}
		
		 $j('.back-to-top a[href*=#]').bind("click", jump);

	});
});
