window.onload = function () {
$('#pageFilters-noSub, #pageFilters-inner').attr("id","pageFilters");
$('#clubLocator1, #clubLocator2, #clubLocator3').attr("id","clubLocator");
$('#clubLocatorN1, #clubLocatorN2, #clubLocatorN3').attr("id","clubLocatorN");
$('#clubLocatorLink1, #clubLocatorLink2, #clubLocatorLink3').attr("id","clubLocatorLink");
$('#clubLocatorLinkN1, #clubLocatorLinkN2, #clubLocatorLinkN3').attr("id","clubLocatorLinkN");

$("#clubLocator, #clubLocatorN").hide(); 

$("#clubLocatorLink").mouseover(function(){  
     $("#clubLocator").stop(true, true).delay(1000).show(0);  
});  

$("#clubLocatorLink").mouseout(function(){  
     $("#clubLocator").stop(true, true).delay(1000).hide(0);                                               
});  

$("#clubLocator").mouseover(function(){  
     $("#clubLocator").stop(true, true).show(0);  
  	 try { document.execCommand("BackgroundImageCache", false, true); }
catch(err) {}

});  

$("#clubLocator").mouseout(function(){  
     $("#clubLocator").stop(true, true).delay(2000).hide(0);  
});

//END Club Locator 

//START Club LocatorN


$("#clubLocatorLinkN").mouseover(function(){  
     $("#clubLocatorN").stop(true, true).delay(1000).show(0);  
});  

$("#clubLocatorLinkN").mouseout(function(){  
     $("#clubLocatorN").stop(true, true).delay(1000).hide(0);                                               
});  

$("#clubLocatorN").mouseover(function(){  
     $("#clubLocatorN").stop(true, true).show(0);  
  	 try { document.execCommand("BackgroundImageCache", false, true); }
catch(err) {}

});  

$("#clubLocatorN").mouseout(function(){  
     $("#clubLocatorN").stop(true, true).delay(2000).hide(0);  
});

$('#clubLocatorLinkN').parents('span').css({"background" : "none", "position" : "relative"});
$('#clubLocatorLinkN').css({"left" : "-5px"});

$(".nav").children().each(function (index) {
						   
			// Get count of columns inside of the dropdowns in order to set the width of the dropdown menu.
			
			var y = $(this).children("a").siblings().children("li").children(".dropDown_new").children(".col").size();
			
			var posL = $(this).position().left;
			 

			// Also determines the placement of the dropdowns depending on the number of columns 
			
			if (y == 3) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","530px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","400px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","190px");
				
			}
	if (posL == 0) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
			
	  if (posL >= 2 && posL < 100) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-60px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
	  
	  if (posL > 101 && posL < 200) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	   if (posL > 201 && posL < 300) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-180px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	  if (posL > 301 && posL < 400) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-260px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 401 && posL < 500) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-340px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-250px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 501 && posL < 600) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-440px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-300px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
 });     
	   
$(".nav li").unbind().hover(function(){
		$navElem = $(this);							 
		$.timeout('Sams.Menu', function(){
			$(".nav li ul").hide();
			$navElem.find('ul').show() 
		}, 400);
	},function(e){
		$navElem = $(this);
		$.timeout('Sams.Menu', function(){
			$(".nav li ul").hide();							
		}, 300)
	});
//end navigation 1

$('.nav li ul').unbind().mouseover(function(){
	$.timeout('Sams.Menu');
}).mouseout(function(){
	$navElem = $(this);
	$.timeout('Sams.Menu', function(){
		$(".nav li ul").hide();							
	}, 300)
});


$(".nav2").children().each(function (index) {
								   
			// Get count of columns inside of the dropdowns in order to set the width of the dropdown menu.
			
			var y = $(this).children("a").siblings().children("li").children(".dropDown_new").children(".col").size();
			
			var posL = $(this).position().left;
			 

			// Also determines the placement of the dropdowns depending on the number of columns 
			
			if (y == 3) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","530px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","400px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","190px");
				
			}
	if (posL == 0) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
			
	  if (posL >= 2 && posL < 100) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-60px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
	  
	  if (posL > 101 && posL < 200) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	   if (posL > 201 && posL < 300) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-180px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	  if (posL > 301 && posL < 400) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-260px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 401 && posL < 500) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-340px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-250px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 501 && posL < 600) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-440px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-300px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
});

$(".nav2 li").unbind().hover(function(){
		$navElem = $(this);							 
		$.timeout('Sams.Menu', function(){
			$(".nav2 li ul").hide();
			$navElem.find('ul').show() 
		}, 400);
	},function(e){
		$navElem = $(this);
		$.timeout('Sams.Menu', function(){
			$('.nav2 li ul').hide();							
		}, 300)
	});
//end navigation 1

$('.nav2 li ul').unbind().mouseover(function(){
	$.timeout('Sams.Menu');
}).mouseout(function(){
	$navElem = $(this);
	$.timeout('Sams.Menu', function(){
		$('.nav2 li ul').hide();							
	}, 300)
});

$(".nav3").children().each(function (index) {
								   
			// Get count of columns inside of the dropdowns in order to set the width of the dropdown menu.
			
			var y = $(this).children("a").siblings().children("li").children(".dropDown_new").children(".col").size();
			
			var posL = $(this).position().left;
			 

			// Also determines the placement of the dropdowns depending on the number of columns 
			
			if (y == 3) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","530px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","400px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings().children("li").children(".dropDown_new").css("width","190px");
				
			}
	if (posL == 0) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
			
	  if (posL >= 2 && posL < 100) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-60px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","0px");
				
			}
        
      } 
	  
	  if (posL > 101 && posL < 200) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-100px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	   if (posL > 201 && posL < 300) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-180px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      } 
	  if (posL > 301 && posL < 400) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-260px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-150px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 401 && posL < 500) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-340px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-250px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
	  if (posL > 501 && posL < 600) {
		  
			if (y == 3) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-440px");
				
			}
			if (y == 2) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-300px");
				
			}
			if (y == 1) {
				$(this).children("a").siblings("ul").children("li").children(".dropDown_new").css("left","-50px");
				
			}
        
      }
   });   
	   
$(".nav3 li").unbind().hover(function(){
		$navElem = $(this);							 
		$.timeout('Sams.Menu', function(){
			$(".nav3 li ul").hide();
			$navElem.find('ul').show() 
		}, 400);
	},function(e){
		$navElem = $(this);
		$.timeout('Sams.Menu', function(){
			$('.nav3 li ul').hide();							
		}, 300)
	});
//end navigation 1

$('.nav3 li ul').unbind().mouseover(function(){
	$.timeout('Sams.Menu');
}).mouseout(function(){
	$navElem = $(this);
	$.timeout('Sams.Menu', function(){
		$('.nav3 li ul').hide();							
	}, 300)
});

$(".btnAvailable").parent("a").each(function(i) {
		$(this).bind("click", function() {
			$(".pop-cart").hide();
			$("#product_"+(i+1)).show();
			
			return false;
		});
	});

$(".pop-cart a.fright").each(function(i) {
		$(this).bind("click", function() {
			$("#product_"+(i+1)).hide();
			
			return false;
		});
	});

// Membership Auto-Renewal Pop-up

$(".pop-cart").hide();
$("#renewPop").hide();
$("#changeRenew").click(function () {
	$("#renewPop").show();
return false;
});
$("#autoClose").click(function () {
	$("#renewPop").hide();
return false;
});
// Membership Auto-Renewal Pop-up Ends

//Start PASupport:: 25th May, 2011 :: 7647 :: Misalignment in the Availability pop up 
// -------------Availability Pop-up
/*$("#available_1").mouseover(function() {
		$("#product_1").show();	 	
	});
	$("#product_1").mouseover(function() {
		$("#product_1").show();	 	
	});
	$("#product_1").mouseout(function() {
		$("#product_1").hide();	 	
	});*/
// -------------Availability Pop-up Ends
//End PASupport:: 25th May, 2011 :: 7647 :: misalignment in the Availability pop up 	
	
// ---------------Product Checkbox and Sorting
	$("#selectproCheck").click(function() {
		var checked_status = this.checked;
		$("input[name$=proCheck]").each(function(i)
		{
			if (this.checked = checked_status) {
				$("#iceproduct_"+(i)).removeClass("iceberg-product");
				$("#iceproduct_"+(i)).addClass("iceberg-productSelected");
				$("#selectAllTop").text("Unselect All");
				$("#selectAllBottom").text("Unselect All");
			} else {
				$("#iceproduct_"+(i)).removeClass("iceberg-productSelected");
				$("#iceproduct_"+(i)).addClass("iceberg-product");
				$("#selectAllTop").text("Select All");
				$("#selectAllBottom").text("Select All");
			}
		});
	});
	
	$("#selectproCheck2").click(function() {
		var checked_status = this.checked;
		$("input[name$=proCheck]").each(function(i)
		{
			if (this.checked = checked_status) {
				$("#iceproduct_"+(i)).removeClass("iceberg-product");
				$("#iceproduct_"+(i)).addClass("iceberg-productSelected");
				$("#selectAllTop").text("Unselect All");
				$("#selectAllBottom").text("Unselect All");
			} else {
				$("#iceproduct_"+(i)).removeClass("iceberg-productSelected");
				$("#iceproduct_"+(i)).addClass("iceberg-product");
				$("#selectAllTop").text("Select All");
				$("#selectAllBottom").text("Select All");
			}
		});
	});
	
	$("input[name$=proCheck]").each(function(i) {
			$(this).bind("click", function () {
			var checked_status = this.checked;								 
			if (this.checked = checked_status) {
				$("#iceproduct_"+(i-1)).removeClass("iceberg-product");
				$("#iceproduct_"+(i-1)).addClass("iceberg-productSelected");
			} else {
				$("#iceproduct_"+(i-1)).removeClass("iceberg-productSelected");
				$("#iceproduct_"+(i-1)).addClass("iceberg-product");
			}
		});
			});
	
// --------------Product Checkbox and Sorting Ends


// ---------- Membership Details
	$("#indiLink").click(function() {
		$("#lgBizLink").removeClass("lgBiz-active");
		$("#lgBizLink").addClass("lgBiz");
		$("#smallBizLink").removeClass("smallBiz-active");
		$("#smallBizLink").addClass("smallBiz");
		$(this).removeClass("indiMem");
		$(this).addClass("indiMem-active");
		$("#indiHouse").fadeIn();
		$("#smallCorp").hide();
		$("#largeCorp").hide();
								  
								  });
	$("#smallBizLink").click(function() {
		$("#indiLink").removeClass("indiMem-active");
		$("#indiLink").addClass("indiMem");
		$("#lgBizLink").removeClass("lgBiz-active");
		$("#lgBizLink").addClass("lgBiz");
		$(this).removeClass("smallBiz");
		$(this).addClass("smallBiz-active");
		$("#indiHouse").hide();
		$("#smallCorp").fadeIn();
		$("#largeCorp").hide();
								  
								  });
	$("#lgBizLink").click(function() {
		$("#indiLink").removeClass("indiMem-active");
		$("#indiLink").addClass("indiMem");
		$("#smallBizLink").removeClass("smallBiz-active");
		$("#smallBizLink").addClass("smallBiz");
		$(this).removeClass("lgBiz");
		$(this).addClass("lgBiz-active");
		$("#indiHouse").hide();
		$("#smallCorp").hide();
		$("#largeCorp").fadeIn();
								  
								  });
	
// ---------- Membership Details Ends
	
	
// ---------Shopping Tools Dropdown
$("#shopToolsLink").click(function () {
       $("#searchDrop").css({ visibility:"hidden" });
	   $("#shopDrop").show();
	  $("#shopDrop").bgiframe({ opacity: false });
	  $("#sub-nav-oneTier ul").css({ float:"none" });

    });
	
	$("#shopDrop").click(function () {
	 $("#searchDrop").css({ visibility:"visible" });
     $("#shopDrop").hide();
	 $("#sub-nav-oneTier ul").css({ float:"left" });
	
    });
// ---------Shopping Tools Dropdown Ends

// --------- Allows keyed entries
$("#monthsdropdown").keyup(function(event){
		if (event.keyCode == 49) {
			$("#jan").attr("selected","selected");
		}
		if (event.keyCode == 50) {
			$("#feb").attr("selected","selected");
		}
		if (event.keyCode == 51) {
			$("#mar").attr("selected","selected");
		}
		if (event.keyCode == 52) {
			$("#apr").attr("selected","selected");
		}
		if (event.keyCode == 53) {
			$("#may").attr("selected","selected");
		}
		if (event.keyCode == 54) {
			$("#jun").attr("selected","selected");
		}
		if (event.keyCode == 55) {
			$("#jul").attr("selected","selected");
		}
		if (event.keyCode == 56) {
			$("#aug").attr("selected","selected");
		}
		if (event.keyCode == 57) {
			$("#sept").attr("selected","selected");
		}
		
	});
// --------- Allows keyed entries Ends
}

function showhide(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none"){
obj.style.display = "";
} else {
obj.style.display = "none";
}
}
}
//-- R2 Taxware s1sivap START
function hidePopUp(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		if (obj != null) {
			obj.style.display = "none";
		}
	}
}
//-- R2 Taxware s1sivap END
(function($){
	var reg = {};
	$.timeout = function(key, fn, time, args){
		var args = args || [];
		if(reg[key] != undefined){
			clearTimeout(reg[key]);
		}
		
		if(arguments.length > 1){
			var fnWrapper = function(){ fn.apply(this, args); };
			reg[key] = setTimeout(fnWrapper, time);
		}
	}
	
})(jQuery)

var $=jQuery.noConflict();

/* begin 11.8 UX updates: Searchbar and Filters */

(function($){
	$('.searchBarNew').ready(function(){
		$('form[name="searchForm"]').submit(function(){
			string=$(this).find('#searchBar').val();
			if(string==='Search' || string===''){
				return false;
			}else{
				return true;
			}
			return false;
		});
		$('#searchSelect').hide();
		if($('#searchBar').val()=='Search'){$('#searchBar').addClass('out');}
		$('#searchBar').focus(function(){if($(this).val()=='Search'){$(this).removeClass('out').val('');}});
		$('#searchBar').blur(function(){if($(this).val()==''){$(this).addClass('out').val('Search');}});
		$('#searchBar').after('<div id="searchSelectJSWrapper" tabindex="100"><span id="searchSelectJS">All SamsClub<span class="arrow"></span></span><ul></ul></div>');
		$('.searchBarNew').children(':not(":last")').wrapAll('<span id="searchBarJS">');
		$('#searchSelect>option').each(function(){$('#searchSelectJSWrapper>ul').append('<li><a href="#">'+$(this).text()+'</a></li>');});
		$('#searchSelectJSWrapper>ul').hide();
		$('#searchSelectJS').click(function(){$(this).closest('#searchBarJS').toggleClass('dropdown');$(this).siblings('ul').toggle(200);return false;});
		var searchHoverTimeout;
		$('#searchSelectJSWrapper').hover(function(){clearTimeout(searchHoverTimeout);},function(){searchHoverTimeout=setTimeout(function(){$('#searchBarJS').removeClass('dropdown');$('#searchSelectJS').siblings('ul').hide(200);},500);});
		
		$('#searchSelectJSWrapper a').click(function(){
			//console.log($(this).text());
			var text=$(this).text();
			text=(text.length>15) ? $.trim(text.substr(0,12))+'...' : text;
			$(this).closest('#searchSelectJSWrapper').children('#searchSelectJS').html(text+'<span class="arrow"></span>');
			$(this).addClass('current').parent().siblings().children().removeClass('current');
			$('#searchSelect').children('option:contains("'+$(this).text()+'")').attr('selected',true);
			$('#searchBarJS').removeClass('dropdown');
			$('#searchSelectJS').siblings('ul').hide(200);
			return false;
		});
		selectedO=$('#searchSelect').children('option:selected');
		selected=selectedO.index('#searchSelect option');
		$('#searchSelectJSWrapper>ul>li').eq(selected).children('a').addClass('current');
		var text=selectedO.text();
		text=(text.length>15) ? $.trim(text.substr(0,12))+'...' : text;
		$('#searchSelectJSWrapper').children('#searchSelectJS').html(text+'<span class="arrow"></span>');
		var barPad=$('#searchSelectJS').outerWidth()+5,barWidth=295-barPad;
		$('#searchBar').css({'width':barWidth,'padding-right':barPad});
	});
	$('#clubChangeAlert>a.close').live('click',function(){//Close Button
		$('#clubChangeAlert').animate({'opacity':'0','height':'0px'},400,function(){$(this).css('display','none');});
		return false;
	});
})(jQuery)

/* end 11.8 UX updates: Searchbar and Filters */
//Start PASupport: 17Aug2011 (Site Redesign Update)
function trackEvent(tag){
	page=document.location.href;
	title=$('.pageTitle').eq(0).text();
	if(title==''){title=$('title').text();}
	title=title.replace(' ','');
	if(page.search(/\?/)>=0){page+='&iid='+title+'|'+tag;}else{page+='?iid='+title+'|'+tag;}
	$.get(page);
}


function openPopupWindow(content,content2){
	if(content==undefined){
		//popup is empty, aborting...
		return false;
	}
	$('body').append('<div class="popupOverlay"></div><div class="popupWindow"><div class="popupCornerTL"></div><div class="popupCornerTop"></div><div class="popupCornerLeft"></div><div class="popupCornerBottom"></div><div class="popupCornerRight"></div><div class="popupCornerBL"></div><div class="popupCornerBR"></div><a href="#" class="popupClose">Close Popup Window</a><div class="popupLogo"></div><div class="popupContent"><div class="popupContentInner"></div></div></div>');
	$('.popupOverlay').add('.popupWindow').fadeOut(0);
	$('.popupOverlay').fadeTo(400,0.6);
	$('.popupWindow').fadeIn(400);
	
	if(typeof(content)=='string' && content.match('^http[s]?://')){
		// url - do xhr
		if(document.location.href.match(/https:\/\//)){
			protocol='https://';
		}else{
			protocol='http://';
		}
		
		$('.popupContentInner').append('<img src="'+protocol+'www.samsclub.com/sams/images/cartAjax_loading.gif" style="display:block;margin:auto;" />');
		
		pageName=content.replace(/\&|\?iid=[\w\W]+\&?/,'').replace(/(https?:\/\/)?[A-Za-z0-9\/ \_\-\%\#\@\+\.\?]*(pageName\=|\/)/,'');
		trackEvent(pageName+'|popup|page');
				
		if(content.match('https')){
			$('.popupContent').after('<iframe class="popupContent" src="'+content+'" id="secure_popup_content" style="width:740px;border:0;padding:0;margin:0 -10px;overflow:auto;overflow-x:hidden;overflow-y:auto;"></iframe>');
			$('div.popupContent').remove();
			//checkPopupHeight();
			$('iframe.popupContent').load(function(){
				checkPopupHeight();
			});
		}else{
			$.get(content, function(data){
				html = data.replace(/<head>[\w\W]+<\/head>/gim,'').replace(/<\!DOCTYPE[\w\W]+\><html>/gim,'').replace(/(<body>|<\/body>|<\/html>)/gim,'')
				.replace(/document.write/gi,'//document.write')
				.replace(/<script[ A-Za-z0-9\'\"\-\_\=\+\[\]\{\}\;\:\.\,\?\\!\@\#\$\%\^\&\*\(\)\/\\]*src=('|")[ A-Za-z0-9\'\"\-\_\=\+\[\]\{\}\;\:\.\,\?\\!\@\#\$\%\^\&\*\(\)\/\\]*(jquery)[ A-Za-z0-9\'\"\-\_\=\+\[\]\{\}\;\:\.\,\?\\!\@\#\$\%\^\&\*\(\)]*\.js('|")[ A-Za-z0-9\'\"\-\_\=\+\[\]\{\}\;\:\.\,\?\\!\@\#\$\%\^\&\*\(\)\/\\]*><\/script>/gi,'')
				.replace(/<noscript[ \w\W\n\r]*<\/noscript>/gim,'')
				.replace(/window\.close\(\)/gim,'$(\'.popupOverlay\').click();return false;');
							
				if(html=='' || html==undefined){$('.popupContent').html('<h2>Error Opening</h2><p>Please try again later.</p>');return false;}//Content returned is empty, give error feedback
				
				$('.popupContent').removeClass('loading').children('.popupContentInner').html(html);
				checkPopupHeight();
			});
			$('.popupContent').ajaxError(function(){
				$('.popupContent .popupContentInner').html('<h2>Error Opening</h2><p>Please try again later.</p>');
			});
		}
		
	}else{
		if(content=='FLASH'){
			if(typeof(content2)=='object'){
				
				flvName=content2.url.replace(/\&|\?iid=[\w\W]+\&?/,'').replace(/(https?:\/\/)?[A-Za-z0-9\/ \_\-\%\#\@\+\.\?]*\//,'');
				trackEvent(flvName+'|popup|video');
				
				$('.popupContent .popupContentInner').empty().append('<div id="popupWindowVideo"></div>');
				$('#popupWindowVideo').css('height',content2.height);
				var fv={'screen':content2.screen,'video':content2.url,'width':content2.width,'height':content2.height};
				swfobject.embedSWF("http://scene7.samsclub.com/is/content/samsclub/Video_Player_v1?v=2","popupWindowVideo",content2.width,content2.height,"9.0.0","/sams/swf/expressInstall.swf",fv,{wmode:"transparent",allowscriptaccess:"always"});
				checkPopupHeight();
			}else{
				// flash config is fubar, aborting.
				return false;
			}
		}else{
			$(content).clone().css({'display':'block','visibility':'visible','opacity':'1'}).appendTo($('.popupContentInner'));
			
			contentName=$(content).attr('id');
			if(contentName==''){contentName=$(content).find('h1:first,h2:first,h3:first,h4:first,h5:first,strong:first').eq(0).text();}
			if(contentName==''){contentName=$.trim($(content).text()).substr(0,20).replace(/ /gm,'');}
			trackEvent(contentName+'|popup|content');
			checkPopupHeight();
		}
	}
	$('.popupClose,.popupOverlay').live('click',function(){
		$('.popupOverlay').add('.popupWindow').fadeOut(400,function(){$(this).remove();});
		return false;
	});
}
function checkPopupHeight(){
	var scrollHeight = new Number;
		
	if($('.popupContent')[0] && $('.popupContent')[0].nodeName.toLowerCase()=='iframe'){
		scrollHeight=$('.popupContent').contents().find('html')[0].scrollHeight;
	}else{
		scrollHeight=$('.popupContent .popupContentInner').height();
	}
		
	if(($('.popupContent').outerHeight()+100)>$(window).height() || scrollHeight > $('.popupContent').outerHeight()){	
		$('.popupWindow').css({'width':'740px','padding':'10px 0 0 0'}).find('#mainContent,#helpContent-negativeTop').css('padding','0');
		$('.popupLogo').css({'margin-left':'-1px'});
		$('.popupContent').css({'height':($(window).height()-200)+'px','overflow':'auto','overflow-x':'hidden'});
	}else{
		var height = new Number;
		if($(window).height()-200 < parseInt(scrollHeight)){
			height = parseInt($(window).height())-200;
		}else{
			height = parseInt(scrollHeight);
		}
		$('.popupContent').css({'height':height+'px','overflow':'auto','overflow-x':'hidden'});
	}
}
$(window).resize(function(){
	checkPopupHeight();
});

function openPopup(url,e){
	proto=location.protocol;
	sub=location.host.split('.').shift();
	if(sub=='samsclub'){sub='www'}
	if(!url.match(/https?:\/\//)){url=proto+'//'+sub+'.samsclub.com/'+url;}	
	openPopupWindow(url);
}
//End PASupport: 17Aug2011 (Site Redesign Update)

/* Start PASupport: 19 August, 2011 :: Membership purchase checkout (Site Redesign)*/
$('#joinNow').ready(function(){
	var hoverTimeout,
		leaveTimeout,
		tableTimeout;
	 	if (typeof benefitTitle!=="undefined" && typeof benefitDefault!=="undefined") {
		$('#joinNow').find('th').parent().append(benefitTitle).closest('table').find('tbody').find('td').eq(0).parent().append(benefitDefault);
		$('#joinNow tbody td:not(".memInfo"),#joinNow label,#joinNow input[type=radio]').css({'cursor':'pointer'});
		$('#joinNow td:not(".memInfo")').click(function(){
			$(this).parent().find('input[type="radio"]').attr('checked',true);
		});
		
		$('#joinNow td,.memInfo').hover(function(){
			clearTimeout(leaveTimeout);clearTimeout(hoverTimeout);
			tr=$(this).parent();
			if($(this).hasClass('memInfo')){return false;}
			hoverTimeout=setTimeout(function(){
				tr.siblings().find('td:not(".memInfo")').css({'background':''});
				$('#joinNowArrow').remove();
				tr.find('td:not(".memInfo")').css({'background':'#efefef url(\'join_now_arrow.png\') no-repeat','background-position':'-20px top'}).eq(0).css({'background':'#efefef'});
				offTop=tr.children('td:first').position().top;
				offLeft=tr.children('td:eq(0)').outerWidth(true) + tr.children('td:eq(1)').outerWidth(true);
				tr.children('td').eq(1).append('<div id="joinNowArrow"></div>');
				$('#joinNowArrow').css({'top':offTop,'left':offLeft});
				name=tr.children('td').eq(0).text();
				if(name.match(/Advantage Plus/)){				
					$('.memInfo').html(benefitsText.advPlus);
				}else if(name.match(/Advantage/)){
					$('.memInfo').html(benefitsText.adv);
				}else if(name.match(/Business Plus/)){
					$('.memInfo').html(benefitsText.busPlus);
				}else if(name.match(/Business/)){
					$('.memInfo').html(benefitsText.bus);
				}
			},100);
		},function(){
			tr=$(this).parent();
			clearTimeout(leaveTimeout);clearTimeout(hoverTimeout);
			leaveTimeout=setTimeout(function(){
				tr.find('td:not(".memInfo")').css({'background':''});
				$('#joinNowArrow').remove();
				$('.memInfo').html(benefitsText.def);
			},100);
		});
		$('#joinNow').hover(function(){
			clearTimeout(tableTimeout);return true;
		},function(){
			clearTimeout(tableTimeout);
			tableTimeout=setTimeout(function(){
				tr.siblings().find('td:not(".memInfo")').css({'background':''});
				$('#joinNowArrow').remove();
				$('.memInfo').html(benefitsText.def);
			},100);
		});		
	}	
});
/* End PASupport: 19 August, 2011 :: Membership purchase checkout (Site Redesign)*/
