Object.extend(Prototype.Browser, {
	css3: function(){
		var name = navigator.userAgent.toLowerCase()
		var m = name.match(/^[\s|\S]+?firefox\/([0-9]+)\.([0-9]+)[\s|\S]+$/)
		if(m && m[1] > 1){
			return true		
		} else 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");
																																		});
		// Labels & Fields
		$$('input[type="text"],input[type="password"],textarea').invoke('setStyle', { border: '1px solid #c5c5c5', width: '218px', fontSize: '12px',  color: '#4d4d4d', fontFamily: 'Helvetica, Arial, sans-serif' });
		$$('input[type="text"],input[type="password"]').invoke('setStyle', { height: '17px', paddingTop: '5px' });
		$$('body:not(.checkout-cart) label:after').invoke('insert', '<span>:</span>');
		$$('input[type="checkbox"] + label span, input[type="radio"] + label span').invoke('remove');
		$$('input[type="checkbox"], input[type="radio"]').invoke('setStyle', { marginRight: '10px' });
		$$("label[for='ccvNumber']").each(function(v) {
			v.addClassName("ccvNumber");
		});
		$$("#processconfirm form td td.checkbg_lt td td[width='45%'] b").each(function(v) {
			v.addClassName("visaSummary");
			v.style.display="inline";
		});


		// Action Buttons
		$$('input[type="submit"], input[type="button"]').invoke('observe', 'mouseover', function(e){ e.target.setStyle({ backgroundPosition: 'left bottom' }) }).invoke('observe','mouseout', function(e){ e.target.setStyle({ backgroundPosition: 'left top' }) });	
		$$('input[type="submit"], input[type="button"]').invoke('setStyle', { display: 'block', textIndent: '-9999px', height: '24px', backgroundRepeat: 'no-repeat', backgroundPosition: 'left top', cursor: 'pointer', fontSize: '0', lineHeight: '0' })

		$$('input[name="add-to-cart"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_add-to-cart_a.png)', width: '107px' })
		$$('input[name="continue"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_continue_a.png)', width: '85px' })
		$$('input[name="submit"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_submit_a.png)', width: '109px' })
		$$('input[name="send"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_send_a.png)', width: '55px' })
		$$('input[name="search"]').invoke('setStyle', {backgroundImage: 'url(../images/schk_search_a.png)', width: '69px', float: 'left', marginLeft: '5px' })
		$$('input[name="go"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_go_a.png)', width: '50px' })
		$$('input[name="submit-inquiry"]').invoke('setStyle', { backgroundImage: 'url(../images/schk_submit-inquiry_a.png)', width: '148px' })
		
		// Family
		$$('span.property:after').invoke('insert','<span style="padding-right: 5px;">:</span>')
		$$('label.sort-by').invoke('setStyle', { paddingRight: '5px' })
		$$('label.sort-by:before').invoke('insert', {top:'<span style="padding: 0 5px;">//</span>'})
		
		// General
		$$('a.more:after').invoke('insert', '<span>...</span>');
		
		// Search Form
		$$('form.search input[name="kw"]').invoke('setStyle', { display: 'block' })

		// Sidenav
		$$('span.quantity:before').invoke('insert', {top:'<span>(</span>'});
		$$('span.quantity:after').invoke('insert', '<span>)</span>');
		$$('ul.side-nav li span.price:first-child:after').invoke('insert','<span style="padding: 0 5px;">-</span>');
		$$('ul.side-nav li:first-child span.price span').invoke('remove');
		
		// Breadcrumbs
		$$('ul.breadcrumbs li:after').invoke('insert', '<span style="padding: 0 5px;">/</span>')
		$$('ul.breadcrumbs li:last-child').invoke('setStyle', { color: '#ed1b2e' })
		$$('ul.breadcrumbs li:last-child span').invoke('remove');
		
		// Nav Items
		$$('ul.nav li:last-child a').invoke('setStyle', { paddingRight: '0', marginRight: '0', borderRight: 'none' })
		
		// Main Nav & Logo Nav
		$$('ul.logo li:last-child').invoke('setStyle', { marginLeft: '0', marginRight: '0', borderRight: 'none' })
		$$('ul.main li:last-child a').invoke('setStyle', { paddingRight: '10px', marginRight: '10px', borderRight: '1px solid #f25c6a' })
				
		//Footer Styles
		$$('div#footer p.support span.tel:nth-child(2):after').invoke('insert', '<span style="padding: 0 10px;">.<span>')
		$$('ul.copyright li:last-child').invoke('setStyle', { background: 'url(../images/schk_canada-flag_icon.png) no-repeat right center', paddingRight: '35px' })
		
		//Microformats
		$$('span.type:after').invoke('insert', '<span style="padding-right: 5px;">:</span>')
		
		//Sitemap
		$$('body.sitemap h3 + ul').invoke('setStyle', { paddingBottom: '10px' })
		
		// Gift Cards & Gift Certificates
		$$('form.gift-card input[name="add-to-cart"]').invoke('setStyle', { clear: 'both', float: 'right' })
		$$('input[name="amount"]').invoke('setStyle', { width: '50px', verticalAlign: 'top', margin: '0 2px' })
		
		// Store Locator
		$$('body.store-locator input[name="continue"]').invoke('setStyle', { marginTop: '10px' })
		$$('body.store-locator table.results tr.location:last-child td').invoke('setStyle', { borderBottom: 'none' })
		$$('body.store-locator table.results tr.location td:last-child').invoke('setStyle', { paddingRight: '0' })

		// Search
		$$('body.search.no-results ol.search-tips li p:first-child').invoke('setStyle', { color: '#4d4d4d', fontWeight: 'bold' })
		$$('body.search.no-results input[name="search"]').invoke('setStyle', { marginLeft: '5px' })

		// Email Signup
		$$('body.email input[type="text"]').invoke('setStyle', { height: '22px', marginRight: '10px' })
		
		// Product 
		$$('body.hproduct ul.breadcrumbs li:last-child a').invoke('setStyle', { color: '#ED1B2E' })
		$$('dl.options input[name="add-to-cart"]').invoke('setStyle', { marginRight: '20px' })
		$$('div.sub h4:after').invoke('insert', '<span>:</span>');
		$$('ol#rv-product-slider li:last-child').invoke('setStyle', { paddingRight: '0', marginRight: '0', borderRight: '0' })
		$$('ul.keywords li:last-child, ul.categories li:last-child').invoke('setStyle', { paddingRight: '0', marginRight: '0', borderRight: '0' })
		
		// Shop by Appointment
		$$('ul.fields.contact-info li:nth-child(even)').invoke('setStyle', { marginRight: '0' })
		$$('ul.fields.contact-info input').invoke('setStyle', { width: '178px' })
		$$('fieldset.phones input').invoke('setStyle', { width: '40px' })
		$$('label[for="cell"], label[for="work"], label[for="home"]').invoke('setStyle', { display: 'block', fontWeight: 'bold', paddingBottom: '0' })
		$$('label[for="work-ext"]').invoke('setStyle', { display: 'inline', margin: '0 2px 0 5px', fontWeight: 'normal' })
		
		
		// Pagination
		$$('ul.pages li:first-child a:before').invoke('insert', {top:'<span style="padding-right: 5px; color: #ec1b2e;">&lt;&lt;</span>'})
		$$('ul.pages li:last-child a:after').invoke('insert', '<span style="padding-left: 5px; color: #ec1b2e;">&gt;&gt;</span>')
		
		// Checkout
		$$('body.checkout .padding table input.pagetext').invoke('setStyle', { width: '130px', display: 'block' })
		
		// Tell a Friend
		$$('div.pop-up.tell-a-friend div.field + div.field').invoke('setStyle', { float: 'right' })
		$$('div.pop-up.tell-a-friend input[name="recaptcha_response_field"]').invoke('setStyle', { float: 'left' })
		$$('div.pop-up.tell-a-friend input[name="send"]').invoke('setStyle', { float: 'right' })
		
		// Helpdesk
		$$('body.help h2 + p').invoke('setStyle', { width: '640px', paddingBottom: '25px' })
		$$('form#contact-us label span:not(.required)').invoke('remove');
		$$('form#contact-us input[type="text"]').invoke('setStyle', { display: 'block' })
		$$('form#contact-us div.field:nth-child(even)').invoke('setStyle', { float: 'right' })
		$$('form#contact-us input[name="submit-inquiry"]').invoke('setStyle', { float: 'right' })
		
		// Helpdesk
		$$('body.cart td[width="380"] table[cellpadding="3"]').invoke('setStyle', { float: 'right' })
		$$('body.cart td[width="380"] table tr td').invoke('setStyle', { verticalAlign: 'top' })
		$$('body.cart td[width="380"] table tr td:last-child').invoke('setStyle', { textAlign: 'right' })
		$$('body.cart td[width="380"] table tr:first-child td').invoke('setStyle', { padding: '10px 0', borderBottom: '1px solid #f0f0f0' })
		$$('body.cart td[width="380"] table tr:nth-child(2), body.cart td[width="380"] table tr:nth-child(4), body.cart td[width="380"] table tr:nth-child(11), body.cart td[width="380"] table tr:nth-child(13)').invoke('setStyle', { display: 'none' })
		$$('body.cart td[width="380"] table tr:nth-child(3) td').invoke('setStyle', { padding: '10px 0', borderBottom: '1px solid #f0f0f0', height: '30px' })
		$$('body.cart td[width="380"] table tr:nth-child(5) td').invoke('setStyle', { padding: '10px 0', borderBottom: '1px solid #f0f0f0' })
		$$('body.cart td[width="380"] table tr:nth-child(6) td').invoke('setStyle', { padding: '10px 0', borderBottom: '1px solid #f0f0f0' })
		$$('body.cart td[width="380"] table tr:nth-child(7) td').invoke('setStyle', { paddingTop: '10px' })
		$$('body.cart td[width="380"] table tr:nth-child(10) td').invoke('setStyle', { paddingBottom: '10px' })
		$$('body.cart td[width="380"] table tr:nth-child(12) td').invoke('setStyle', { padding: '10px 0', borderTop: '1px solid #f0f0f0' })
		
		//Cart & Checkout

		//Login
		$$('#processlogin table[width="750"]').invoke('setStyle', { marginBottom: '15px', display: 'block' })
		$$('#processlogin table + br').invoke('setStyle', { display: 'none' })
		$$('#processlogin table[width="750"][cellpadding="3"]').invoke('setStyle', { display: 'none' })
		$$('#processlogin table[width="71%"]').invoke('setStyle', { width: '700px', margin: '0 auto' })
		$$('#processlogin table[width="71%"] table').invoke('setStyle', { width: '700px', lineHeight: '2', border: '1px solid #cc0000' })
		$$('#processlogin table[width="71%"] table td').invoke('setStyle', { padding: '10px'  })
		
		//My Account
		$$('#processmyaccount table[cellpadding="5"]').invoke('setStyle', { display: 'block', marginBottom: '10px' })
		
		//Address
		$$('#processaddress td.checkbg_lt table:nth-child(2) tr:first-child td:first-child').invoke('setStyle', { color: '#C51626' })
		
		// Item Destionations
		$$('body.itemDestinations-process div.content table[width="600"]').invoke('setStyle', { width: '100%' })
		
		//Payment
		$$('#processpayment #ccPin').invoke('setStyle', { width: '30px' })

		//Cart
		$$('body.cart div.content table[width="750"][cellpadding="0"]').invoke('setStyle', { marginBottom: '15px' })
		$$('body.cart div.content table[width="750"][cellpadding="0"] tr:nth-child(2) td:nth-child(3) table:first-child').invoke('setStyle', { float: 'right' })
		$$('body.cart div.content table[width="750"][cellpadding="0"] tr:nth-child(2) td:nth-child(2) a').invoke('setStyle', { textDecoration: 'underline' })
		$$('img[src="/images/may_we_suggest.gif"]').invoke('setStyle', { verticalAlign: 'top' })
		$$('body.cart div.content table[width="750"][cellpadding="0"] tr:nth-child(2) td:nth-child(3) table:first-child a.pagelink').invoke('setStyle', { display: 'inline', right: '0' })
		$$('table#cartBgclrProdDtls td[width="380"], table#cartBgclrProdDtls td[valign="top"]:nth-child(2)').invoke('setStyle', { paddingLeft: '15px' })
		$$('body.cart table#cartBgclrProdDtls img[src*="graphics"]').invoke('setStyle', { padding: '0 10px 15px 0' })
		$$('body.cart table#cartBgclrProdDtls img[width="52"]').invoke('setStyle', { display: 'none' })
		
		//Infozone Images
		$$('body.info div.content img[align="right"]').invoke('setStyle', { paddingLeft: '15px', float: 'right', clear: 'right' })
		$$('body.info div.content img[align="left"]').invoke('setStyle', { paddingRight: '15px', float: 'left', clear: 'left' })
		
		//Gift Wrap
		$$('.giftWrap-process td[width="45%"], .giftWrap-process td[width="55%"]').invoke('setStyle', { verticalAlign: 'top' })
		$$('.giftWrap-process img[align="left"]').invoke('setStyle', { float: 'left', paddingRight: '10px', verticalAlign: 'top' })
		
		//Survey Email
		//$$('body.surveyEmail-process table[width="750"]').invoke('setStyle', { float: 'left', width: '600px' })
		
	}
	
	//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');
				}
			}
				
				
			}
		
		});
	});
	
	
});