Event.observe(window, 'load', init, false);
initial = false;

function init() {
	loadAccordions();	// below
	webkitFormStyles();
	//ieBGTweaks();
	if($('goForm')) {
		Event.observe($('goForm'), 'click', showContactForm);
	//	Event.observe($('sb'), 'click', hideContactForm);
	}
}

function loadAccordions() {
	
var navAccordion = new accordion('lnav', {
    classNames : {
		toggle : 'lnavUp',
		toggleActive : 'lnavDown',
		content : 'lnavContent'
	},
	defaultSize : {
		height : null,
		width:null
	},
	direction : 'vertical'
});
if(initial && initial < 0) {
var array = $$('#lnav .lnavUp');
navAccordion.quickActivate(array[array.length - 1]);
} else if(initial){
navAccordion.quickActivate($$('#lnav .lnavUp')[initial]);
} else {
navAccordion.quickActivate($$('#lnav .lnavUp')[0]);
}


var col1Items = $$('div.col1 *');
	for (var i = col1Items.length - 1; i >= 0; i--){
		col1Items[i].style.visibility='visible';
	}
}

function webkitFormStyles () {
	if (Prototype.Browser.WebKit && navigator.appVersion.charAt(0) == '5') {
		if($('contactInfo') && $('cvv')){ // JB 3/25 because front page of support has a #contactInfo too
			var baseInputs = $$('#contactInfo input');
			for (var i = baseInputs.length - 1; i >= 0; i--){
				if (baseInputs[i].type != 'radio') {
					baseInputs[i].style.width = 205 + 'px';
				}
			}
			$('cvv').style.width = 52 + 'px';
			$('expireMonth').style.width = 40 + 'px';
			$('expireYear').style.width = 66 + 'px';
			$('zip_billing').style.width = 138 + 'px';
			$('zip_shipping').style.width = 138 + 'px';
		}
	}
}

function ieBGTweaks(){
	if (Prototype.Browser.IE) {
		var col3RoundBottomCorners = $$('div.col3 div.bottom img');
		for (var j = col3RoundBottomCorners.length - 1; j >= 0; j--){
			col3RoundBottomCorners[j].filters.gradient.enabled=false;
		}
	}
}

function showContactForm(){

	$('help3').setStyle({
	  height: 'auto'
	});
	
	$('goForm').hide();

	$('showForm').setStyle({
							display: 'block',
							height: 'auto',
							visibility: 'visible',
							overflow: 'hidden',
							width: '370px'
							});
	
	// JB 3/25 fixed to account for IE's position:relative
	if(Prototype.Browser.IE) $('showForm').up('.col2_content').setStyle({ height: '750px' });
	
	return false;
}

function hideContactForm() {
	$('showForm').hide();
	if(Prototype.Browser.IE) $('showForm').up('.col2_content').setStyle({ height: '450px' });
	$('thankYouMessage').setStyle({ display: 'block' });
}


function init_shopping_alerts(){
	initIntStore()
alertses = $$('.bigNotice');
panelses = $$('.bigNotice .infopanel');
triggerses = $$('.bigNotice .moreinfo'); // the "show details" buttons
triggerses2 = $$('.bigNotice .noinfo'); // the "hide details" buttons
checkses = $$('#checkboxes input');

for(d = 0; d<triggerses.length; d++){
triggerses[d].uid = d;
Event.observe(triggerses[d], "click", showPanelClick.bindAsEventListener(triggerses[d]));
}

for(e = 0; e<triggerses2.length; e++){
triggerses2[e].uid = e;
Event.observe(triggerses2[e], "click", hidePanelClick.bindAsEventListener(triggerses2[e]));
}

for(v = 0; v<checkses.length; v++){
checkses[v].uid = v;
if(checkses[v].readAttribute('checked') == "" || checkses[v].readAttribute('checked')){
							 alertses[v].show();
checkses[v].statex = true;
							 } else {
checkses[v].statex = false;
}
Event.observe(checkses[v], "click", doAlertClick.bindAsEventListener(checkses[v]));
}




}

function doAlertClick(e){
if(this.statex){
alertses[this.uid].hide();
hidePanelClick.apply(this); // [5107]
this.statex = false;
} else {
alertses[this.uid].show();
this.statex = true;
}

}

function showPanelClick(){
	// show details button clicked
panelses[this.uid].show();
triggerses2[this.uid].show();
triggerses[this.uid].hide();

alertses[this.uid].setStyle({
  height: 'auto'
});

}

function hidePanelClick(){
	// hide details button clicked
triggerses[this.uid].show();
triggerses2[this.uid].hide();
panelses[this.uid].hide();
alertses[this.uid].setStyle({
  height: '40px'
});


}

defaultCountry = 0;





function initIntStore(){
	var sameAsBillCheck = $$('#sameAsBill input')[0];
	doShipping.apply($$('#sameAsBill input')[0]);
	Event.observe(sameAsBillCheck, "click", doShipping.bindAsEventListener(sameAsBillCheck));
	Event.observe($$('#Country SELECT')[0], 'change', swapInt);
	swapInt();
	}
	
	function doShipping(){
	if(this.checked){
	sameAsBilling();

		
	} else {
	notSameAsBilling();



	}
	}
	
	function swapInt(){
	if($$('#Country SELECT')[0].value != defaultCountry){
		$('interFields').show();
		$('InternationalField').show();
		$('interLabel1').show();
		$('interLabel2').show();
		$('StatePopup').hide();
		$('usLabel').hide();
		$$('.interblock')[0].addClassName('imode');
		$$('#sameAsBill INPUT')[0].disable();
		$('sameAsBill').addClassName('inactive');
		$$('#sameAsBill input')[0].checked = false;
		
		// fix [5148]: set phone to require only 3 characters
		sprytextfield8.minChars = 3;
		
		notSameAsBilling();
		
	} else {
		$('interFields').hide();
		$('InternationalField').hide();
		$('interLabel1').hide();
		$('interLabel2').hide();
		$('StatePopup').show();
		$('usLabel').show();
		$$('.interblock')[0].removeClassName('imode');	
		$$('#sameAsBill INPUT')[0].enable();
		$('sameAsBill').removeClassName('inactive');

		// fix [5148]: set phone to require 10 characters
		sprytextfield8.minChars = 10;


	};
	}
	
	// edit the two fields below to extend or remove Spry validation
	var sabFields = []; // blank; change in sameAsBilling()
	var sabAttributes = {isRequired: false, minChars: null, maxChars: null}; // keys are the attributes to blank, values are blank attributes to insert
	var sabStoreRequirements = [];
	
	function sameAsBilling(){
		sabFields = [sprytextfield14, sprytextfield15, sprytextfield16, sprytextfield18, sprytextfield19, sprytextfield20];
		
		for(var field in sabFields) {
			sabStoreRequirements[field] = {}; // initialize array
			for(var attribute in sabAttributes) {
				sabStoreRequirements[field][attribute] = sabFields[field][attribute];  // save old value
				sabFields[field][attribute] = sabAttributes[attribute] // insert default value
			}
		}
		$('shipChunk').hide();
		$('chunkNotice').show();
		
	}
	function notSameAsBilling(){
		for(var field in sabFields) {
			for(var attribute in sabAttributes) {
				sabFields[field][attribute] = sabStoreRequirements[field][attribute];  // replace with old value
			}
		}
		$('shipChunk').show();
		$('chunkNotice').hide();
	}
	
	
	
	
	
	
	function initIntDev(){
	
	Event.observe($$('#country SELECT')[0], 'change', swapIntDev);
	swapIntDev();
	}

	
	
	function swapIntDev(){
	if($$('#country SELECT')[0].value != defaultCountry){
		
		$('interFields').show();
		$('InternationalField').show();
		$('interLabel1').show();
		$('interLabel2').show();
		$('StatePopup').hide();
		$('usLabel').hide();
		$$('.interblock')[0].addClassName('imode');

	} else {
		$('interFields').hide();
		$('InternationalField').hide();
		$('interLabel1').hide();
		$('interLabel2').hide();
		$('StatePopup').show();
		$('usLabel').show();
		$$('.interblock')[0].removeClassName('imode');	
	};
	}