jQuery(document).ready (
   function(){
		j = jQuery.noConflict();
		
		/* Header */
		
		//Changes header sign-in to Sign In and  Store locator url incorrect(unable to do with replacement widget)
		if (j('.signInMenu').length > 0) {
			//unable to check text due to excessive spacing around the text
			j('.signInMenu .signIn a').text('Sign In');
		}
		
		/*Browse*/
		
		//Checks if # per page dropdown exists, if so changes pagination width
		if (j("body.browse .resultSizeForm .changeSearchSizeForm").length <= 0) {
			j(".searchOptions .searchPagination").css("width", "490px");
		}
		//Leftnav - takes out "Shop"
		if (j("body.browse ul.browseLadder").length > 0) {
			j("ul.browseLadder:first").children("li").children("a").remove();
			var top = j("ul.browseLadder:first").children("li");
			if (j(".browseLadder .current").length > 0)
				j(".browseLadder .current").removeClass("current");
			//Leftnav - Puts current main category at top
			j(top).prepend(j(".browseLadder:first").children().children("ul").children().children("ul").prev());
			j(top).children(":first").addClass("current");
			//Leftnav - Pulls subcategory data, inserts it after main category
			var childrenlist = j("ul.browseLadder:first").children().children("ul").children().children("ul");
			j(childrenlist).insertAfter(j(top).children(":first"));
			//Leftnav - hides rest of links
			j(top).children(".browseLadder").hide();
		}
		//Wraps browse page images with set height (also for search page)
		if (j("body.browse .productImage").length > 0 || j("body.search .productImage").length > 0)
			j(".productImage").parent().wrap("<div class='productImageWrapper'></div>");
		//Removes 'most popular' dropdown option
		if (j('body.browse #searchRank').length > 0) {
			j('#searchRank option').each(function(){
				if (j(this).text() == 'Most Popular')
					j(this).remove();
			});
		}
		
		/* Search */
		
		//Hides Brand header and brand link list from Leftnav
		if (j("body.search .browseRefinements").length > 0) {
			if (j("body.search .browseRefinements h3:contains('Brand')").length > 0) {
				j("body.search .browseRefinements h3:contains('Brand')").hide().next("ul.linkList").hide();
			}
		}
			
		/* Product Detail */
		
		if (j('body.detail ul.productInfo').length > 0 && j('body.detail div.productInformation h3').length > 0) {
			j('ul.productInfo').before(j('div.productInformation h3'));
		}	
		if (j('ul.productInfo em').length > 0) {
			i = 0;
			j('ul.productInfo em').parent('li').each(function(i){
				j(this).attr('id', 'proddetails' + i);
				if (j('ul.productInfo em').eq(i).html() == 'Release date:' || j('ul.productInfo em').eq(i).html() == 'Manufactured by:' || j('ul.productInfo em').eq(i).html() == 'Merchant SKU:') {
					j(this).attr('class', 'hide');
				}
				else {
					j(this).attr('class', 'show');
				}
				i = i + 1;
			});
		}	
		//Fix Why we love it/ What else you need to know floating issue
		if (j("body.detail .productInformation").length > 0) {
			if (j("#BenefitWhyWeLoveItHeader").length > 0 && j("#BenefitWhyYouNeedItHeader").length > 0) {
				j("#BenefitWhyWeLoveItHeader").wrap("<div></div>");
				j("#BenefitWhyYouNeedItHeader").wrap("<div></div>");
			}
			//Fix IE spacing above tips
			j("body.detail .productInformation").each(function() {
				if (j.trim(j(this).text()) == '')
					j(this).remove();
			});
		}
		//Remove spacing below tips header
		if (j("body.detail #left-6 .groups").length > 0) {
			if (j("#left-6 .groups h3").length > 0)
				j("#left-6 .groups h3").remove();
			if (j("#left-6 .groups h4").length > 0)
				j("#left-6 .groups h4").remove();
			if (j("#left-6 .entries").length < 1)
				j("#left-5").hide();
		}
		if (j("body.detail #left-8 .groups").length > 0) {
			j("body.detail #left-7").insertBefore(j("body.detail #left-5"));
			j("body.detail #left-8").insertAfter(j("body.detail #left-7"));
			if (j("#left-8 .entries").length < 1)
				j("#left-7").hide();
		}
		
		//Fix cart quantity and gift wrap alignment in IE
		if (j("#center-4 .productList dl.attributeList").length > 0) {
			j("#center-4 .productList dl.attributeList").each(function(){
				if (jQuery(this).children("dt.quantity").length > 0) {
					var quantity = j(this).children("dt.quantity");
					var amount = j(this).children("dd.quantity").children("span.quantity");
					j(quantity).append(j(amount));
					var gift = j(this).children("dt.giftWrap");
					var giftul = j(this).children("dd.giftWrap").children("ul");
					j(gift).append(j(giftul));
					var giftanswer = j(this).children("dd.giftWrap");
					j(gift).append("<span style='margin-left:6px;'>" + j.trim(j(giftanswer).text()) + "</span>");
					j(giftanswer).html("").append(j(giftul));
				}
			});
		}
		
		//popup for promotions in opl
		if (j("body#pageId1100 .promotionalCodes p.formHelp a").length > 0) {
			var href= j("body#pageId1100 .promotionalCodes p.formHelp a").attr("href");
			j("body#pageId1100 .promotionalCodes p.formHelp a").click(function() {
			  window.open(href, 'promotions', 'width=900, height=500, resizable=1, scrollbars=1');
			  return false;
			});
		}
		
		/* newsletter */
		j('.homePromoSignup form.signup').submit(function(){
		var SignupEmail='http://pages.newsletter.benefitcosmetics.com/page.aspx?QS=38dfbe491fab00eaf38a8895aa75c2b9927e0545c02ade3c7c37104498c7dbf2&emailaddr='+j('.newsSignupEmail').val();
		var winH = j(window).height()/2-250;
		var winWidth = j(window).width()/2-280;
		window.open(SignupEmail,'window_name','width=710, height=680, left='+winWidth+',top='+winH+', scrollbars=yes, resizable=no');
		});
		j('.newsSignupEmail').focus(function() {
		  if (j(this).val() == 'Enter email address')
		  	j(this).val('');
		});
		j('.newsSignupEmail').blur(function() {
		  if (j(this).val() == '')
		  	j(this).val('Enter email address');
		});
		
		
		/*if (j("body.detail").length > 0)
			document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " + "SRC=\"http://s7.addthis.com/js/250/addthis_widget.js#username=benefitcosmetics\"></SCR" + "IPT>");*/
		
	}
);

