Object.extend(Prototype.Browser, {
	css3: function(){
		if (Prototype.Browser.WebKit) {
			return true
		} else {
			return false
		}
	}
});

$(document).observe('dom:loaded', function(e){
	
	var para = {}
	para.eventType = 'hover';
	para.forceClose = true;
	para.animate = false
	if ($$('ul.main')[0]) {
		$$('ul.main')[0].dropnav(para);
	}
	
	$$("input[type='radio'][name='SPCK_KIDS_R']").each(function(v) {
		if(v.up("table")) {
			v.up("table").style.width="auto";
		}
	});
	if(!Prototype.Browser.css3()){
		$$('form[name="applyDiscount"] td[align="left"]').each(function(v) {
		v.addClassName("promoCell");
		});
	}
	
	//CSS3 Override for Firefox mid CSS3 versions
	$$('form.gift-card fieldset:nth-of-type(even)').invoke('setStyle', { float: 'right' })	
	$$('form.gift-card fieldset label:first-of-type').invoke('setStyle', { marginTop: '0px'	})
})
Event.observe(window, 'load', function () {
	// Product List -- oddly, this doesn't work properly if done on the dom:loaded.
	$$('body.search ol.products li:nth-of-type(4n+4), body.family ul.products li:nth-of-type(4n+4), body.apr ol.products li:nth-of-type(5n+5), body.help ul.help-topics li.section:nth-child(5n+5)').invoke('setStyle', { marginRight: 0 })
	$$('body.category ul.categories li:nth-of-type(4n+4)').invoke('setStyle', { marginRight: '0', paddingRight: '0', borderRight: '0' })
});
//Category Leftnav
$(document).observe("dom:loaded", function(e) {
	$(document.body).observe("click", function(ee) {
		Df.Anchor.rewriteHandler(ee);
	})
});

Event.observe(window,'load',function(){

	//window load event
	var alink = $$('.category .side-nav li a');
	

	alink.each(function(v){
		if(!v.hasClassName("topcat") && !v.hasClassName("family") && !v.hasClassName("superfamily") && v.up("li").down("ul")){
			var ref = v.href
			v.removeAttribute("rel");
			v.href = 'javascript:void(0)'
		}
		
		var temp;
		var current;
		v.observe('click', function(e){
			//run your code
			if(!v.hasClassName("topcat") && !v.hasClassName("superfamily")){

				
			if(v.next(0)){				
				if(!v.next(0).hasClassName("active")){
					
					prevSib = v.up().previousSiblings();
					nextSib = v.up().nextSiblings();
					prevSib.each(function(i){
						i.up().select('li.active', 'ul.active').each(function(j){
							
							j.removeClassName('active');
						});
					});
					nextSib.each(function(i){
						i.up().select('li.active', 'ul.active').each(function(j){
							j.removeClassName('active');
						});
					})
					
					v.next(0).addClassName('active');
					v.up(0).addClassName('active');
					
				}else{
					v.next(0).removeClassName('active');
					v.up(0).removeClassName('active');
				}
			}
				
				
			}
		
		});
	});
	
	
});