//-CONSTANTS--------------------------------------------------------------------

var VIEWPORTDELTA = -493;

var evenOdd = Array('even','odd');
var frontRear = {
	'frontWheel' : 'Front wheel',
	'rearWheel'  : 'Rear wheel'
};

//------------------------------------------------------------------------------

function parseQueryString(s) {
	var vars = s.substring(1).split(/[&;]/);
	var rs = {};
	if (vars.length) vars.each(function(val) {
		var keys = val.split('=');
		if (keys.length && keys.length == 2) rs[encodeURIComponent(keys[0])] = encodeURIComponent(keys[1]);
	});
	return rs;
} // parseQueryString

function commaNumber(number){
	number = '' + number;
	if (number.length > 3) {
		var mod = number.length % 3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for(i=0 ; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
			else
				output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
			} // if..else
			return (output);
		} // for
	else
		return number;
} // commaNumber

function formatCost(cost) {
	return (cost==0) ? "Included" : "$"+commaNumber(cost);
} // formatCost

//------------------------------------------------------------------------------

function setRadioButton( groupName, buttonValue ) {
	$$('input[name='+groupName+']').each( function(el) {
		el.checked = (el.value == buttonValue);
	}); // each
} // function..setRadioButton

function getRadioButton( groupName ) {
	var buttonValue = '';
	$$('input[name='+groupName+']').each( function(el) {
		if(el.checked) { buttonValue = el.value; }
	}); // each
	return buttonValue
} // function..getRadioButton

//------------------------------------------------------------------------------

function dialogManager( plan ) {
	mdl.modalShow({ 'hideOnClick': false, 'modalStyle': { 'opacity':.50, 'background-color':'#000000', 'z-index': 1000 } });
	var req = new Request.HTML({url : plan.dialogInclude,
		onSuccess: function(html) {
			$('dialogContainer').set('text', '').adopt(html);

			plan.init();
			new Hash(plan.methods).each( function(methodFunction, key) {
				$(key).onclick = $lambda(methodFunction);
			}); // each
		} // onSuccess
	}).send();
} // function..dialogManager

//------------------------------------------------------------------------------

var emailOrderPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/email-order-dialog.inc',
	init : function() {
		$('sender_name').focus();
		$('order_json').value = JSON.encode(configurator.wheelOrder);
	},
	methods : {
		dialogSendButton : function() {
			$$('.dialogStep2').setStyle('display','inline');

			$('emailOrderDialog').get('send',{
				method: 'post',
				onSuccess: function(wsResult){
					var jsonResult = JSON.decode(wsResult);
					if(!jsonResult.success) {
						$('messageMsg').set('text',jsonResult.message);
						$$('.dialogStep2').setStyle('display','none');
					} else {
						orderId = jsonResult.orderId;
						$('dialogContainer').empty();
						mdl.modalHide();
					} // if..else
				}
			}).send();

		}, // dialogSendButton
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		} // dialogCloseButton
	} // methods
} // emailOrderPlan

//------------------------------------------------------------------------------

var homePageRetrieveOrderPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/retrieve-order-dialog.inc',
	init : function() {
		$('orderId').focus();
	},
	methods : {
		dialogSendButton : function() {
			$$('.dialogStep2').setStyle('display','inline');

			$('retrieveOrderDialog').get('send',{
				method: 'post',
				onSuccess: function(wsResult){
					var jsonResult = JSON.decode(wsResult);
					if(!jsonResult.success) {
						$('messageMsg').set('text',jsonResult.message);
						$$('.dialogStep2').setStyle('display','none');
					} else {
						window.location = 'customize.php?' + $('retrieveOrderDialog').toQueryString();
					} // if..else
				}
			}).send();
		}, // dialogSendButton
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		} // dialogCloseButton
	} // methods
} // homePageRetrieveOrderPlan

//------------------------------------------------------------------------------

var retrieveOrderPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/retrieve-order-dialog.inc',
	init : function() {
		$('orderId').focus();
	},
	methods : {
		dialogSendButton : function() {
			$$('.dialogStep2').setStyle('display','inline');

			$('retrieveOrderDialog').get('send',{
				method: 'post',
				onSuccess: function(wsResult){
					var jsonResult = JSON.decode(wsResult);
					if(!jsonResult.success) {
						$('messageMsg').set('text',jsonResult.message);
						$$('.dialogStep2').setStyle('display','none');
					} else {
						configurator.wheelOrder = jsonResult.message;
						configurator.orderId = jsonResult.orderId;

						$("sendPrint").setStyle('display','block');

						configurator.initialize();

						$('dialogContainer').empty();
						mdl.modalHide();
					} // if..else
				}
			}).send();
		}, // dialogSendButton
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		} // dialogCloseButton
	} // methods
} // retrieveOrderPlan

//------------------------------------------------------------------------------

var downloadBrochurePlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/download-brochure-plan-dialog.inc',
	init : function() {
		$('orderId').focus();
	},
	methods : {
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		} // dialogCloseButton
	} // methods
} // downloadBrochurePlan

//------------------------------------------------------------------------------

var confirmConfigurationCopyPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/copy-confirm-dialog.inc',
	wheelCopyDirection : 'rearToFront',
	init : function() {
		$('instructionsRearToFront').setStyle('display', this.wheelCopyDirection=='rearToFront' ? 'block' : 'none');
		$('instructionsFrontToRear').setStyle('display', this.wheelCopyDirection!='rearToFront' ? 'block' : 'none');
	},
	methods : {
		dialogConfirmYesButton : function() {
			configurator.copyWheelConfiguration(confirmConfigurationCopyPlan.wheelCopyDirection);
			$('dialogContainer').empty();
			mdl.modalHide();

			if(confirmConfigurationCopyPlan.wheelCopyDirection=='frontToRear') {
				configurator.step3('rearWheel'); //-- make them configure a drive choice
			} else {
				configurator.trackStatistics('frontWheel');	//-- in this case, we're "done"
			} // if
		},
		dialogConfirmNoButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // confirmConfigurationCopyPlan

//------------------------------------------------------------------------------

var completeStepNotificationPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/complete-step-notification.inc',
	init : function() {
	},
	methods : {
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogConfirmOkButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // completeStepNotificationPlan

//------------------------------------------------------------------------------

var popupWarningPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/popup-warning-notification.inc',
	init : function() {
	},
	methods : {
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogConfirmOkButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // popupWarningPlan

//------------------------------------------------------------------------------

var completeConfigurationNotificationPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/complete-configuration-notification.inc',
	init : function() {
		if((configurator.wheelOrder.frontWheel.configured!="true") && (configurator.wheelOrder.rearWheel.configured!="true")) {
			$('wheelListCopy').set('text','front and rear wheels');
		} else if(configurator.wheelOrder.frontWheel.configured!="true") {
			$('wheelListCopy').set('text','front wheel');
		} else if(configurator.wheelOrder.rearWheel.configured!="true") {
			$('wheelListCopy').set('text','rear wheel');
		} // if
	},
	methods : {
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogConfirmOkButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // completeConfigurationNotificationPlan

//------------------------------------------------------------------------------

var confirmConfigurationClearPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/clear-confirm-dialog.inc',
	wheelConfiguration : 'frontWheel',
	init : function() {
		$('instructionsFrontWheel').setStyle('display', this.wheelConfiguration=='frontWheel' ? 'block' : 'none');
		$('instructionsRearWheel').setStyle('display', this.wheelConfiguration!='frontWheel' ? 'block' : 'none');
	},
	methods : {
		dialogConfirmYesButton : function() {
			configurator.clearWheelConfiguration(confirmConfigurationClearPlan.wheelConfiguration);
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogConfirmNoButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // confirmConfigurationClearPlan

//------------------------------------------------------------------------------

var wheelTagConfigurationPlan = {
	dialogInclude : '/zedtech/_includes/code/dialogs/wheeltag-dialog.inc',
	wheelConfiguration : 'frontWheel',
	init : function() {
		ShowWheelTagSWF();
	},
	methods : {
		dialogSaveButton : function() {
			setRadioButton('decalColor', "");
			configurator.wheelOrder[wheelTagConfigurationPlan.wheelConfiguration].hasCustomDecal = true;
			configurator.wheelOrder[wheelTagConfigurationPlan.wheelConfiguration].customDecalOptions = {
				zColor 			: zColorVal,
				iColor			: iColorVal,
				p1Color			: p1ColorVal,
				p2Color			: p2ColorVal,
				swooshColor		: swooshColorVal,
				strokeColor		: strokeColorVal,
				textColor		: textColorVal,
				materialType	: materialtypeVal,
				materialCost	: materialcostVal
			} // customDecalOptions

			configurator.generateBill(wheelTagConfigurationPlan.wheelConfiguration);

			$('decalDesignSelect').addClass('editDecal');

			$('dialogContainer').empty();
			mdl.modalHide();
		},
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}
	} // methods
} // wheelTagConfigurationPlan

//------------------------------------------------------------------------------

var mdl = new Modalizer();

var wheelConfigurator = new Class({
	orderId : "",

	wheelGraphicPath : "/zedtech/_media/images/step1/",

	//-- keep this in sync with wheelmodel.json.js!!!
	wheelModel : {
		frontWheel : [
			{
				label : 'ZED 2',
				isDiskBased : false,
				rimOptions  : {
					'Tubular'	: 'front-zed2-tubular.gif'
				}
			},
			{
				label : 'ZED 3',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'front-zed3-clincher.gif',
					'Tubular'	: 'front-zed3-tubular.gif'
				}
			},
			{
				label : 'ZED 4',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'front-zed4-clincher.gif',
					'Tubular'	: 'front-zed4-tubular.gif'
				}
			},
			{
				label : 'ZED 8',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'front-zed8-clincher.gif',
					'Tubular'	: 'front-zed8-tubular.gif'
				}
			},
			{
				label : 'ZED 10',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'front-zed10-clincher.gif',
					'Tubular'	: 'front-zed10-tubular.gif'
				}
			}
		],
		rearWheel : [
			{
				label : 'ZED 2',
				isDiskBased : false,
				rimOptions  : {
					'Tubular'	: 'rear-zed2-tubular.gif'
				}
			},
			{
				label : 'ZED 3',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'rear-zed3-clincher.gif',
					'Tubular'	: 'rear-zed3-tubular.gif'
				}
			},
			{
				label : 'ZED 4',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'rear-zed4-clincher.gif',
					'Tubular'	: 'rear-zed4-tubular.gif'
				}
			},
			{
				label : 'ZED 8',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'rear-zed8-clincher.gif',
					'Tubular'	: 'rear-zed8-tubular.gif'
				}
			},
			{
				label : 'ZED 10',
				isDiskBased : false,
				rimOptions  : {
					'Clincher'	: 'rear-zed10-clincher.gif',
					'Tubular'	: 'rear-zed10-tubular.gif'
				}
			},
			{
				label : 'ZED 9',
				isDiskBased : true,
				rimOptions  : {
					'Clincher'	: 'rear-zed9-clincher.gif',
					'Tubular'	: 'rear-zed9-tubular.gif'
				}
			},
			{
				label : 'ZED Sub-9',
				isDiskBased : true,
				rimOptions  : {
					'Tubular'	: 'rear-zedsub9-tubular.gif'
				}
			},
			{
				label : 'ZED Super-9',
				isDiskBased : true,
				rimOptions  : {
					'Tubular'	: 'rear-zedsuper9-tubular.gif'
				}
			}
		]
	}, // wheelModel

	//-- 2010 model year prices

	wheelOptionCosts : {
		frontWheel : {
			model : [
				{ 'Clincher' : 1575,	'Tubular' : 1575 },	// ZED 2
				{ 'Clincher' : 1575,	'Tubular' : 1575 },	// ZED 3
				{ 'Clincher' : 1575,	'Tubular' : 1575 },	// ZED 4
				{ 'Clincher' : 1620,	'Tubular' : 1620 },	// ZED 8
				{ 'Clincher' : 1665,	'Tubular' : 1665 }	// ZED 10
			],
			bearingStyle : {
				'Standard' : 0,
				'Ceramic' : 0 //-- Ceramic bearings free in 2010
			},
			laminateStyle : {
				'Standard' : 0,
				'SS' : 125,
				'SL' : 125
			}
		},
		rearWheel : {
			model : [
				{ 'Clincher' : 1925,	'Tubular' : 1925 },	// ZED 2
				{ 'Clincher' : 1925,	'Tubular' : 1925 },	// ZED 3
				{ 'Clincher' : 1925,	'Tubular' : 1925 },	// ZED 4
				{ 'Clincher' : 1980,	'Tubular' : 1980 },	// ZED 8
				{ 'Clincher' : 2035,	'Tubular' : 2035 },	// ZED 10
				{ 'Clincher' : 2200,	'Tubular' : 2100 },	// ZED 9
				{ 						'Tubular' : 2500 },	// ZED Sub-9
				{ 						'Tubular' : 2500 }	// ZED Super-9
			],
			bearingStyle : {
				'Standard' : 0,
				'Ceramic' : 0 //-- Ceramic bearings free in 2010
			},
			sramRedCassetteModel : {
				'Model 11-23' : 230,
				'Model 11-26' : 230
			},
			laminateStyle : {
				'Standard' : 0,
				'SS' : 125,
				'SL' : 125
			}
		},
		wheelBag : {
			'false' : 0,
			'true' : 185
		}
	}, // wheelOptionCosts

	blankWheel : {
		configured			: "false",
		usdCost				: 0,
		modelIdx			: 1,
		modelName			: "ZED 3",
		modelNameCost		: 0,
		rimStyle			: "Tubular",
		rimStyleCost		: 0,
		driveSystem			: "",
		driveSystemCost		: 0,
		addCassette			: false,	//-- n/a
		sramRedCassetteModel: "",		//-- n/a
		cassetteOption		: "",
		decalColor			: "",
		decalColorCost		: 0,
		hasCustomDecal		: false,
		customDecalOptions : {
			zColor			: "",
			iColor			: "",
			p1Color			: "",
			p2Color			: "",
			swooshColor		: "",
			strokeColor		: "",
			textColor		: "",
			materialType	: "",
			materialCost	: ""
		},
		nippleColor			: "",
		nippleColorCost		: 0,
		hubCapColor			: "",
		hubCapColorCost		: 0,
		hubNutColor			: "",
		hubNutColorCost		: 0,
		bearingStyle		: "Ceramic",
		bearingStyleCost	: 0,
		laminateStyle		: "",
		laminateStyleCost	: 0
	}, // blankWheel

	wheelOrder : {
		frontWheel : {
			configured			: "false",
			usdCost				: 0,
			modelIdx			: 1,
			modelName			: "ZED 3",
			modelNameCost		: 0,
			rimStyle			: "Tubular",
			rimStyleCost		: 0,
			driveSystem			: "",
			driveSystemCost		: 0,
			addCassette			: false,	//-- n/a
			sramRedCassetteModel: "",		//-- n/a
			decalColor			: "",
			decalColorCost		: 0,
			hasCustomDecal		: false,
			customDecalOptions : {
				zColor			: "",
				iColor			: "",
				p1Color			: "",
				p2Color			: "",
				swooshColor		: "",
				strokeColor		: "",
				textColor		: "",
				materialType	: "",
				materialCost	: ""
			},
			nippleColor			: "",
			nippleColorCost		: 0,
			hubCapColor			: "",
			hubCapColorCost		: 0,
			hubNutColor			: "",
			hubNutColorCost		: 0,
			bearingStyle		: "Ceramic",
			bearingStyleCost	: 0,
			laminateStyle		: "",
			laminateStyleCost	: 0
		},
		rearWheel : {
			configured			: "false",
			usdCost				: 0,
			modelIdx			: 1,
			modelName			: "ZED 3",
			modelNameCost		: 0,
			rimStyle			: "Tubular",
			rimStyleCost		: 0,
			driveSystem			: "",
			driveSystemCost		: 0,
			addCassette			: false,
			sramRedCassetteModel: "",
			decalColor			: "",
			decalColorCost		: 0,
			hasCustomDecal		: false,
			customDecalOptions : {
				zColor			: "",
				iColor			: "",
				p1Color			: "",
				p2Color			: "",
				swooshColor		: "",
				strokeColor		: "",
				textColor		: "",
				materialType	: "",
				materialCost	: ""
			},
			nippleColor			: "",
			nippleColorCost		: 0,
			hubCapColor			: "",
			hubCapColorCost		: 0,
			hubNutColor			: "",
			hubNutColorCost		: 0,
			bearingStyle		: "Ceramic",
			bearingStyleCost	: 0,
			laminateStyle		: "",
			laminateStyleCost	: 0
		},
		wheelBag : 'false',
		wheelBagCost : 0
	}, // wheelOrder

    initialize: function(){
		//-- new - free upgrade for 2010 MY
		this.wheelOrder.frontWheel.bearingStyle = "Ceramic";
		this.wheelOrder.rearWheel.bearingStyle = "Ceramic";

		$('price').setStyle('display','none');

		$('rearWheelTab').onclick = function() {
			this.makeRearWheelTabActive();
			return false;
		}.bind(this); // onclick
		$('frontWheelTab').onclick = function() {
			this.makeFrontWheelTabActive();
			return false;
		}.bind(this); // onclick

		if( (this.wheelOrder.frontWheel.configured=="false" && this.wheelOrder.rearWheel.configured=="false") ) {
			$('sendPrint').setStyle('display','none');
		} // if

		$('sendViaEmailLink').onclick = function() {
			if((configurator.wheelOrder.frontWheel.configured=="configuring") || (configurator.wheelOrder.rearWheel.configured=="configuring")) {
				dialogManager(completeConfigurationNotificationPlan);
			} else {
				dialogManager(emailOrderPlan);
			} // if..else
		}
		$('retreiveOrderLink').onclick = function() {
			dialogManager(retrieveOrderPlan);
		} // onclick
		$('downloadBrochureLink').onclick = function() {
			if((configurator.wheelOrder.frontWheel.configured=="configuring") || (configurator.wheelOrder.rearWheel.configured=="configuring")) {
				dialogManager(completeConfigurationNotificationPlan);
			} else {
                var jsonRequest = new Request.JSON({url: "/zedtech/_ws/putorder.php", onSuccess: function(jsonResult){
                    configurator.orderId = jsonResult.orderId;
                    var newWindow = window.open('zedtech-order.php?orderid='+configurator.orderId, '_blank');
                    if(newWindow==null) {
                        dialogManager(popupWarningPlan);
                    } else {
                        newWindow.focus();
                    } // if..else
                }}).post({'ignore_contact_info': 'true', 'order_json': JSON.encode(configurator.wheelOrder) });
			} // if..else
		} // onclick

		this.generateBill('frontWheel');
		this.generateBill('rearWheel');
		this.step1();
	},

	//---------------------------------

	makeRearWheelTabActive : function() {
		$('rearWheelTab').addClass('on');
		$('frontWheelTab').removeClass('on');
		$('rearWheelOptionsBill').addClass('selectionTableOn');
		$('frontWheelOptionsBill').removeClass('selectionTableOn');
	},

	makeFrontWheelTabActive : function() {
		$('rearWheelTab').removeClass('on');
		$('frontWheelTab').addClass('on');
		$('rearWheelOptionsBill').removeClass('selectionTableOn');
		$('frontWheelOptionsBill').addClass('selectionTableOn');
	},

	updateStep2Wheels : function(wheel) {
		if(!this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].rimOptions.Clincher) {
			$('tubularRim').set('checked',true);
			this.wheelOrder[wheel].rimStyle = "Tubular";
		} // if

		['previous','current','next'].each( function(pos,idx) {
			var wheelIdx = (this.wheelOrder[wheel].modelIdx+(idx-1)) % this.wheelModel[wheel].length;
			wheelIdx = (wheelIdx==-1) ? this.wheelModel[wheel].length-1 : wheelIdx;
			$(pos+'WheelLabel').setProperty('html',this.wheelModel[wheel][wheelIdx].label.replace(' ','&nbsp;'));
			$(pos+'WheelImage').setProperty('src',this.wheelGraphicPath+this.wheelModel[wheel][wheelIdx].rimOptions.Tubular);
		}.bind(this)); // each

		var wheelIdx = this.wheelOrder[wheel].modelIdx;
		$('selectWheelRimTubular').setStyle('display',$defined(this.wheelModel[wheel][wheelIdx].rimOptions.Tubular) ? 'block' : 'none');
		$('selectWheelRimClincher').setStyle('display',$defined(this.wheelModel[wheel][wheelIdx].rimOptions.Clincher) ? 'block' : 'none');

		if(this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].isDiskBased) {
			this.wheelOrder[wheel].nippleColor		= "";
			this.wheelOrder[wheel].hubCapColor		= "";
			this.wheelOrder[wheel].hubNutColor		= "";
			this.wheelOrder[wheel].laminateStyle	= "";
		} // if

		$(wheel+'SelectedImage').setProperty('src',this.wheelGraphicPath+this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].rimOptions[this.wheelOrder[wheel].rimStyle]);

		this.generateBill(wheel);
	}, // updateStep2Wheels

	generateBill : function(wheel) {
		var idx = 0, price = 0, subtotal = 0, html = '', tbodyhtml = '';

		if(this.wheelOrder[wheel].configured!="false") {
			html += '<table cellspacing="0">';
			html += '<thead>';
			html += '<tr><th>Category</th><th>Selection</th><th>Item&nbsp;price</th></tr>';
			html += '</thead>';
			tbodyhtml = '<tbody>';


			price = this.wheelOptionCosts[wheel].model[this.wheelOrder[wheel].modelIdx][this.wheelOrder[wheel].rimStyle];
			subtotal += price;
			tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Wheel</td><td><strong>'+this.wheelOrder[wheel].modelName+'</strong></td><td>'+formatCost(price)+'</td></tr>';
			this.wheelOrder[wheel].modelNameCost = price;

			if(this.wheelOrder[wheel].rimStyle!='') {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Rim</td><td><strong>'+this.wheelOrder[wheel].rimStyle+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].rimStyleCost = price;
			} // if
			if(this.wheelOrder[wheel].driveSystem!='') {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Drive</td><td><strong>'+this.wheelOrder[wheel].driveSystem+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].driveSystemCost = price;
			} // if
			if(this.wheelOrder[wheel].addCassette && (this.wheelOrder[wheel].sramRedCassetteModel!='')) {
				price = this.wheelOptionCosts[wheel].sramRedCassetteModel[this.wheelOrder[wheel].sramRedCassetteModel];
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>SRAM Red Cassette</td><td><strong>'+this.wheelOrder[wheel].sramRedCassetteModel+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].addCassetteCost = price;
			} // if
			if(this.wheelOrder[wheel].decalColor!="") {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Decal</td><td><strong>'+this.wheelOrder[wheel].decalColor+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].decalColorCost = price;
			} // if
			//-------- CUSTOM
			if(this.wheelOrder[wheel].hasCustomDecal) {
				price = parseInt(this.wheelOrder[wheel].customDecalOptions.materialCost);
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Custom Decal</td><td> </td><td>'+formatCost(price)+'</td></tr>';
			} // if
			//-------- CUSTOM
			if(this.wheelOrder[wheel].nippleColor!="") {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Nipple</td><td><strong>'+this.wheelOrder[wheel].nippleColor+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].nippleColorCost = price;
			} // if
			if(this.wheelOrder[wheel].hubCapColor!="") {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Hub cap</td><td><strong>'+this.wheelOrder[wheel].hubCapColor+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].hubCapColorCost = price;
			} // if
			if(this.wheelOrder[wheel].hubNutColor!="") {
				price = 0;
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Hub nut</td><td><strong>'+this.wheelOrder[wheel].hubNutColor+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].hubNutColorCost = price;
			} // if
			if(this.wheelOrder[wheel].laminateStyle!="") {
				price = this.wheelOptionCosts[wheel].laminateStyle[this.wheelOrder[wheel].laminateStyle];
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Laminate</td><td><strong>'+this.wheelOrder[wheel].laminateStyle+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].laminateStyleCost = price;
			} // if
			if(this.wheelOrder[wheel].bearingStyle!="") {
				price = this.wheelOptionCosts[wheel].bearingStyle[this.wheelOrder[wheel].bearingStyle];
				subtotal += price;
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Bearing</td><td><strong>'+this.wheelOrder[wheel].bearingStyle+'</strong></td><td>'+formatCost(price)+'</td></tr>';
				this.wheelOrder[wheel].bearingStyleCost = price;
			} // if
			if((this.wheelOrder.frontWheel.configured=="true") && (this.wheelOrder.rearWheel.configured=="true")) {
				tbodyhtml += '<tr class="'+evenOdd[idx++ % 2]+'"><td>Titanium quick releases</td><td><strong></strong></td><td>FREE</td></tr>';
			} // if

			tbodyhtml += '</tbody>';

			html += '<tfoot>';
			html += '<tr><th colspan="2">'+frontRear[wheel]+' price</th><th>$'+commaNumber(subtotal)+'</th></tr>';
			html += '</tfoot>';
			html += tbodyhtml;
			html += '</table>';

			html += '<a href="#" rel="'+wheel+'" id="'+wheel+'ClearConfiguration">Clear '+frontRear[wheel].toLowerCase()+' configuration</a>';

			$(wheel+'OptionsBill').set('html',html);

			$(wheel+'ClearConfiguration').onclick = function() {
				confirmConfigurationClearPlan.wheelConfiguration = this.rel;
				dialogManager(confirmConfigurationClearPlan);
			};

			this.wheelOrder[wheel].usdCost = subtotal;
		} else {
			$(wheel+'OptionsBill').set('html',frontRear[wheel]+' not configured');
		} // if..else

		//-- Wheel Bag - Special case
		html = '';
		price = this.wheelOptionCosts.wheelBag[this.wheelOrder.wheelBag];
		if(this.wheelOrder.wheelBag=='true') {
			//-- free if two wheels configured
			if((this.wheelOrder.frontWheel.configured=="true") && (this.wheelOrder.rearWheel.configured=="true")) {
				price = 0;
			} // if

			html += '<table cellspacing="0">';
			html += '<thead>';
			html += '<tr><th colspan="2">Wheel bag</th><th>'+formatCost(price)+'</th></tr>';
			html += '</thead>';
			html += '</table>';
		} // if..else
		this.wheelOrder.wheelBagCost = price;
		$('wheelBagOptionsBill').set('html',html);

		$(wheel+'SubtotalCost').setStyle('display',(subtotal!=0) ? '' : 'none');
		$(wheel+'Cost').set('text','$'+commaNumber(subtotal));

		var totalCost = this.wheelOrder['frontWheel'].usdCost+this.wheelOrder['rearWheel'].usdCost + this.wheelOrder.wheelBagCost;
		$('totalCost').set('text','$' + commaNumber(totalCost));

		$('price').setStyle('display',(totalCost!=0) ? 'block' : 'none');
	}, // generateBill

	copyWheelConfiguration : function(wheelCopyDirection) {
		if(wheelCopyDirection=='rearToFront') {
			this.wheelOrder.frontWheel = $merge(this.wheelOrder.rearWheel);

			//-- front wheels don't have "drives"
			this.wheelOrder.frontWheel.driveSystem			= "";
			this.wheelOrder.frontWheel.driveSystemCost		= 0;
			this.wheelOrder.frontWheel.addCassette			= false;
			this.wheelOrder.frontWheel.sramRedCassetteModel	= '';

			this.makeFrontWheelTabActive();
			this.generateBill('frontWheel');
		} else {
			this.wheelOrder.rearWheel = $merge(this.wheelOrder.frontWheel);
			this.wheelOrder.rearWheel.configured			= "configuring"; //-- need to configure drive

			//-- make sure rear wheel drive is in an neutral initial state
			this.wheelOrder.rearWheel.driveSystem			= "";
			this.wheelOrder.rearWheel.driveSystemCost		= 0;
			this.wheelOrder.rearWheel.addCassette			= false;
			this.wheelOrder.rearWheel.sramRedCassetteModel	= '';

			this.makeRearWheelTabActive();
			this.generateBill('rearWheel');
		} // if..else
		this.step1();
	}, // copyWheelConfiguration

	clearWheelConfiguration : function(wheel) {
		this.wheelOrder[wheel] = this.blankWheel;
		this.initialize();
	}, // clearWheelConfiguration

	//-- ----------------------------------------
	//-- STEP 1 - Choose front/rear wheel
	//-- ----------------------------------------
	step1 : function() {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step1');

		$('slider').setStyle('top',0*VIEWPORTDELTA);

		//---------------------------------

		if(this.wheelOrder.frontWheel.configured=="false") {
			$('frontWheelSelectedImage').setProperty('src','_media/images/common/nowheelselected.gif');
			$('frontWheelSelectedImage').className = 'wheel';
		} else {
			$('frontWheelSelectedImage').setProperty('src',this.wheelGraphicPath+this.wheelModel['frontWheel'][this.wheelOrder['frontWheel'].modelIdx].rimOptions[this.wheelOrder['frontWheel'].rimStyle]);
			$('frontWheelSelectedImage').className = '';
		} // if..else
		if(this.wheelOrder.rearWheel.configured=="false") {
			$('rearWheelSelectedImage').setProperty('src','_media/images/common/nowheelselected.gif');
			$('rearWheelSelectedImage').className = 'wheel';
		} else {
			$('rearWheelSelectedImage').setProperty('src',this.wheelGraphicPath+this.wheelModel['rearWheel'][this.wheelOrder['rearWheel'].modelIdx].rimOptions[this.wheelOrder['rearWheel'].rimStyle]);
			$('rearWheelSelectedImage').className = '';
		} // if..else

		if((this.wheelOrder.frontWheel.configured=="false") && (this.wheelOrder.rearWheel.configured=="false")) {
			this.wheelOrder.wheelBag = 'false';
			this.wheelOrder.wheelBagCost = 0;
		} // if..else

		//---------------------------------

		if(this.wheelOrder.frontWheel.configured=="true") {
			$('copyFrontToRear').setStyle('display', 'block');
			$('frontWheelStateButton').addClass('wheelButtonFrontSelected');
		} else {
			$('copyFrontToRear').setStyle('display', 'none');
			$('frontWheelStateButton').removeClass('wheelButtonFrontSelected');
		} // if..else

		//-- disk based models cannot be front wheels - do not allow copying
		if(this.wheelOrder.rearWheel.configured=="true" && !this.wheelModel.rearWheel[this.wheelOrder.rearWheel.modelIdx].isDiskBased) {
			$('copyRearToFront').setStyle('display', 'block');
		} else {
			$('copyRearToFront').setStyle('display', 'none');
		} // if..else

		if(this.wheelOrder.rearWheel.configured=="true") {
			$('rearWheelStateButton').addClass('wheelButtonRearSelected');
		} else {
			$('rearWheelStateButton').removeClass('wheelButtonRearSelected');
		} // if..else

		//---------------------------------

		$('copyFrontToRear').onclick = function() {
			confirmConfigurationCopyPlan.wheelCopyDirection = 'frontToRear';
			dialogManager(confirmConfigurationCopyPlan);
		}.bind(this);

		$('copyRearToFront').onclick = function() {
			confirmConfigurationCopyPlan.wheelCopyDirection = 'rearToFront';
			dialogManager(confirmConfigurationCopyPlan);
		}.bind(this);

		//---------------------------------

		//-- do both so Titanium quick releases find their way onto the list
		this.generateBill('frontWheel');
		this.generateBill('rearWheel');

		//---------------------------------

		$('selectFrontWheel').onclick = function() {
			this.wheelOrder.frontWheel.configured = (this.wheelOrder.frontWheel.configured)=="true" ? "true" : "configuring";
			this.makeFrontWheelTabActive();
			this.generateBill('frontWheel');
			this.generateBill('rearWheel');

			this.step2('frontWheel');
			return false; // for href="#" foiling
		}.bind(this); // onclick..selectFrontWheel

		$('selectRearWheel').onclick = function() {
			this.wheelOrder.rearWheel.configured = (this.wheelOrder.rearWheel.configured)=="true" ? "true" : "configuring";
			this.makeRearWheelTabActive();
			this.generateBill('frontWheel');
			this.generateBill('rearWheel');

			this.step2('rearWheel');
			return false; // for href="#" foiling
		}.bind(this); // onclick..selectFrontWheel
	}, // step1

	//-- ----------------------------------------
	//-- STEP 2 - Choose rim - Tubular, Clincher
	//-- ----------------------------------------
	step2 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step2');

		$('slider').setStyle('top',1*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		$('step2Prev').setStyle('display',(this.wheelOrder[wheel].configured=="true") ? 'block' : 'none');

		$('step2').removeClass('frontWheel').removeClass('rearWheel');
		$('step2').addClass(wheel);

		$('discNotTrackCompatible').setStyle('display',(wheel=='rearWheel') ? 'block' : 'none');

		setRadioButton('rimStyle', this.wheelOrder[wheel].rimStyle);
		this.updateStep2Wheels(wheel);

		$('wheelTypePrevious').onclick = function() {
			this.wheelOrder[wheel].modelIdx = (this.wheelOrder[wheel].modelIdx==0) ? $A(this.wheelModel[wheel]).length-1 : (this.wheelOrder[wheel].modelIdx-1) % $A(this.wheelModel[wheel]).length;
			this.wheelOrder[wheel].modelName = this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].label;

			this.updateStep2Wheels(wheel);
		}.bind(this);
		$('wheelTypeNext').onclick = function() {
			this.wheelOrder[wheel].modelIdx = (this.wheelOrder[wheel].modelIdx+1) % $A(this.wheelModel[wheel]).length;
			this.wheelOrder[wheel].modelName = this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].label;

			this.updateStep2Wheels(wheel);
		}.bind(this);

		$$('#step2 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].rimStyle = getRadioButton('rimStyle');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step2Next').onclick = function() {
			if(getRadioButton('rimStyle')!="") {
				if(wheel=='rearWheel') {
					this.step3(wheel);
				} else {
					this.step4(wheel);
				} // if..else
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step2Prev').onclick = function() {
			this.step1();
			return false;
		}.bind(this);
	}, // step2

	//-- ----------------------------------------
	//-- STEP 3 - Choose drive system
	//-- ----------------------------------------
	step3 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step3');

		$('slider').setStyle('top',2*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('driveSystem', this.wheelOrder[wheel].driveSystem);
		$('sramRedCassette').set('checked',this.wheelOrder[wheel].addCassette);
		setRadioButton('sramRedCassetteModel', this.wheelOrder[wheel].sramRedCassetteModel);

		if(getRadioButton('driveSystem')!='Shimano') {
			$('sramRedCassetteOption').removeClass('enabled');
			$('sramRedCassette').set('checked','');
			setRadioButton('sramRedCassetteModel', '');

			$('sramRedCassette').set('disabled','disabled');
			$('cassette_11_23').set('disabled','disabled');
			$('cassette_11_26').set('disabled','disabled');
		} // if

		$('campagnoloDrive').onclick = function() {
			$('sramRedCassetteOption').removeClass('enabled');
			$('sramRedCassette').set('checked','');
			setRadioButton('sramRedCassetteModel', '');

			$('sramRedCassette').set('disabled','disabled');
			$('cassette_11_23').set('disabled','disabled');
			$('cassette_11_26').set('disabled','disabled');
		}.bind(this);
		$('shimanoDrive').onclick = function() {
			$('sramRedCassetteOption').addClass('enabled');

			$('sramRedCassette').set('disabled','');
			$('cassette_11_23').set('disabled','');
			$('cassette_11_26').set('disabled','');
		}.bind(this);
		$('sramRedCassette').onclick = function() {
			setRadioButton('sramRedCassetteModel', '');
		}.bind(this);

		$$('#step3 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].driveSystem			= getRadioButton('driveSystem');
			this.wheelOrder[wheel].addCassette			= $('sramRedCassette').checked;
			this.wheelOrder[wheel].sramRedCassetteModel = getRadioButton('sramRedCassetteModel');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step3Next').onclick = function() {
			if(
				(this.wheelOrder[wheel].driveSystem!="") && (
					(this.wheelOrder[wheel].addCassette) && (getRadioButton('sramRedCassetteModel')!='')
					||
					(!this.wheelOrder[wheel].addCassette) && (getRadioButton('sramRedCassetteModel')=='')
				)
			) {
				this.step4(wheel);
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step3Prev').onclick = function() {
			this.step2(wheel);
			return false;
		}.bind(this);
	}, // step3

	//-- ----------------------------------------
	//-- STEP 4 - Select or design your decal
	//-- ----------------------------------------
	step4 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step4');

		$('slider').setStyle('top',3*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('decalColor', this.wheelOrder[wheel].decalColor);

		if(configurator.wheelOrder[wheel].hasCustomDecal) {
			$('decalDesignSelect').addClass('editDecal');
		} else {
			$('decalDesignSelect').removeClass('editDecal');
		} // if..else

		$$('#step4 input').set({'events': { 'click': function(){
			$('decalDesignSelect').removeClass('editDecal');
			configurator.wheelOrder[wheel].hasCustomDecal = false;
			configurator.wheelOrder[wheel].customDecalOptions = {
				zColor 			: "",
				iColor			: "",
				p1Color			: "",
				p2Color			: "",
				swooshColor		: "",
				strokeColor		: "",
				textColor		: "",
				materialType	: "",
				materialCost	: ""
			} // customDecalOptions

			this.wheelOrder[wheel].decalColor = getRadioButton('decalColor');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('decalDesignSelect').onclick = function() {
			setRadioButton('decalColor', '');
			this.wheelOrder[wheel].decalColor = '';
			wheelTagConfigurationPlan.wheelConfiguration = wheel;
			dialogManager(wheelTagConfigurationPlan);
		}.bind(this);

		$('step4Next').onclick = function() {
			if((this.wheelOrder[wheel].decalColor!="") || this.wheelOrder[wheel].hasCustomDecal) {
				if(this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].isDiskBased) {
					this.step9(wheel);
				} else {
					this.step5(wheel);
				} // if
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step4Prev').onclick = function() {
			if(wheel=='rearWheel') {
				this.step3(wheel);
			} else {
				this.step2(wheel);
			} // if..else
			return false;
		}.bind(this);
	}, // step4

	//-- ----------------------------------------
	//-- STEP 5 - Choose nipple color
	//-- ----------------------------------------
	step5 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step5');

		$('slider').setStyle('top',4*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('nippleColor', this.wheelOrder[wheel].nippleColor);

		$$('#step5 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].nippleColor = getRadioButton('nippleColor');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step5Next').onclick = function() {
			if(this.wheelOrder[wheel].nippleColor!="") {
				this.step6(wheel);
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step5Prev').onclick = function() {
			this.step4(wheel);
			return false;
		}.bind(this);
	}, // step5

	//-- ----------------------------------------
	//-- STEP 6 - Select hub cap color
	//-- ----------------------------------------
	step6 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step6');

		$('slider').setStyle('top',5*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('hubCapColor', this.wheelOrder[wheel].hubCapColor);

		$$('#step6 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].hubCapColor = getRadioButton('hubCapColor');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step6Next').onclick = function() {
			if(this.wheelOrder[wheel].hubCapColor!="") {
				this.step7(wheel);
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step6Prev').onclick = function() {
			this.step5(wheel);
			return false;
		}.bind(this);
	}, // step6

	//-- ----------------------------------------
	//-- STEP 7 - Select hub nut color
	//-- ----------------------------------------
	step7 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step7');

		$('slider').setStyle('top',6*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('hubNutColor', this.wheelOrder[wheel].hubNutColor);

		$$('#step7 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].hubNutColor = getRadioButton('hubNutColor');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step7Next').onclick = function() {
			if(this.wheelOrder[wheel].hubNutColor!="") {
				if(
					(this.wheelOrder[wheel].modelIdx==2 /* ZED 4 */ || this.wheelOrder[wheel].modelIdx==3 /* ZED 8 */)
					&&
					this.wheelOrder[wheel].rimStyle=="Tubular"
				) {
					this.step8(wheel);
				} else {
					this.step9(wheel);
				} // if
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step7Prev').onclick = function() {
			this.step6(wheel);
			return false;
		}.bind(this);
	}, // step7

	//-- ----------------------------------------
	//-- STEP 8 - Select laminate
	//-- ----------------------------------------
	step8 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step8');

		$('slider').setStyle('top',7*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('laminateStyle', this.wheelOrder[wheel].laminateStyle);

		$$('#step8 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].laminateStyle = getRadioButton('laminateStyle');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step8Next').onclick = function() {
			if(this.wheelOrder[wheel].laminateStyle!="") {
				this.step9(wheel);
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step8Prev').onclick = function() {
			this.step7(wheel);
			return false;
		}.bind(this);
	}, // step8

	//-- ----------------------------------------
	//-- STEP 9 - Bearing upgrade
	//-- ----------------------------------------
	step9 : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) pageTracker._trackPageview('/zedtech/customize/completed-step9');

		$('slider').setStyle('top',8*VIEWPORTDELTA);
		$$('.currentWheelTitle').set('text',frontRear[wheel]);

		setRadioButton('bearingStyle', this.wheelOrder[wheel].bearingStyle);

		$$('#step9 input').set({'events': { 'click': function(){
			this.wheelOrder[wheel].bearingStyle = getRadioButton('bearingStyle');
			this.generateBill(wheel);
		}.bind(this) }}); // click

		$('step9Next').onclick = function() {
			if(getRadioButton('bearingStyle')!='') {
				$("sendPrint").setStyle('display','block');
				this.wheelOrder[wheel].configured = "true";
				this.step10(wheel);
			} else {
				dialogManager(completeStepNotificationPlan);
			} // if..else
			return false;
		}.bind(this);
		$('step9Prev').onclick = function() {
			if(this.wheelOrder[wheel].bearingStyle!="") {
				if(this.wheelModel[wheel][this.wheelOrder[wheel].modelIdx].isDiskBased) {
					this.step4(wheel);
				} else if(
					(this.wheelOrder[wheel].modelIdx==2 /* ZED 4 */ || this.wheelOrder[wheel].modelIdx==3 /* ZED 8 */)
					&&
					this.wheelOrder[wheel].rimStyle=="Tubular"
				) {
					this.step8(wheel);
				} else {
					this.step7(wheel);
				} // if
			} // if
			return false;
		}.bind(this);
	}, // step9

	//-- ----------------------------------------
	//-- STEP 10 - Wheel bag
	//-- ----------------------------------------
	step10 : function(wheel) {
		this.trackStatistics(wheel);

		$('slider').setStyle('top',9*VIEWPORTDELTA);

		$('wheelBag').set('checked',this.wheelOrder.wheelBag=='true');

		$$('#step10 input').set({'events': { 'click': function(){
			this.wheelOrder.wheelBag = $('wheelBag').get('checked') ? 'true' : 'false';
			this.generateBill(wheel); //-- doesn't matter which wheel here...
		}.bind(this) }}); // click

		$('step10Next').onclick = function() {
			this.step1();
			return false;
		}.bind(this);
		$('step10Prev').onclick = function() {
			this.step9(wheel);
			return false;
		}.bind(this);
	}, // step10

	trackStatistics : function(wheel) {
		//-- for Google Analytics
		if(pageTracker) {
			//-- STEP 1 - /zedtech/customize/completed-wheel-configuration/{wheelPosition}
			pageTracker._trackPageview(
				'/zedtech/customize/completedWheelConfiguration/' + wheel);

			//-- STEP 2 - /zedtech/customize/wheelModel/{wheelPosition}/{modelName}/{rimStyle}
			pageTracker._trackPageview(
				'/zedtech/customize/wheelModel/' + wheel + '/' + this.wheelOrder[wheel].modelName + '/' +	this.wheelOrder[wheel].rimStyle);

			//-- STEP 3 -/zedtech/customize/driveSystem/{driveSystem}/{addCassette}/{sramRedCassetteModel}
			if(this.wheelOrder[wheel].driveSystem) pageTracker._trackPageview(
				'/zedtech/customize/driveSystem/' + this.wheelOrder[wheel].driveSystem + '/addSramRedCassette_' + this.wheelOrder[wheel].addCassette + '/' + this.wheelOrder[wheel].sramRedCassetteModel
			);

			//-- STEP 4 -/zedtech/customize/hasCustomDecal/{hasCustomDecal}
			pageTracker._trackPageview(
				'/zedtech/customize/hasCustomDecal/' + (this.wheelOrder[wheel].hasCustomDecal ? 'hasCustomDecal' : 'hasStandardDecal')
			);

			//-- STEP 5 -/zedtech/customize/nippleColor/{nippleColor}
			if(this.wheelOrder[wheel].nippleColor) pageTracker._trackPageview(
				'/zedtech/customize/nippleColor/' + this.wheelOrder[wheel].nippleColor
			);

			//-- STEP 6 -/zedtech/customize/hubCapColor/{hubCapColor}
			if(this.wheelOrder[wheel].hubCapColor) pageTracker._trackPageview(
				'/zedtech/customize/hubCapColor/' + this.wheelOrder[wheel].hubCapColor
			);

			//-- STEP 7 -/zedtech/customize/hubNutColor/{hubNutColor}
			if(this.wheelOrder[wheel].hubNutColor) pageTracker._trackPageview(
				'/zedtech/customize/hubNutColor/' + this.wheelOrder[wheel].hubNutColor
			);

			//-- STEP 8 -/zedtech/customize/laminateStyle/{laminateStyle}
			if(this.wheelOrder[wheel].laminateStyle) pageTracker._trackPageview(
				'/zedtech/customize/laminateStyle/' + this.wheelOrder[wheel].laminateStyle
			);

			//-- STEP 9 -/zedtech/customize/bearingStyle/{bearingStyle}
			if(this.wheelOrder[wheel].bearingStyle) pageTracker._trackPageview(
				'/zedtech/customize/bearingStyle/' + this.wheelOrder[wheel].bearingStyle
			);
		} // if..pageTracker exists
	} // trackStatistics
}); // class..wheelConfigurator

//------------------------------------------------------------------------------

var configurator;

window.addEvent('domready', function() {
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if(!isIE6) {
		$$('.zedTip').each(function(el){
			var content = el.title.split('::');
			el.store('tip:title', content[0]);
			el.store('tip:text', content[1]);
		}); // each

		var zedTips = new Tips($$('.zedTip'), {
			className: 'tipContainer',
			showDelay: 200,
			hideDelay: 400,
			fixed: true
		});
	} // if

	if($('steps')) {
		configurator = new wheelConfigurator();

		if(window.location.search) {
			var myRequest = new Request({
				url: '/zedtech/_ws/getorder.php',
				method: 'post',
				onSuccess: function(wsResult){
					var jsonResult = JSON.decode(wsResult);
					if(!jsonResult.success) {
						window.location = 'customize.php'; //-- wha?  start over
					} else {
						configurator.wheelOrder = jsonResult.message;
						configurator.orderId = jsonResult.orderId;

						$("sendPrint").setStyle('display','block');

						configurator.initialize();
					} // if..else
				}
			}).send(window.location.search.substring(1));
		} // if
	} // if
}); // domready

//------------------------------------------------------------------------------
