// JavaScript Document
//web-bivi
var binderDimensions = {};
var capacitySize = {};
var quationAnswers = {};
var mechanismSize = {};
binderDimensions["A3"] = {"page" : {"height":"300","width":"200"},"spine" : {"height":"300","width":"30"},"capacityDimensions" : {"15" : [440,715], "25" : [440,734], "40" : [440,772] }, "capacityLeverArchDimensions" :  {"15" : [440,715], "25" : [440,734], "40" : [440,772] },"binderCSS" : {'2D':{'height' : '60%', 'top' : '22%'},'3D':{'height' : '70%', 'top' : '16%'},'4D':{'height' : '80%', 'top' : '11%'},'LeverArch':{'height' : '150px', 'top' : '10%'}	}};
binderDimensions["A4Prof"] = {"page" : {"height":"250","width":"175"},"spine" : {"height":"250","width":"25"},"capacityDimensions" : {"15" : [311,535], "25" : [ 311,557], "40" : [311,592], "50" : [311,637], "65" : [311,671] },"capacityLeverArchDimensions" :  {"15" : [311,535], "25" : [ 311,557], "40" : [311,613], "50" : [311,631], "65" : [311,643] },"binderCSS" : {'2D':{'height' : '80%', 'top' : '10%'},'3D':{'height' : '85%', 'top' : '8%'},'4D':{'height' : '85%', 'top' : '8%'},'LeverArch':{'height' : '150px', 'top' : '20%'}}};
binderDimensions["A4Land"] = {"page" : {"height":"175","width":"200"},"spine" : {"height":"175","width":"30"},"capacityDimensions" : {"15" : [230,704], "25" : [230,734], "40" : [230,772], "50" : [230,800]},"capacityLeverArchDimensions" :  {"15" : [230,704], "25" : [230,734], "40" : [230,772], "50" : [230,800] },"binderCSS" : {'2D':{'height' : '70%', 'top' : '16%'},'3D':{'height' : '80%', 'top' : '10%'},'4D':{'height' : '80%', 'top' : '10%'},'LeverArch':{'height' : '150px', 'top' : '10%'}}};
binderDimensions["A5"] = {"page" : {"height":"200","width":"150"},"spine" : {"height":"200","width":"20"},"capacityDimensions" : {"15" : [225,400], "25" : [225,417], "40" : [225,456],  "50" : [225,491], "65" : [225,529]},"capacityLeverArchDimensions" :  {"15" : [225,400], "25" : [225,417], "40" : [225,456],  "50" : [225,491], "65" : [225,529]},"binderCSS" : {'2D':{'height' : '80%', 'top' : '10%'},'3D':{'height' : '80%', 'top' : '10%'},'4D':{'height' : '85%', 'top' : '7%'},'LeverArch':{'height' : '150px', 'top' : '14%'}}};


capacitySize["15"] = "26";// { "name": "15" "size": "26" };
capacitySize["25"] = "38";// { "name": "25" "size": "38" };
capacitySize["40"] = "53";//{ "name": "40" "size": "53" };
capacitySize["50"] = "70";//{ "name": "50" "size": "70" };
capacitySize["65"] = "90";//{ "name": "65" "size": "90" };


mechanismSize["2D"] = { "height": 124, "width": 20 };
mechanismSize["3D"] = { "height": 209, "width": 20 };
mechanismSize["4D"] = { "height": 286, "width": 20 };
mechanismSize["lever"] = { "height": 94, "width": 55 };

(function($){				
	$.extend({
		binder:
		{
			display: 
			{
				formatText: function(questionText,answerText)
				{
					if(questionText == 'binder_size')
					{
						binderText = answerText.split(" ");
						returnString = (binderText[1] == "Landscape") ? binderText[0] + ' ' + binderText[1] : binderText[0];
						
					}
					else if(questionText == 'capacity')
					{
						$parts = {};
						if(steps[0].stepOptions[0].text.indexOf(' ') > -1)
						{
							$parts = steps[0].stepOptions[0].text.split(' ');
						}
						else
						{
							$parts[0] = steps[0].stepOptions[0].text;
						}
						$.each($parts, function(key, value) { 
												answerText = answerText.replace(value,'');
												})
						answerText = answerText.replace(' ','').replace('mm','');
						returnString =  answerText + 'mm';
					}
					else if(questionText == 'mechanism')
					{
						mechanismText =  answerText.split(" ");		
						if(answerText.toLowerCase().indexOf('dee') > -1)
						{
							returnString = mechanismText[0]+'D';
						}
						else
						{
							returnString = 'Lever Arch';
						}
					}
					else if(questionText == 'colours')
					{
						returnString = answerText;
						
					}
					else
					{
						returnString = answerText;	
					}
					return returnString;
				},
				help: function(toShow)
				{
					var a = document.createElement("a");
					a.href = "/configurator/help/" + toShow
					a.rel = "lyteframe";
					a.title = "Configurator Notes";
					a.rev = "width: 700px; height: 500px; scrolling: auto;";
					myLytebox.start( a, false, true);	
				},
				changeDisplay: function(clickedItem, menuID)
				{				
				
					currentID = $(clickedItem).attr('id');
					classNames = $(clickedItem)[0].className;
					
					title = $(clickedItem).attr('title');
					numQuestions = $.configurator.getObjectSize(steps[$stepNumber].stepOptions);
					currentQuestion = $.configurator.findCurrentQuestion(menuID, clickedItem,-1)
	
					$answerText = $(clickedItem).parent().attr('id');
					$answerUnformattedText = $(clickedItem).attr('title');
				
					if(classNames.indexOf("current") > -1 || classNames.indexOf("colourList") > -1 )
					{					
						if(steps[$stepNumber].stepOptions.type == "group")
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ",""), "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID}
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");
						}
						else
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames.replace("current", "").replace("headerOption", "").replace("colourList", "").replace("pie_hover","").replace("pie_first-child","").replace(" ",""), "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID}
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");
						}					
					}
					else
					{
						if(steps[$stepNumber].stepOptions.type == "group")
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames, "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID} 				
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");
						}
						else
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames, "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID} 				
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");
						}					
					}
	
					$.display.newConfigMakeActive($(clickedItem), menuID)
				
					switch(menuID)
					{
						case 'binder_size': $.binder.display.changeBinderDisplay(currentID); break;
						case 'mechanism': $.binder.display.changeMechanismDisplay(currentID); break;
						case 'capacity': $.binder.display.changeCapacityDisplay(currentID); break;
						case 'inside_front_pocket': $.binder.display.changePocketImage(currentID, "front", currentQuestion, menuID, "inside"); break;
						case 'inside_back_pocket': $.binder.display.changePocketImage(currentID, "back", currentQuestion, menuID, "inside"); break;
						case 'colours' : $.binder.display.changeColourDisplay(currentID); break;
						case 'encapsulation_clear_overlay' : $.binder.display.changeEncapsulation(currentID, currentQuestion, menuID); break;
						case 'spine_pocket' : $.binder.display.changeSpinePocket(currentID, currentQuestion, menuID, title,answerID); break;
						case 'outer_pocket' : $.binder.display.changePocketImage(currentID, "front", currentQuestion, menuID, "outside"); break;
						case 'encap_printing' : return true; break;
						case 'printing': $.binder.display.changePrintOptions(currentID); break;
					}
					
				},
				changePrintOptions: function(currentID)
				{
					$('.selectedPrint').html($('#'+currentID).text() + ' selected')
				},
				changeBinderDisplay: function(currentID)
				{
					dims = binderDimensions[currentID];
					$('.pageVert').css({'height': dims.page.height+'px','width': dims.page.width+'px' });
					$('.spineVert').css({'height': dims.spine.height+'px','width': dims.spine.width+'px' });
					$.binder.display.updateDimensionsText(currentID);
					steps[0].stepOptions[0].binderReference = currentID;
				},
				updateDimensionsText: function(currentID)
				{
					
					$('.diagram').show();
					$('.illustrationPurposes').css('visibility','visible');
					$('#next_step img').css('visibility','visible');
					dims = binderDimensions[currentID];
									
					if(steps[2].stepOptions[0].capacityKey!=undefined){
						capacityWidth = steps[2].stepOptions[0].capacityKey;
					}
					else{
						capacityWidth = '15';
					}
				
					if(steps[1].stepOptions[0].answerText == 'lever_arch_mechanism')
					{										
						capacityWidthText = (dims.capacityLeverArchDimensions[capacityWidth]==undefined) ? dims.capacityLeverArchDimensions['15'][1] : dims.capacityLeverArchDimensions[capacityWidth][1];
					}
					else
					{
						capacityWidthText = (dims.capacityDimensions[capacityWidth]==undefined) ? dims.capacityDimensions['15'][1] : dims.capacityDimensions[capacityWidth][1];
					}
					$('#productWidth label').html(capacityWidthText+' mm');
					
					$rulerWidth = ((parseInt(dims.page.width)*2) + parseInt($('.spine').css('width')) + 6);
																							
					$('#productWidth').css({'width': $rulerWidth+'px'});
					
					$('#productHeight label').html(dims.capacityDimensions[capacityWidth][0]+' mm').css({'background':'#ffffff','line-height' :'14px','margin-top' : Math.round(((dims.page.height)/2) - 6)+'px'});
					$('#productHeight').css({'height': dims.page.height+'px', 'margin-left':'22px'});
					
					
				},
				changeCapacityDisplay: function(currentID)
				{
					capacityWidth = capacitySize[currentID];
					$('.spine').css({"width": capacityWidth +"px" });
					steps[2].stepOptions[0].capacityKey = currentID;
					$.binder.display.updateDimensionsText(steps[0].stepOptions[0].binderReference);
				},
				changeMechanismDisplay: function(currentID)
				{				
					$('#mechanismImage').attr({"src": "/img/configImgs/mech"+currentID+".png"});
					$('#rivetsImage').attr({"src": "/img/configImgs/rivets"+currentID+".png"});
				},
				changePocketImage: function(currentID, location, currentQuestion, menuID, section)
				{
					
					// Check for the landscape option...
					var myAnswerText = steps[0]["stepOptions"][0]["answerText"];
					var landscapeRegExp = /landscape/;
					var checkLandscape = myAnswerText.search(landscapeRegExp);
					if(section == "inside")
					{
						if($('.pockets .inside').is(':hidden'))
						{
							$.binder.display.showInside();	
						}	
					}
					else
					{
						if($('pockets .outside').is(':hidden'))
						{
							$.binder.display.showOutside();	
						}
					}
					
					
					if(location == "front" || location == "back" )
					{
						// Diagonal pockets for landscape overriden after...
							
						if(currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") == "cdpocket")
						{
							$backgroundImage = 'url(/img/configImgs/'+currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") +'_'+location.toLowerCase().replace(" ", "_").replace(/\)/gi,"").replace(/\(/gi,"")+'.png)';
							if($('.' + location,$('.'+ section)).css("backgroundImage") == $backgroundImage)
							{
								$('.' + location,$('.'+ section)).css({"background-image": 'none'});
								$wrapper = section+'_'+location+'_pocket';
								$.display.makeInactive($('#'+currentID,$('#'+$wrapper)));
								if(location == "back")
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5094, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.newConfigMakeActive($('#'+currentID,$('#'+$wrapper)), 'configurator_wrapper');
							$('.' + location,$('.'+ section)).css({"background-image": $backgroundImage, "background-repeat":"no-repeat"});				
						
							if(location == "back")
							{
								$('.' + location,$('.'+ section)).css({"background-position" : "80% 50%" });
							}
							else
							{
								 $('.' + location,$('.'+ section)).css({"background-position" : "center 50%" });
							}
						}
						else if(currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") == "businesscardholder" || currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") == 'businesscardpocket')
						{
							$backgroundImage = 'url(/img/configImgs/'+currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") +'_'+location.toLowerCase().replace(" ", "_").replace(/\)/gi,"").replace(/\(/gi,"")+'.png)';
							if($('.' + location,$('.'+ section)).css("backgroundImage") == $backgroundImage)
							{
								$('.' + location,$('.'+ section)).css({"background-image": 'none'});
								$wrapper = section+'_'+location+'_pocket';
								$.display.makeInactive($('#'+currentID,$('#'+$wrapper)));
								if(location == "back")
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5094, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.newConfigMakeActive($('#'+currentID,$('#'+$wrapper)), 'configurator_wrapper');
							$('.' + location,$('.'+ section)).css({"background-image": $backgroundImage, "background-repeat":"no-repeat"});				
						
							$('.' + location,$('.'+ section)).css({'background-position' : '14% 94%'});
						}
						else
						{
							binderSizeArray = myAnswerText.split('_');
							if(currentID == "diagonal")
							{
								if(binderSizeArray[1] == "landscape")
								{
									$backgroundImage = 'url(/img/configImgs/' + binderSizeArray[0] + "_" + binderSizeArray[1] + "_" + currentID + "_" + location + ".png)";
									
								}
								else
								{
									$backgroundImage = 'url(/img/configImgs/' +binderSizeArray[0] + "_" + currentID + "_" + location + ".png)";
								}
							}
							else
							{
								$backgroundImage = 'url(/img/configImgs/'+currentID.toLowerCase().replace(/,/gi,"").replace(" ", "_") +'_'+location.toLowerCase().replace(" ", "_").replace(/\)/gi,"").replace(/\(/gi,"")+'.png)';
							}
								
							if($('.' + location,$('.'+ section)).css("backgroundImage") == $backgroundImage)
							{
								$('.' + location,$('.'+ section)).css({"background-image": 'none'});
								$wrapper = section+'_'+location+'_pocket';
								$.display.makeInactive($('#'+currentID,$('#'+$wrapper)));
								if(location == "back")
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5094, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.newConfigMakeActive($('#'+currentID,$('#'+$wrapper)), 'configurator_wrapper');
							$('.' + location,$('.'+ section)).css({"background-image": $backgroundImage, "background-repeat":"no-repeat"});		
						
						
							if(location == "back")
							{
								if(currentID == "diagonal")
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "right bottom" });
								}
								else if(currentID == "horizontal")
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "center center" });
								}
								else
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "center center" });
								}
							}
							else
							{
								if(currentID == "diagonal")
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "left bottom" });
								}
								else if(currentID == "horizontal")
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "center center" });
								}
								else
								{
									$('.' + location,$('.'+ section)).css({"background-position" : "center center" });
								}
							}
						}
	
						
					}
					else
					{
						
					}
				},
				removeColour: function()
				{
					$('.box').css({"background-color":''});
				},
				changeColourDisplay: function(currentID)
				{
					$('.box').css({"background-color":'#'+currentID});
				},
				changeEncapsulation: function(currentID, currentQuestion, menuID)
				{			
					
					$.display.newConfigMakeActive($('#'+currentID,$('#'+menuID)), 'configurator_wrapper');
					
					if(currentID == "of")
					{
						$('.front', $('.outside')).css({"background-image": "url('/img/configImgs/overlayHatch.png')" })
						$('.front', $('.outside')).css({"background-repeat": "no-repeat" })
						$('.front', $('.outside')).css({"background-position": '0 7px' })
						$('.spine', $('.outside')).css({"background-image": "none" })
						$('.back', $('.outside')).css({"background-image": "none" })
					}
					else if(currentID == "ofs")
					{
						$('.front', $('.outside')).css({"background-image": "url('/img/configImgs/overlayHatch.png')" })
						$('.front', $('.outside')).css({"background-repeat": "no-repeat" })
						$('.front', $('.outside')).css({"background-position": '0 7px' })
						$('.spine', $('.outside')).css({"background-image": "url('/img/configImgs/overlayHatch.png')" })
						$('.spine', $('.outside')).css({"background-repeat": "no-repeat" })
						$('.spine', $('.outside')).css({"background-position": '0 7px' })
						
						$('.back', $('.outside')).css({"background-image": "none" })
					}
					else if(currentID == "ef")
					{
						$('.front', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat"})
						$('.spine', $('.outside')).css({"background-image": "none" })
						$('.back', $('.outside')).css({"background-image": "none" })
					}
					else if(currentID == "efs")
					{
						$('.front', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat" })
						$('.spine', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat" })
						$('.back', $('.outside')).css({"background-image": "none" })
					}
					else if(currentID == "efbs")
					{
						$('.front', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat" })
						$('.spine', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat" })
						$('.back', $('.outside')).css({"background-image": "url('/img/configImgs/encpHatch.png')","background-repeat": "repeat" })
					}
					else
					{
						$('.front', $('.outside')).css({"background-image": "none" })
						$('.spine', $('.outside')).css({"background-image": "none" })
						$('.back', $('.outside')).css({"background-image": "none" })
					}	
					
					if(currentID.indexOf('ef') > -1)
					{
						$('#encap_printing_label').show();
						$('#encap_printing').show();
					}
					else
					{
						$('#encap_printing_label').hide();
						$('#encap_printing').hide();
						
						if($answers[1] != undefined)
						{
							$newAns = new Array();
							$newAns[0] = $answers[0];
							$answers = new Array();
							answers = $newAns;
							$('input',$('#encap_printing')).each(function(){
								 $(this).attr('checked', false);
							});
						}
					}
					
					
				},
				changeSpinePocket: function(currentID, currentQuestion, menuID, title,answerID)
				{
						
					$.display.newConfigMakeActive($('#'+currentID,$('#'+menuID)), 'configurator_wrapper');
					if(currentID != 'none')
					{
						firstSub = title.substring( title.indexOf('(') + 1)
						inbetweenBrackets = firstSub.substring(0, firstSub .indexOf(')'))
						
						if(inbetweenBrackets.indexOf('mm') > -1)
						{
							numMills = inbetweenBrackets.replace('mm','');
						}
						else
						{
							firstSub = title.substring(0, title.indexOf('(') - 1)
							numMills = firstSub.replace('mm','').replace(' ','');											
						}
						
						title = title.toLowerCase();
						alignFrom = "";
						if(title.indexOf('top') > -1)
						{
							alignFrom = "top";
						}
						else if(title.indexOf('bottom') > -1 || title.indexOf('base') > -1)
						{
							alignFrom = "bottom";
						}
						else
						{
							alignFrom = "centre";
						}
						$position = "centre";
						
						if(steps[0]['stepOptions']['0']['binderReference'].toLowerCase() == 'a4prof')
						{
							$binderSize = 'a4';
						}
						else if(steps[0]['stepOptions']['0']['binderReference'].toLowerCase() == 'a4land')
						{
							$binderSize = 'a4_landscape';
						}
						else 
						{
							$binderSize = steps[0]['stepOptions']['0']['binderReference'].toLowerCase();
						}
						
						if(numMills < 200)
						{
							pocketSize = '155';
						}
						else if(numMills < 300)
						{
							pocketSize = '225';
						}
						else
						{
							pocketSize = 'full';
						}
						
						spineImage = $binderSize + '_' + steps[2]['stepOptions']['0']['answerText'] + '_' + pocketSize + '_spine.png';
						
						
						steps[0]['stepOptions']['0']['binderReference']
						if(alignFrom == "bottom")
						{
							$position = "bottom";
						}
						else if(alignFrom == "top")
						{
							$position = "top";
						}
						else
						{
							$position = "centre";
						}
						
						$('.spine',$('.outside')).css({'background-image' : "url('/img/configImgs/"+spineImage+"')" });
						$('.spine',$('.outside')).css({'background-repeat' : "no-repeat"});
						$('.spine',$('.outside')).css({'background-position' : $position });
					}
					else
					{
						$('.spine',$('.outside')).css({'background-image' : "none"});
						$('.spine',$('.outside')).css({'background-repeat' : "no-repeat"});
						$('.spine',$('.outside')).css({'background-position' : "center center"});
					}
	
					//$.display.makeInactive($('#'+currentID));
					
				},
				showInside: function()
				{
					$('.diagram .outside').hide();
					$('#outsideLink').removeClass('current');
					$('#insideLink').addClass('current');
					$('.diagram .inside').show();
				},
				showOutside: function()
				{
					$('.diagram .outside').show();
					$('#outsideLink').addClass('current');
					$('#insideLink').removeClass('current');
					$('.diagram .inside').hide();
				},
				showColoursGroups: function(questionText, answerList)
				{
					
					optionsToShow = $.winman.returnVisibleOptions(546);
					$('li', $('#colours')).remove();
					$.each(optionsToShow, function(key, value) { 
														if(value.AnswerText.toLowerCase().indexOf('standard') > -1)
														{
															$.winman.answer(value.AnswerId);
															optionsToShow = $.winman.returnVisibleOptions(547);
															$.binder.display.showColours(questionText, 'standard_range', optionsToShow);
														}
														else
														{
															$.winman.answer(value.AnswerId);
															optionsToShow = $.winman.returnVisibleOptions(547);
															$.binder.display.showColours(questionText, 'recycled_range', optionsToShow);															
														}
														} );
						$('li', $('#colours')).bind('click', function() { $.binder.display.changeDisplay($(this), 'colours'); return false; });
						$('#step4Menu').show();
				},
				showColours: function(questionText, groupRange, answerList)
				{
				
					$.each(answerList, function(key, value)
					{
						
						
						if(value.AnswerText.indexOf('{') > -1)
						{											
							listText = value.AnswerText.split("{");
							answername = $.trim(listText[0]);
							colourCode = listText[1].replace("}","");
						}
						else
						{
							listText = value.AnswerText.split("(");
							answername = $.trim(listText[0]);
							colourCode = listText[1].replace(")","");
						}
						if(groupRange == 'recycled_range')
						{
							hexColourCode = '<span class="rcycld">Recycled</span>';
						}
						else
						{
							hexColourCode = '';
						}
						newHtml = '<li style="background-color:'+colourCode+'" id="'+colourCode.replace("#","")+'" class="'+value.AnswerId.toString()+' colourList" title="'+answername.replace('[','(').replace(']',')')+'">'+answername.replace('[','(').replace(']',')')+' ' + hexColourCode+'</li>';
						$('#colours').append(newHtml)
					})
				
					
					
				},
				makeStepActive: function(stepID)
				{
			
					$currentstep = steps[$stepNumber].id;
					//$('.'+$currentstep,$('.step_nav')).removeClass('next');
					$('.'+$currentstep,$('.step_nav')).addClass('current');
					$('.'+$currentstep,$('.step_nav')).next().addClass('next').removeClass('current');
					$('.'+$currentstep,$('.step_nav')).next().next().removeClass('next');
					$index = $('.'+$currentstep,$('.step_nav')).index()
					
										/*
					try
					{
						pageTracker._trackPageview('/configurator/Vinyl-Binder/Step'+stepID);
					}
					catch(err)
					{
						//console.debug(err)
					}
					*/
				},
				showLoader: function()
				{
					$numTimes = $('#loader').attr('attrlang');
					if($numTimes == undefined)
					{
						$numTimes = 1;	
					}
					else
					{
						$numTimes = parseInt($numTimes) + 1;
					}
					$('#loader').css({'position':'absolute'})
					$('#loader').css("top", (($(window).height() - $('#loader').outerHeight()) / 2) + $(window).scrollTop() + "px");
    				$('#loader').css("left", (($(window).width() - $('#loader').outerWidth()) / 2) + $(window).scrollLeft() + "px");
					$('#loader').css({'z-index':'10'})
					$('#loader').attr({'attrlang': $numTimes});
					$('#loader').show();
				},
				hideLoader: function()
				{				
					$numTimes = $('#loader').attr('attrlang');
					$numTimes = parseInt($numTimes) - 1;
					$('#loader').attr({'attrlang': $numTimes});
					
					if($numTimes == 0)
					{				
						$('#loader').hide();
					}
					setTimeout("$('#productHeight').hide().show()",50);
		
				}
			},
			configurator: 
			{
				fillFileName: function()
				{
					$('#dummyFileName').val($('#configuratorFile').val())
				},
				reprice: function()
				{
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.doReprice()',200);
				},
				doReprice: function()
				{
					quantity = $('#qtyToBuy').val();
					$('#quantityToBasket').val(quantity)
					returnedData = $.winman.reprice(quantity, 'binder')
					if(returnedData != "error")
					{
						strPricePerUnit = returnedData.ConfiguratorRePriceResult.Price;
						strDiscountPerUnit = returnedData.ConfiguratorRePriceResult.Discounted;
						strExtraDiscountPricePerUnit = (returnedData.ConfiguratorRePriceResult.ExtraDiscountPrice != returnedData.ConfiguratorRePriceResult.Discounted) ? returnedData.ConfiguratorRePriceResult.ExtraDiscountPrice : ''
						
						breakPoints = returnedData.ConfiguratorRePriceResult.PriceBreaks;
						if(strDiscountPerUnit != '')
						{
							strBreakPointText = '<li><a href="#" onclick="$.binder.configurator.quickReprice('+quantity+'); return false" title="Order '+quantity+' for &pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'">Order '+quantity+' for <strong>&pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'</strong></a></li>';
						}
						else
						{	
							strBreakPointText = '<li><a href="#" onclick="$.binder.configurator.quickReprice('+quantity+'); return false" title="Order '+quantity+' for &pound;'+parseFloat(strPricePerUnit).toFixed(2)+'">Order '+quantity+' for <strong>&pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'</strong></li></a>';
						}
						$missingBreakPoint = false;
						$.each(breakPoints.PriceBreak, function(key, values) {
												if(values.Discounted != undefined)
												{
													if(parseFloat(values.Discounted) < 5000)
													{
														strBreakPointText = strBreakPointText +'<li><a href="" onclick="$.binder.configurator.quickReprice('+values.Quantity+'); return false" title="Order '+ values.Quantity+' for &pound;'+parseFloat(values.Discounted).toFixed(2)+'">Order '+values.Quantity+' for <strong>&pound;'+parseFloat(values.Discounted).toFixed(2)+' (&pound;' + (parseFloat(values.Discounted) /  values.Quantity).toFixed(2) + ' per unit)</strong></a></li>';
													}
													else
													{
														$missingBreakPoint = true;
													}
												}
												else
												{
													if(parseFloat(values.Price) < 5000)
													{
														strBreakPointText = strBreakPointText +'<li><a href="" onclick="$.binder.configurator.quickReprice('+values.Quantity+'); return false" title="Order '+ values.Quantity+' for &pound;'+parseFloat(values.Price).toFixed(2)+'">Order '+values.Quantity+' for <strong>&pound;'+parseFloat(values.Price).toFixed(2)+' (&pound;' + (parseFloat(values.Price) /  values.Quantity).toFixed(2) + ' per unit)</strong></a></li>';
													}
													else
													{
														$missingBreakPoint = true;
													}
												}
										 
									 
									 })
						
						
						if(strDiscountPerUnit != '')
						{
							strPricePerUnit = strDiscountPerUnit;
						}
						
						if(strExtraDiscountPricePerUnit != '')
						{
							
							$('#discount').parent().show();
							$('#discountPricePerUnit').html("&pound;" + (parseFloat(strPricePerUnit) / quantity).toFixed(2));
							$('#discountPricePerUnit').parent().show();
							$('#discountPrice').parent().show();
							$('#discountPrice').html("&pound;" + (parseFloat(strPricePerUnit).toFixed(2)));
							$('#beforeDiscount').val(parseFloat(strPricePerUnit).toFixed(2));
							strPricePerUnit = strExtraDiscountPricePerUnit;
						}
						else
						{
							$('#discountPricePerUnit').parent().hide();
							$('#discount').parent().hide();
							$('#discountPrice').parent().hide();
							$('#beforeDiscount').val('');
						}
						
						$('#pricePerUnit').html("&pound;" + (parseFloat(strPricePerUnit) / quantity).toFixed(2));
						$('#priceTotalCost').html("&pound;" + parseFloat(strPricePerUnit).toFixed(2));
						$('#BasketItemPrice').val(strPricePerUnit);
						
						if(parseFloat(strPricePerUnit).toFixed(2) >= 5000)
						{
							$('#addToBasket').hide();
							$('#add_to_basket').hide();
							$('.breakpointText').hide();
							$('.howtosave').hide();
							$('#pricePerUnit').parent().hide();
							$('.totalCost').hide();
							$('#pdfLink').hide();
							$('.AltBreakPoints').show();
							$('.howtosave').hide();
							$('.bulkBuyTitle').hide();
							$('.total',$('.price-box')).hide();
						}
						else
						{
							$('#addToBasket').show();
							$('#add_to_basket').show();
							$('.breakpointText').show();
							$('.howtosave').show();
							$('#pricePerUnit').parent().show();
							$('.totalCost').show();
							$('#pdfLink').show();
							$('.AltBreakPoints').hide();
							$('.howtosave').show();
							$('.bulkBuyTitle').show();
							$('.total',$('.price-box')).show();
						}
						
						/*if($('#discount').is(':visible'))
						{											 
							$discount = $('#discount').html()
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:10px">Price breakpoints may not reflect the '+$discount+' web discount</span>')
							if($missingBreakPoint == true)
							{
								$('.breakpointText').html($('.breakpointText').html() + '<br /><span style="font-size:10px">' + $('span',$('.AltBreakPoints')).html() + '</span>');
							}
						}
						else
						{
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:12px">Please call the Sales Team on 017213 584091 to see if we can offer you a discount</span>');	
						}*/
						$('.breakText').remove();
						
						if($('#discount').is(':visible'))
						{											 
							$discount = $('#discount').html()
							$('.breakpointText').html(strBreakPointText);
							 $('.breakpointText').after('<span style="font-size:10px; color: #7C8C96" class="breakText">Price breakpoints may not reflect the '+$discount+' discount</span>');
							if($missingBreakPoint == true)
							{
							
								$('.breakText').remove();
								$('.breakpointText').after('<br /><span style="font-size:10px; color: #7C8C96" class="breakText">' + $('span',$('.AltBreakPoints')).html() + '</span>');
							}
						}
						else
						{
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:12px; color: #7C8C96 " class="breakText">Please call the Sales Team on 017213 584091 to see if we can offer you a discount<br>Standard delivery times are 10 working days</span>');
						}
						$('.breakpointText').after('<br /><br /><span style="font-size:10px; color: #7C8C96">Standard delivery times are 10 working days</span>');
						
						/*
						
						$('#pricePerUnit').html("&pound;" + (parseFloat(strPricePerUnit) / quantity).toFixed(2));
						$('#priceTotalCost').html("&pound;" + parseFloat(strPricePerUnit).toFixed(2));
						$('#BasketItemPrice').val(strPricePerUnit);
						
						//Over-ride total with discount amount if necessary
						if(strDiscountPerUnit != '')
						{
							$('#pricePerUnit').html("&pound;" + (parseFloat(strDiscountPerUnit) / quantity).toFixed(2));
							$('#priceTotalCost').html("&pound;" + parseFloat(strDiscountPerUnit).toFixed(2));
							$('#BasketItemPrice').val(strDiscountPerUnit);
						}
						*/
						//$('#BasketConfigKey').val(returnedData.ConfiguratorRePriceResult.Configuration);
						
						
				/*		$('#discount').parent().show();
						$('#discountPrice').parent().show();
						$('#discountPrice').html(returnedData.ConfiguratorRePriceResult.DiscountPrice)*/
					}
					else
					{
							
					}	
					
					$.binder.display.hideLoader();
				},
				submitAnswers: function()
				{				
					numAnswers = $.configurator.getObjectSize($answers);
					$.each($answers, function(key, value) { 
						
							if(value != null)
							{
								answer = $.winman.answer(value.id.toString())
								
								questionNum = $.configurator.findCurrentQuestion(value.menuID, "", -1);
								
								groupNum = $.binder.configurator.getGroupFromQuestion(value.menuID, -1);
								
								if(steps[$stepNumber].stepOptions[questionNum] != undefined && steps[$stepNumber].stepOptions[questionNum].type == "question")
								{
									questionText = steps[$stepNumber].stepOptions[questionNum].questionText
									answerText = $.binder.display.formatText(questionText,value.unformattedText)
									$('.'+questionText,$('.chosen')).show();
									$('span',$('.'+questionText,$('.chosen'))).html(answerText)																		 
									steps[$stepNumber].stepOptions[questionNum].answer = value.id;
									steps[$stepNumber].stepOptions[questionNum].answerText = value.text
									steps[$stepNumber].stepOptions[questionNum].text = answerText
								}
								else
								{						
									
									groupNum = $.binder.configurator.getGroupFromQuestion(value.menuID, -1);
									questionText = steps[$stepNumber].stepOptions[groupNum].stepOptions[questionNum].questionText
									answerText = $.binder.display.formatText(questionText,value.unformattedText)
									if(questionText.indexOf('pocket') > -1)
									{
										
										if(questionText.indexOf('inside') > -1)
										{
											$('.insidePockets',$('.chosen')).show();
											$('.pockets',$('.insidePockets',$('.chosen'))).show();
											$('.'+questionText,$('.insidePockets',$('.chosen'))).show();
											$('span',$('.'+questionText,$('.insidePockets',$('.chosen')))).html(answerText)					
										}
										else
										{
											$('.outsidePockets',$('.chosen')).show();
											$('.pockets',$('.outsidePockets',$('.chosen'))).show();
											$('.'+questionText,$('.outsidePockets',$('.chosen'))).show();
											$('span',$('.'+questionText,$('.outsidePockets',$('.chosen')))).html(answerText)	
										}
										
									}
									else if(questionText == 'printing')
									{
										$('span',$('.'+questionText,$('.chosen'))).html(answerText);
										if($originalFile != undefined)
										{
											$('span',$('.artwork',$('.chosen'))).html('<a target="_blank" href="/uploaded/userImages/'+$uploadeFile+'">View</a>');
											//$('span',$('.artwork',$('.chosen'))).html($originalFile);
											$('.artwork',$('.chosen')).show();
										}
									}
									else
									{
										$('span',$('.'+questionText,$('.chosen'))).html(answerText);
									}
									$('.'+questionText,$('.chosen')).show();
									steps[$stepNumber].stepOptions[groupNum].stepOptions[questionNum].answer = value.id;
									steps[$stepNumber].stepOptions[groupNum].stepOptions[questionNum].answerText = value.text;
									steps[$stepNumber].stepOptions[groupNum].stepOptions[questionNum].text = value.unformattedText;							
								}
							}
						})
					$answers = {};
					
				},
				getGroupFromQuestion: function(questionText, subNumber)
				{
					//to do need to search object for question text and return the group key
					if(questionText == "encapsulation_clear_overlay" || questionText == "encap_printing")
					{
						return 0;
					}
					else if(questionText == "outer_pocket" || questionText == "spine_pocket" || questionText == "inside_front_pocket" || questionText == "inside_back_pocket")
					{
						return 1;
					}
					else
					{
						return 2;	
					}
					/*
				if(subNumber == -1)
					{
						theArray = 	steps[$stepNumber].stepOptions
					}
					else
					{					
						theArray = 	steps[$stepNumber].stepOptions[subNumber].stepOptions;
					}
					
					counter = 0
					$.each(theArray,function(key, values)
										  {
												if(values.type == "question")	
												{
												}
												else
												{
													 $.binder.configurator.getGroupFromQuestion(questionText,counter);
													 counter = counter + 1
												}
										  }
										  )*/
				},								
				nextStep: function()
				{
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.donextStep()',200);
					//$('#productHeight').hide().show();
				},
				donextStep: function()
				{
					quantity = '';				
					if($('input',$('.menuContent:visible')).length ==  1)
					{
						numAnswers = $.configurator.getObjectSize($answers);
						if($('input',$('.menuContent:visible')).val() != "")
						{
							quantity = $('input',$('.menuContent:visible')).val();		
						}
					}
	
					if($stepNumber==5 && (quantity=='' || quantity==0))
					{
						alert("You need to select an answer for this step");
					} //check quantity is not null on the final step or otherwise check required fields for the winman stage
					else if($stepNumber!=5 && $('.menuContent:visible').is('.required') && $.configurator.getObjectSize($answers) == 0)
					{
						alert("You need to select an answer for this step");
					}
					else if($stepNumber == 4)
					{
						$numSubSteps = $.configurator.getObjectSize(steps[4]['stepOptions'][$subStepNumber]['stepOptions'])
						
						if($subStepNumber == 0)
						{
							$nextStep = true;
							if($answers[0]['text'].indexOf("encap") > -1)
							{
								if($answers[1] == undefined)
								{
									alert("You need to select an printing option.");
									$nextStep = false;
								}
							}
							else
							{
								if($answers[1] != undefined)
								{
									$answers[1] = null;
								}
							}
							if($nextStep == true)
							{
								$subStepNumber++;
								$menu = steps[4]['stepOptions'][$subStepNumber]['name'].toLowerCase();
								if($menu == 'print')
								{
									$menu = 'printing';
								}
								$.binder.configurator.changeOptions($menu, null);
							}
						}
						else if($subStepNumber == 1)
						{
							$dontCount = 0;
							$.each(steps[4]['stepOptions'][$subStepNumber]['stepOptions'], function(key, values)
																									{
																											if(values.noanswer != undefined && values.noanswer == true)
																											{
																												$dontCount = $dontCount + 1;
																											}
																									} );
							$numSubSteps = $numSubSteps - $dontCount;
							if($.configurator.getObjectSize($answers) < $numSubSteps)
							{
								alert('Please select an option for all available pockets types');
							}
							else
							{
								$subStepNumber++;
								$menu = steps[4]['stepOptions'][$subStepNumber]['name'].toLowerCase();
								if($menu == 'print')
								{
									$menu = 'printing';
								}							
								$.binder.configurator.changeOptions($menu, null);
							}
						}
						else
						{
							$.binder.configurator.submitAnswers();
							if(extraAnswer == true)
							{
							//	$.winman.answer(5125);
								extraAnswer = false;
							}
							$('.menuContent').hide();
							$answers = {};
							$.binder.display.makeStepActive('qty');
							$('.qty',$('.step_nav')).addClass('current');
							$('.qty',$('.step_nav')).next().addClass('next');
							$('#quantityinput').show();
							$stepNumber = $stepNumber + 1;
							$.binder.configurator.setUpHelpLink('quantity')
							$('h2.title').html($('.title',$('.menuContent:visible')).html())
						}
					}
					else
					{
						//$('#start_over').show();
						if($('.menuContent:visible').attr("id") == "quantityinput")
						{	
						//	alert('check if colour print and then check qty');
							 $quantity = $('#desiredQty').val()
							 if(isNaN($quantity))
							 {
								 alert('Please enter a number');
								 $.binder.display.hideLoader();
								 return false;
							 }
							 else if($quantity.indexOf('.') > -1 || parseInt($quantity) < 1)
							 {
								 alert("Please enter a whole number greater than 1");
								 $.binder.display.hideLoader();
								 return false;
							 }
						}
						if($stepNumber == 5)
						{
							$.binder.configurator.calculatePrice($quantity)
							$.binder.configurator.setUpHelpLink('quote');
							$('.nav-buttons').addClass('quote');
						}
						else
						{
							$('.nav-buttons').removeClass('quote');
							if($stepNumber == 3)
							{
								if($answers[0]['unformattedText'].indexOf('Standard') != -1)
								{
									ColourAnswerId = 5101;
								}
								else
								{
									ColourAnswerId = 5102;
								}
								$.winman.answer(ColourAnswerId);
							}
							
							$.binder.configurator.submitAnswers();
							
							$stepNumber = $stepNumber + 1;
							$answers = {};
							$.binder.configurator.loadMenu(steps[$stepNumber]);
						}
					}
				
					$.binder.display.hideLoader();
				},
				doStartOver: function()
				{
					$(this).dialog("close");
					$('#next_step').show();
					$('#config_prod_preview').css({'visibility':'hidden'});	
					$('.illustrationPurposes').css('visibility','hidden');
					
					$('#configuratorFile').val('');
					$('#uploadMessage').html('');
					$uploadeFile = null;
					$originalFile = null;
					$('#dummyFileName').val('');
					
					
					$.configurator.getQuestionsList();
					if($error == true)
					{
						alert("There has been a problem with the configurator.  Please try again later")	
					}
					else
					{
						$.binder.configurator.createStepList();
						$('.menuContent').hide();
						$('.box').css({"background-color":"#EEEEEE", 'background-image':''});
						$('#mechanismImage').attr({"src": "/img/configImgs/mech.png"});
						$('#rivetsImage').attr({"src": "/img/configImgs/rivets.png"});
					
						$stepNumber = 0;
						$.binder.configurator.loadMenu(steps[$stepNumber]);
					}
								 
					$.binder.display.hideLoader();
				},
				previousStep: function()
				{
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.doPreviousStep()',200)
				},
				doPreviousStep: function()
				{
					$('.dl-quote').hide();
					$answersToDelete = steps[$stepNumber];
					$answers = {};
					switch($stepNumber)
					{
						case 0:
							window.location.href = '/configurator';
							break;
						case 1: 
								$('#config_prod_preview').css({'visibility':'hidden'});
								$('.illustrationPurposes').css('visibility','hidden');
								$('#mechanismImage').attr({"src": "/img/configImgs/mech.png"});
								$('#rivetsImage').attr({"src": "/img/configImgs/rivets.png"});
								steps[1]['stepOptions'][0]['answer'] = null;
								steps[1]['stepOptions'][0]['answerText'] = null;
								steps[1]['stepOptions'][0]['text'] = null;
								$stepNumber = $stepNumber -1;
								$.binder.configurator.loadMenu(steps[$stepNumber])
								$('.mechanism',$('.chosen')).hide();
								$('.binder_size',$('.chosen')).hide();
								
							break;
						case 2: 
								$('#mechanismImage').attr({"src": "/img/configImgs/mech.png"});
								$('#rivetsImage').attr({"src": "/img/configImgs/rivets.png"});
								steps[1]['stepOptions'][0]['answer'] = null;
								steps[1]['stepOptions'][0]['answerText'] = null;
								steps[1]['stepOptions'][0]['text'] = null;
								dims = binderDimensions[steps[0]['stepOptions'][0]['binderReference']];
								steps[2]['stepOptions'][0]['answer'] = null;
								steps[2]['stepOptions'][0]['answerText'] = null;
								steps[2]['stepOptions'][0]['text'] = null;
								steps[2]['stepOptions'][0]['capacityKey'] = null;
								$('.spineVert').css({'height': dims.spine.height+'px','width': dims.spine.width+'px' });
								$.binder.display.updateDimensionsText(steps[0].stepOptions[0].binderReference);
								$stepNumber = $stepNumber -1;
								$.binder.configurator.loadMenu(steps[$stepNumber]);
								$('.mechanism',$('.chosen')).hide();
								$('.capacity',$('.chosen')).hide();
							break;
						case 3:
								dims = binderDimensions[steps[0]['stepOptions'][0]['binderReference']];
								steps[2]['stepOptions'][0]['answer'] = null;
								steps[2]['stepOptions'][0]['answerText'] = null;
								steps[2]['stepOptions'][0]['text'] = null;
								steps[2]['stepOptions'][0]['capacityKey'] = null;
								steps[4]['stepOptions'][0]['stepOptions'][1]['answer'] = null;
								steps[4]['stepOptions'][0]['stepOptions'][1]['answerText'] = null;
								steps[4]['stepOptions'][0]['stepOptions'][1]['text'] = null	;
								
								$('.spineVert').css({'height': dims.spine.height+'px','width': dims.spine.width+'px' });
								$.binder.display.updateDimensionsText(steps[0].stepOptions[0].binderReference);
								
								$('.box').css({"background-color":'#EEEEEE'});
								$stepNumber = $stepNumber -1;
	
								$('.front', $('.outside')).css({"background-image": "none" });
								$('.spine', $('.outside')).css({"background-image": "none" });
								$('.back', $('.outside')).css({"background-image": "none" });
								$.binder.configurator.loadMenu(steps[$stepNumber]);
								$('input',$('#encap_printing')).each(function(){
								 	$(this).attr('checked', false);
								});
								$('.encapsulation_clear_overlay',$('.chosen')).hide();
								$('.insidePockets',$('.chosen')).hide();
								$('.printing',$('.chosen')).hide();
								$('.colours',$('.chosen')).hide();
								$('.capacity',$('.chosen')).hide();
							break;
						case 4:
								$currentStep = $stepNumber;
								if($subStepNumber == 0)
								{
									$stepNumber = $stepNumber -1;
									$('.box').css({"background-color":'#EEEEEE'});
								}
								else
								{
									$subStepNumber = $subStepNumber - 1;
								}
								switch($subStepNumber)
								{
									case 0: 
										$answers = {};
										$answers[542] = {"id": 5084, "text":'None',"unformattedText":'None', "menuID":0}
										$answers[543] = {"id": 5089, "text":'None',"unformattedText":'None', "menuID":1}
										$answers[544] = {"id": 5094, "text":'None',"unformattedText":'None', "menuID":2}
										$.binder.configurator.submitAnswers();
										steps[4]['stepOptions'][0]['stepOptions'][1]['answer'] = null;
										steps[4]['stepOptions'][0]['stepOptions'][1]['answerText'] = null;
										steps[4]['stepOptions'][0]['stepOptions'][1]['text'] = null;
										
										$('.front', $('.inside')).css({"background-image": "none" });
										$('.spine', $('.inside')).css({"background-image": "none" });
										$('.back', $('.inside')).css({"background-image": "none" });
										$('.front', $('.outside')).css({"background-image": "none" });
										$('.spine', $('.outside')).css({"background-image": "none" });
										$('.back', $('.outside')).css({"background-image": "none" });
										$('input',$('#encap_printing')).each(function(){
											 $(this).attr('checked', false);
										});
										
										$('.encapsulation_clear_overlay',$('.chosen')).hide();
										$('.insidePockets',$('.chosen')).hide();
										$('.outsidePockets',$('.chosen')).hide();
										$('.printing',$('.chosen')).hide();
									break;
									case 1:  
										$('#configuratorFile').val('');
										$uploadeFile = null;
										$originalFile = null;
										$('#dummyFileName').val('');
										
										$front = true;
										$spine = true;
										$back = true;
										$answers = {};
										$answers[542] = {"id": 5084, "text":'None',"unformattedText":'None', "menuID":0}
										$answers[543] = {"id": 5089, "text":'None',"unformattedText":'None', "menuID":1}
										$answers[544] = {"id": 5094, "text":'None',"unformattedText":'None', "menuID":2}
										switch(steps[4]['stepOptions'][0]['stepOptions'][0]['answerText'])
										{
											case 'clear_overlay_front': 
													$front = false; 
												break;
											case 'clear_overlay_front_spine': 
													$front = false;
													$spine = false; 
												break;
											case 'encap_front': 
													$front = false;
													$spine = false; 
												break;
											case 'encap_front_spine': 
													$front = false;
													$spine = false;
												break;
											case 'encap_front_back_spine': 
													$front = false;
													$spine = false;
													$back = false;
												break;
										}
										$('.front', $('.inside')).css({"background-image": "none" });
										$('.spine', $('.inside')).css({"background-image": "none" });
										$('.back', $('.inside')).css({"background-image": "none" });
										
										if($front == true)
										{
											$('.front', $('.outside')).css({"background-image": "none" });
										}
										if($spine == true)
										{
											$('.spine', $('.outside')).css({"background-image": "none" });
										}
										if($back == true)
										{
											$('.back', $('.outside')).css({"background-image": "none" });
										}
										
										$('.insidePockets',$('.chosen')).hide();
										$('.outsidePockets',$('.chosen')).hide();
										$('.printing',$('.chosen')).hide();
									break;	
									case 2:
										$('#configuratorFile').val('');
										$uploadeFile = null;
										$originalFile = null;
										$('#dummyFileName').val('');
										
										$('.printing',$('.chosen')).hide();
									break;
								}
								
								if($currentStep == $stepNumber)
								{
									$menu = steps[4]['stepOptions'][$subStepNumber]['name'].toLowerCase();
									if($menu == 'print')
									{
										$menu = 'printing';
									}
	
									$.binder.configurator.changeOptions($menu, null)
								}
								else
								{
									$front = true;
									$spine = true;
									$back = true;
									
									switch(steps[4]['stepOptions'][0]['stepOptions'][0]['answerText'])
									{
										case 'clear_overlay_front': 
												$front = false; 
											break;
										case 'clear_overlay_front_spine': 
												$front = false;
												$spine = false; 
											break;
										case 'encap_front': 
												$front = false;
												$spine = false; 
											break;
										case 'encap_front_spine': 
												$front = false;
												$spine = false;
											break;
										case 'encap_front_back_spine': 
												$front = false;
												$spine = false;
												$back = false;
											break;
									}
									
									
									$('.front', $('.inside')).css({"background-image": "none" });
									$('.spine', $('.inside')).css({"background-image": "none" });
									$('.back', $('.inside')).css({"background-image": "none" });
									
									if($front == true)
									{
										$('.front', $('.outside')).css({"background-image": "none" });
									}
									if($spine == true)
									{
										$('.spine', $('.outside')).css({"background-image": "none" });
									}
									if($back == true)
									{
										$('.back', $('.outside')).css({"background-image": "none" });	
									}
									
									$.binder.configurator.loadMenu(steps[$stepNumber]);
								}
								
							break;
							$('.printing',$('.chosen')).hide();
							$('.selectedPrint').html('');
							$('#uploadMessage').html('');
							$('.fileBrower').val('');
								
						case 5:
								
								$('#order_sample').hide();
								$('#add_to_basket').hide();
								$('.nav-buttons').removeClass('quote');
								$stepNumber = $stepNumber -1;
								$.binder.configurator.loadMenu(steps[$stepNumber]);
								$subStepNumber = $.configurator.getObjectSize(steps[4]['stepOptions']) - 1;
								$menu = steps[4]['stepOptions'][$subStepNumber]['name'].toLowerCase();
								if($menu == 'print')
								{
									$menu = 'printing';
								}
								$('.selectedPrint').html('');
								$('#uploadMessage').html('');
								$('.fileBrower').val('');
								$.binder.configurator.changeOptions($menu, null);								
								$('.artwork',$('.chosen')).hide();
								$('.printing',$('.chosen')).hide();
							break;
							
					}
				
					$('#next_step').show();	
					
					$.binder.display.hideLoader();
				},			
				startOver: function()
				{
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.doStartOver()',200);
				},
				setupConfigurator: function()
				{
					$productID = 31074;
					$itemType = 'binder';
					$('li',$('.chosen')).hide();
					$('.chosen > li:eq(0)').show();
					$stepNumber = 0;
					$.binder.display.showLoader();
					$('#next_step').show();
					$('.menuContent').hide();
					$('.diagram').hide();
					$('.illustrationPurposes').css('visibility','hidden');
					$('.dl-quote').hide();
					$('#order_sample').hide();
					$('#add_to_basket').hide();
					
					$('#mechanismImage').attr({"src": "/img/configImgs/mech.png"});
					$('#rivetsImage').attr({"src": "/img/configImgs/rivets.png"});
					
					$('#configuratorFile').val('');
					$uploadeFile = null;
					$originalFile = null;
					$('#dummyFileName').val('');
					
					$.configurator.getQuestionsList();
					if($error == true)
					{
						alert("There has been a problem with the configurator.  Please try again later");	
					}
					else
					{
						
						$.binder.configurator.createStepList();
						$numquestions = $.configurator.getObjectSize(steps);
						$.binder.configurator.loadMenu(steps[$stepNumber]);
						$('#next_step').bind('click', function(){ $.binder.configurator.nextStep(); return false; });
						$('#previouse_step').bind('click', function(){ $.binder.configurator.previousStep(); return false; });
						$('#outsideLink').bind('click', function(){ $.binder.display.showOutside(); return false; });
						$('#insideLink').bind('click', function(){ $.binder.display.showInside();  return false; });
					}
					$.binder.display.hideLoader();
				},
				binderDescription: function(properties)
				{
					return "Binder Size: " + properties['Orientation_size'] + ", Mechanism: " + properties['Mechanism'];
				},
				binderProperties: function()
				{
					var properties = {};
					var pockets = {};
					var overlays = {};
					var theColour = '';
					var pocketString = '';
					//overlays 
					properties['Artwork'] = null;
					
					$.each(steps, function(key, value){										   
										   $.each(value.stepOptions, function(keys, values)
																			  {
																				if(values.type == "question")
																				{
																					if(values.questionText == 'binder_size')
																					{
																						binderText = values.text.split(" ");
																						binderString = (binderText[1] == "Landscape") ? binderText[0] + ' ' + binderText[1] : binderText[0];
																						properties['Orientation_size'] = binderString;
																					}
																					else if(values.questionText == 'capacity')
																					{
																						properties['Capacity'] =  values.answerText + 'mm';
																					}
																					else if(values.questionText == 'mechanism')
																					{
																						mechanismText =  values.text.split(" ");																					
																						if(mechanismText.length > 3)
																						{
																							if(mechanismText[3].toLowerCase() == "dee")
																							{
																								properties['Mechanism'] = mechanismText[0]+'D';
																							}
																							else
																							{
																								properties['Mechanism'] = mechanismText[0] + ' ' + mechanismText[1];
																							}
																						}
																						else
																						{
																							properties['Mechanism'] = mechanismText[0] + ' ' + mechanismText[1];
																						}
																					}
																					else if(values.questionText == 'colours')
																					{
																						theColour = values.text;
																					}
																				}
																				else
																				{
																					if(values.name == "Pockets")
																					{
																						
																						  $.each(values.stepOptions, function(keyss, valuess)
																															 {
																																if(valuess.text != undefined)
																																{
																																	pocketString = pocketString + valuess.questionText.replace(/_/gi,' ') + ': ' + valuess.text + '<br />';	
																																}																													
																															 })
																					}
																					else if(values.name == "Print")
																					{
																						properties['Artwork'] = steps[4].stepOptions[2].stepOptions[0].text;
																					}
																				}																				
																			  })   
										   })
					properties['Pockets'] = pocketString;
					properties['Overlays'] = (steps[4].stepOptions[0].stepOptions[0].text == 'None' ) ? 'None Selected' : steps[4].stepOptions[0].stepOptions[0].text;
					properties['Colour'] = theColour;
					return properties;
				},
				quickReprice: function(quantity)
				{
					$('#qtyToBuy').val(quantity);
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.doReprice()',200);
				},
				calculatePrice: function(quantity)
				{
					binderPropertiesList = $.binder.configurator.binderProperties();
					json = $.winman.finish(quantity, binderPropertiesList);
					setTimeout(function() { $.binder.configurator.doCalculatePrice(quantity) },100);
				},
				doCalculatePrice: function(quantity)
				{
					$('.quote',$('.step_nav')).addClass('current');
					$('.dl-quote').show();
					$('#order_sample').show();
					$('#add_to_basket').show();
					$('#next_step').hide();
					$('#add_to_basket').bind('click',function() { $('#BasketAddForm').submit(); return false; });
					$('#order_sample').bind('click',function() { $('#BasketAddForm2').submit(); return false; });
					$('.quote',$('.progress')).addClass('current')
						
					if(json == "error" || typeof(json)!='object')
					{
						alert("The system did not return a price for this quantity.\nYou could try a different quantity or contact us for more information.");
						$('#next_step').show();
					}
					else
					{
						$seedId = json.ConfiguratorFinishResult.seed;
						newProductId = json.ConfiguratorFinishResult.ProductId;
						strPricePerUnit = json.ConfiguratorFinishResult.Price
						strDiscountPerUnit = (json.ConfiguratorFinishResult.Discounted != undefined) ? json.ConfiguratorFinishResult.Discounted : ''
						strExtraDiscountPricePerUnit = (json.ConfiguratorFinishResult.ExtraDiscountPrice != json.ConfiguratorFinishResult.Discounted) ? json.ConfiguratorFinishResult.ExtraDiscountPrice : ''
						// Set-up full description
						var fullDescription = json.ConfiguratorFinishResult.Description;
						
						////////////////////////////////////////////////////////////////////////////////
						
						$webBiviCode = newProductId;
						$.binder.display.makeStepActive("quoteMenu");
						$('.nav-buttons').addClass('quote');
							
						$('#config_tabs').hide();
						$('#config_bread').hide();
						var detailsText = "";
						
						if(strDiscountPerUnit != '')
						{
							strPricePerUnit = strDiscountPerUnit;							
						}						
						
						if(strExtraDiscountPricePerUnit != '')
						{
							
							$('#discount').parent().show();
							$('#discountPricePerUnit').html("&pound;" + (parseFloat(strPricePerUnit) / quantity).toFixed(2));
							$('#discountPricePerUnit').parent().show();
							$('#discountPrice').parent().show();
							$('#discountPrice').html("&pound;" + (parseFloat(strPricePerUnit).toFixed(2)));
							$('#beforeDiscount').val(strPricePerUnit);
							strPricePerUnit = strExtraDiscountPricePerUnit;
						}
						else
						{
							$('#discount').parent().hide();
							$('#discountPricePerUnit').parent().hide();
							$('#discountPrice').parent().hide();
							$('#beforeDiscount').val('')
						}
					
						
						$('#pricePerUnit').html("&pound;" + (parseFloat(strPricePerUnit) / quantity).toFixed(2));
						$('#priceTotalCost').html("&pound;" + parseFloat(strPricePerUnit).toFixed(2));
						$('#BasketItemPrice').val(strPricePerUnit);
						
					
						//Over-ride total with discount amount if necessary
						
						/*if(strDiscountPerUnit != '')
						{
							$('#pricePerUnit').html("&pound;" + (parseFloat(strDiscountPerUnit) / quantity).toFixed(2));
							$('#priceTotalCost').html("&pound;" + parseFloat(strDiscountPerUnit).toFixed(2));
							$('#BasketItemPrice').val(strDiscountPerUnit);
						}*/
						
						
						//$('#discountPrice').html("&pound;" + parseFloat(strDiscountPerUnit).toFixed(2));
						$('.menuContent').hide();
						$('#quoteMenu').show();
						$('div',$('#quoteMenu')).show();
						
						
						//$('#BasketSizeSelect).val($seedId);
						
						binderPropertiesList = $.binder.configurator.binderProperties();
						detailsText = "<strong>Binder Size:</strong> " + binderPropertiesList["Orientation_size"] + "<br /><strong>Mechanism:</strong> " +  binderPropertiesList["Mechanism"] + "<br /><strong>Capacity:</strong> " +  binderPropertiesList["Capacity"];
					
						$('#theDetails').html(detailsText);
						$('#qtyToBuy').val(quantity)
						$('#quantityToBasket').val(quantity)
						
						$('#BasketConfigKey').val($configuration);
						$('#BasketConfigKey2').val($configuration);
						//$('#BasketConfigKey').val($configuration);
						
						$('#BasketLongDesc').val(fullDescription);
						if($uploadeFile == null)
						{
						$uploadeFile = "";	
						}
						$('#BasketFileName').val($uploadeFile)
						$('#BasketFileName2').val($uploadeFile)
						//$('#BasketFileName').val($uploadeFile);
						
						
						$('#seedId').val($seedId)
						$('#seedId2').val($seedId)
						$('#configuredId').val(newProductId)
						$('#configuredId2').val(newProductId)
						$('#BasketSizeSelect').val(newProductId);
						$('#BasketSizeSelect2').val(newProductId);
					
						
						/*pocketsText = "";
						$.each(binderPropertiesList["pockets"], function(key, value){
									
									if(value != "" && value != undefined)
									 {
										pocketsText = pocketsText + key.replace(/_/gi, " ") + ": " + value + "<br>";
									 }
									 })
					
						//overlayText = (binderPropertiesList["overlay"] != "" ) ? binderPropertiesList["overlay"] : 'None';
						if(pocketsText == "")
						{
							pocketsText = "None selected";	
						}*/
						
						pocketsText = "None selected";	
						$('#thePockets').html(binderPropertiesList['Pockets']);
						
						colourText = (binderPropertiesList["Colour"]!=undefined) ? binderPropertiesList["Colour"] : '';
						
						overlayText = 'No overlay selected';
						overlayText = (binderPropertiesList["Overlays"]!=undefined) ? binderPropertiesList["Overlays"] : overlayText;
						//overlayText = overlayText.replace(/_/gi, " ") + ": " + value + "<br>";
						
						var printText = 'No print option selected';
						printText = (binderPropertiesList["Artwork"] != undefined && binderPropertiesList["Artwork"] != null) ? binderPropertiesList["Artwork"] : printText;
						
						var artworkText = 'No artwork selected';
						artworkText = ($originalFile != undefined && $originalFile != null) ? $originalFile : artworkText;
						
						//////////////////////////////////////////////////////////////////////////////////////////
						$('#theColour').html(colourText);
						$('#theOverlays').html(overlayText);
						$('#theArtwork').html(artworkText);
						$('#thePrint').html(printText);
						
						// $('#theArtwork').html($originalFile);
						strDescription = $.binder.configurator.binderDescription(binderPropertiesList)
						binderPropertiesList["description"] = strDescription
						
						breakPoints = json.ConfiguratorFinishResult.PriceBreaks;
						if(strDiscountPerUnit != '')
						{
							strBreakPointText = '<li><a href="#" onclick="$.binder.configurator.quickReprice('+quantity+'); return false" title="Order '+quantity+' for &pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'">Order '+quantity+' for <strong>&pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'</strong></a>';
						}
						else
						{	
							strBreakPointText = '<li><a href="#" onclick="$.binder.configurator.quickReprice('+quantity+'); return false" title="Order '+quantity+' for &pound;'+parseFloat(strPricePerUnit).toFixed(2)+'">Order '+quantity+' for <strong>&pound;'+parseFloat(strDiscountPerUnit).toFixed(2)+'</strong></a>';
						}
						$missingBreakPoint = false;
						$.each(breakPoints.PriceBreak, function(key, values) {
																if(values.Discounted != undefined)
																{
																	if(parseFloat(values.Discounted) < 5000)
																	{
																		strBreakPointText = strBreakPointText +'<li><a href="" onclick="$.binder.configurator.quickReprice('+values.Quantity+'); return false" title="Order '+ values.Quantity+' for &pound;'+parseFloat(values.Discounted).toFixed(2)+'">Order '+values.Quantity+' for <strong>&pound;'+parseFloat(values.Discounted).toFixed(2)+' (&pound;' + (parseFloat(values.Discounted) /  values.Quantity).toFixed(2) + ' per unit)</strong></a>';
																	}
																	else
																	{
																		$missingBreakPoint = true;
																	}
																}
																else
																{
																	if(parseFloat(values.Price) < 5000)
																	{
																		strBreakPointText = strBreakPointText +'<li><a href="" onclick="$.binder.configurator.quickReprice('+values.Quantity+'); return false" title="Order '+ values.Quantity+' for &pound;'+parseFloat(values.Price).toFixed(2)+'">Order '+values.Quantity+' for <strong>&pound;'+parseFloat(values.Price).toFixed(2)+' (&pound;' + (parseFloat(values.Price) /  values.Quantity).toFixed(2) + ' per unit)</strong></a>';
																	}
																	else
																	{
																		$missingBreakPoint = true;
																	}
																}
														 
													 
													 })
						$('li',$('.breakpointText')).remove();
						if($('#discount').is(':visible'))
						{											 
							$discount = $('#discount').html()
							$('.breakpointText').append(strBreakPointText);
							 $('.breakpointText').after('<span style="font-size:10px; color: #7C8C96" class="breakText">Price breakpoints may not reflect the '+$discount+' discount</span>');
							if($missingBreakPoint == true)
							{
							
								$('.breakpointText').append();
								$('.breakpointText').after('<br /><span style="font-size:10px; color: #7C8C96" class="breakText">' + $('span',$('.AltBreakPoints')).html() + '</span>');
							}
						}
						else
						{
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:12px; color: #7C8C96" class="breakText">Please call the Sales Team on 017213 584091 to see if we can offer you a discount</span>');
						}
						$('.breakpointText').after('<br /><br /><span style="font-size:10px; color: #7C8C96">Standard delivery times are 10 working days</span>');
							//$('#BasketProperties').val(description)						
						binderPropertiesList['fullDescription'] = fullDescription;
						$encodedString = $.toJSON(binderPropertiesList);
						$('#BasketProperties').val($encodedString.replace(/undefined/gi,'"None selected"'))
						$('#BasketProperties2').val($encodedString.replace(/undefined/gi,'"None selected"'))
						//$('#BasketProperties').val($encodedString.replace(/undefined/gi,'"None selected"'))
						if(parseFloat(strPricePerUnit).toFixed(2) >= 5000)
						{
							$('#addToBasket').hide();
							$('#add_to_basket').hide();
							$('.breakpointText').hide();
							$('.howtosave').hide();
							$('#pricePerUnit').parent().hide();
							$('.totalCost').hide();
							$('#pdfLink').hide();
							$('.AltBreakPoints').show();
							$('.howtosave').hide();
							$('.bulkBuyTitle').hide();
							$('.total',$('.price-box')).hide();
						}
						else
						{
							$('#addToBasket').show();
							$('#add_to_basket').show();
							$('.breakpointText').show();
							$('.howtosave').show();
							$('#pricePerUnit').parent().show();
							$('.totalCost').show();
							$('#pdfLink').show();
							$('.AltBreakPoints').hide();
							$('.howtosave').show();
							$('.bulkBuyTitle').show();
							$('.total',$('.price-box')).show();
						}
						$('#next_step').hide();
					}
					$('h2.title').html($('.title',$('.menuContent:visible')).html())	
				},
				unbindMenuClicks: function()
				{
					$.each(steps, function(key, values) { $('#'+values.id).unbind("click") })
				},
				findNumberById: function(id)
				{
					$.each(steps, function(e,values) { 
										 
										   if(values.id == id)
										   {
												retunedID= e;   
												return false;
										   }
										   })
				
					return retunedID;
				},
				setUpHelpLink: function(questionText)
				{
					$('#help_me').unbind('click');
				
					switch(questionText)
					{
						case 'binder_size' : $('#help_me').attr({'title' :'Dimensions Guide' }).html('Dimentions Guide'); break;
						case 'mechanism' : $('#help_me').attr({'title' :'Mechanism Guide' }).html('Mechanism Guide');  break;
						case 'capacity' : $('#help_me').attr({'title' :'Capacity Guide' }).html('Capacity Guide'); break;
						case 'colours' : 	$('#help_me').attr({'title' :'Colour Range Guide' }).html('Colour Range Guide'); break;
						case 'encapoverlay' : 	$('#help_me').attr({'title' :'Overlays Guide' }).html('Overlays Guide'); break;
						case 'pockets' : 	$('#help_me').attr({'title' :'Pockets Guide' }).html('Pockets Guide'); break;
						case 'print' : 	$('#help_me').attr({'title' :'Artwork Guide' }).html('Artwork Guide'); break;
						case 'quantity' : 	$('#help_me').attr({'title' :'Quanitity Guide' }).html('Quanitity Guide'); break;
						case 'quote' : 	$('#help_me').attr({'title' :'Quote Guide' }).html('Quote Guide'); break;
					}
					$('#help_me').bind('click', function() { $.binder.display.help(questionText); return false; })
			
				},
				bindMenuClicks: function()
				{
					//$.binder.configurator.unbindMenuClicks();
					if($stepNumber > 0)
					{
						for(i = 0; i < $stepNumber; i++)
						{
							$('#'+steps[i].id).css({'cursor':'pointer'})
							$('#'+steps[i].id).bind("click", function() { 
																			
																			theID = $.binder.configurator.findNumberById($(this).attr("id"))
																			$stepNumber = parseInt(theID)
																			$.binder.configurator.loadMenu(steps[theID]);
																} )
						}
					
					}
				},
				loadMenu: function(stepOptions)
				{
					if($stepNumber == 4)
					{
						$('.current:not(.nav .current)',$('.menuContent:visible')).removeClass('current');
					
						$('.overlays',$('#optionsMenu')).hide();
						$('.pockets',$('#optionsMenu')).hide();					
						$('.print',$('#optionsMenu')).hide();	
						$answers = {};
						$.binder.configurator.setUpHelpLink('encapoverlay')
						$subStepNumber = 0;
						//$('#overlays').bind('click', function() { $.binder.configurator.changeOptions('overlays', null); } )
						//$('#pockets').bind('click', function() { $.binder.configurator.changeOptions('pockets', null); } )
						//$('#print').bind('click', function() { $.binder.configurator.changeOptions('printing', null); } )
						
						
						$('#inside_pockets').bind('click', function() { $.binder.configurator.changeOptions('pockets', 'inside'); return false; } )
						$('#outside_pockets').bind('click', function() { $.binder.configurator.changeOptions('pockets', 'outside'); return false; } )
						
						//$.binder.configurator.bindMenuClicks();
						$.binder.display.makeStepActive(stepOptions.id);
						$.binder.configurator.getOptions(stepOptions);		
						$('.overlays',$('#optionsMenu')).show();
						//$('#overlays').css({'background-color':'#FFF'});
						$('.pockets',$('#optionsMenu')).hide();					
						$('.print',$('#optionsMenu')).hide();	
					}
					else					
					{
						if(stepOptions.stepOptions[0].questionText == 'capacity')
						{
							if(steps[1].stepOptions[0].answerText == 'lever_arch_mechanism')
							{
								extraText = '-leverArch';
							}
							else
							{
								extraText = '';
							}
							$('li',$('#config_optionsSpine')).each(function() { 
																	id = $(this).attr('id')
																	$('img',$(this)).attr({'src': '/img/configImgs/'+ id +'mm'+extraText+'.png' })
																			
												})
							
						}
						$.binder.configurator.setUpHelpLink(stepOptions.stepOptions[0].questionText)
						//$.binder.configurator.bindMenuClicks();
						$.binder.display.makeStepActive(stepOptions.id);
						$.binder.configurator.getOptions(stepOptions);		
					}
					$('h2.title').html($('.title',$('.menuContent:visible')).html())
					$('.current:not(.nav .current)',$('.menuContent:visible')).removeClass('current');

					
				},
				changeOptions: function(buttonClicked, subButtonClicked)
				{
					$.binder.display.showLoader();
					setTimeout(function(){$.binder.configurator.doChangeOptions(buttonClicked, subButtonClicked)},200)
				},
				doChangeOptions: function(buttonClicked, subButtonClicked)
				{
					
					/*$currentstep = steps[$stepNumber].id;
					$('.'+$currentstep,$('.step_nav')).addClass('current');
						
					$('.'+$currentstep,$('.progress',$('#optionsMenu'))).addClass('current');
					$('.'+$currentstep,$('.progress',$('#optionsMenu'))).next().addClass('next').removeClass('current');
					$('.'+$currentstep,$('.progress',$('#optionsMenu'))).next().next().removeClass('next');
					
					*/
					$('.current:not(.nav .current)',$('.menuContent:visible')).removeClass('current');
					if(buttonClicked == "overlays")
					{
						
						$('.next',$('.step_nav',$('#optionsMenu'))).removeClass('next');
						$('.current',$('.step_nav',$('#optionsMenu'))).removeClass('current');
						$('#overlays',$('.progress',$('#optionsMenu'))).addClass('current');
						$('#overlays',$('.progress',$('#optionsMenu'))).next().addClass('next');
						
						$.binder.configurator.setUpHelpLink('encapoverlay');
						$.binder.display.showOutside();
						
						
						$('#subStep2BreadLine').removeClass('subActiveLine');
						$('img',$('#subStep2BreadImage')).attr({'src': '/img/configImgs/bread_image.png'})
						$('#subStep3BreadLine').removeClass('subActiveLine');
						$('img',$('#subStep3BreadImage')).attr({'src': '/img/configImgs/bread_image.png'})
						$('.headerOption', $('#overlays')).css({'font-weight' : 'bold'})
						$('.headerOption', $('#pockets')).css({'font-weight' : 'normal'})
						$('.headerOption', $('#print')).css({'font-weight' : 'normal'})
						
						
						$('.overlays',$('#optionsMenu')).show();
						$('.pockets',$('#optionsMenu')).hide();
						$('.print',$('#optionsMenu')).hide();
						$.binder.configurator.submitAnswers()
							$.each(steps[$stepNumber].stepOptions[0].stepOptions, function(key,values)
									 {
									questionlist = $.winman.returnVisibleOptions(values.id);
									$.binder.configurator.hideShowOptions(questionlist,values.questionText) 
								 })
							
					}
					else if(buttonClicked == "pockets")
					{
						$('.next',$('.step_nav',$('#optionsMenu'))).removeClass('next');
						$('.current',$('.step_nav',$('#optionsMenu'))).removeClass('current');
						$('#overlays',$('.progress',$('#optionsMenu'))).addClass('current');
						$('#pockets',$('.progress',$('#optionsMenu'))).addClass('current').addClass('next');
						$('#pockets',$('.progress',$('#optionsMenu'))).next().addClass('next');
					
						
						$('.headerOption', $('#overlays')).css({'font-weight' : 'normal'})
						$('.headerOption', $('#pockets')).css({'font-weight' : 'bold'})
						$('.headerOption', $('#print')).css({'font-weight' : 'normal'})
						
						$.binder.configurator.setUpHelpLink('pockets');
						
						//$('#overlays').css({'background-color':'#CCC'});
						//$('#pockets').css({'background-color':'#FFF'});
						//$('#print').css({'background-color':'#CCC'});
						
						$('.overlays').hide();
						$('.pockets').show();
						$('.print').hide();
						
						if(subButtonClicked == null)
						{
							reloadList = true;
						}
						else
						{
							reloadList = false;
						}
						
						if(subButtonClicked == null || subButtonClicked == 'inside')
						{
							$('#inside_pockets').addClass('current');
							$('#outside_pockets').removeClass('current');
							$('.pockets .inside').show();
							$('.pockets .outside').hide();	
							$.binder.display.showInside();
						}
						else
						{
							$('#inside_pockets').removeClass('current');
							$('#outside_pockets').addClass('current');
							$('.pockets .inside').hide();
							$('.pockets .outside').show();
							$.binder.display.showOutside();
						}
						if(reloadList == true)
						{
							$.binder.configurator.submitAnswers()
							$.each(steps[$stepNumber].stepOptions[1].stepOptions, function(key,values)
																				 {
																				questionlist = $.winman.returnVisibleOptions(values.id);
																				if(questionlist.length == 0 || values.id == 592 ||  values.id == 542)
																				{
																					steps[$stepNumber].stepOptions[1].stepOptions[key].noanswer = true;
																				}
																				else
																				{
																					steps[$stepNumber].stepOptions[1].stepOptions[key].noanswer = false;
																				}
																				
																				$.binder.configurator.hideShowOptions(questionlist,values.questionText) 
																			 })
						}
						//submit answers from overlays.
					}
					else
					{
						
						
						$('.step_nav',$('#optionsMenu')).addClass('current');
						$('.step_nav',$('#optionsMenu')).addClass('next');
						
						
						$.binder.configurator.setUpHelpLink('print');
						$.binder.display.showInside();
						
						$('.overlays',$('#optionsMenu')).hide();
						$('.pockets',$('#optionsMenu')).hide();
						$('.print',$('#optionsMenu')).show();
						
						
						
						
						$.binder.configurator.submitAnswers()
						//submit answers from pockets.
						$.each(steps[$stepNumber].stepOptions[2].stepOptions, function(key,values)
																			 {
																				questionlist = $.winman.returnVisibleOptions(values.id);
																				$.binder.configurator.hideShowOptions(questionlist,values.questionText) 
																			 })
						
						if(steps[4].stepOptions[0].stepOptions[1].answerText == 'customer_to_supply')
						{
							$('#artworkUpload').hide();
							
							$('#artworkMsg').html('You have chosen to print your own encapsulation sheets, no further artwork options are available').css({'font-size':'14px'});
							$('#printOptions').hide();
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": questionlist[0].AnswerId, "text":questionlist[0].AnswerText.replace(' ','_').toLowerCase(),"unformattedText":questionlist[0].AnswerText, "menuID":"printing"}
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace("pie_hover","").replace("pie_first-child","").replace(" ","");
							
							
						}
						else
						{
							$('#artworkUpload').show();
							if(questionlist.length == 1 && questionlist[0].AnswerText == "No Print")
							{
								$('#artworkMsg').hide();
								$('#printOptions').hide();
							
								$answers[currentQuestion] = {};
								$answers[currentQuestion] = {"id": questionlist[0].AnswerId, "text":questionlist[0].AnswerText.replace(' ','_').toLowerCase(),"unformattedText":questionlist[0].AnswerText, "menuID":"printing"}
								
							}
							else
							{
								$('#artworkMsg').html('Print Requirements');
								$('#artworkMsg').show();
								$('#printOptions').show();
							}
							
							fileUploader = new AjaxUpload('#fileBrower', {
		  
							  action: '/configurator/uploadImage',					
							  name: 'File',					
							  autoSubmit: false,					
							  responseType: false,					
							  onChange: function(file, extension){
								  $('#fileName').val(file)
								  },
						
							  onSubmit: function(file, extension) {},
							
							  onComplete: function(file, response)
							  {  
								eval("imageDims = " + response);
								
								if(imageDims.error == undefined)
								{
									if(extraAnswer == true)
									{
										extraAnswer = false;
									}
									$originalFile = imageDims.originalFilename
									$uploadeFile = imageDims.newFilename;
									$('#uploadMessage').html("<strong style='font-size: 12px'>File Uploaded</strong>");
									$('#no_print').hide();
								}
								else
								{
									if(imageDims.error == "ext")
									{
										$('#uploadMessage').html("The upload as failed as the file uploaded must be a pdf document.");
									}
									else
									{
										$('#uploadMessage').html("There has been a problem uploading the file.  Please try again.");	
									}
								}
							  }
							});
						}
					}
					
					
					$.binder.display.hideLoader();
				},			
				getOptions: function(theOptions)
				{
					
					theSize = $.configurator.getObjectSize(theOptions.stepOptions)
					$.configurator.hideMenus()
					if(theSize == 1)
					{
						if(theOptions.stepOptions[0].type == "question")
						{
							if(theOptions.stepOptions[0].questionText == "colours")
							{
								$.binder.display.showColoursGroups(theOptions.stepOptions[0].questionText, optionsToShow);
							}
							else
							{
								$.configurator.showMenu(theOptions.stepOptions[0].id);
	
								optionsToShow = $.winman.returnVisibleOptions(theOptions.stepOptions[0].id);
								$.binder.configurator.hideShowOptions(optionsToShow, theOptions.stepOptions[0].questionText)
							}
						}
					}
					else
					{
					
						$.configurator.showMenu(theOptions.id + "Menu");	
						
						$.each(theOptions.stepOptions, function(key, values) { 
																
				
																
																if(values.type != "group")
																{
																	optionsToShow = $.winman.returnVisibleOptions(values.id);
																	if(values.questionText == "colours")
																	{
																		$.binder.display.showColoursGroups(values.questionText, optionsToShow);
																	}
																	else
																	{
																
																		$.binder.configurator.hideShowOptions(optionsToShow, values.questionText);
																		
																			if(values.defaultOption != undefined)
																			{
																				status = $.winman.answer(values.defaultOption);
																				$('.'+values.defaultOption , $('#preOptionBar')).parent().css({'background-color': '#FFF'});
																				// $('.'+values.defaultOption , $('#preOptionBar')).parent().addClass("liCurrent");
																			}
																	}
																	
																}
																else
																{	
																	
																	$.each(values.stepOptions, function(subKeys, subValues) { 
																	optionsToShow = $.winman.returnVisibleOptions(subValues.id);
															
																	$.binder.configurator.hideShowOptions(optionsToShow, subValues.questionText);															
																	
																									})
																}
																if(values.questionText == undefined)
																{
																	return false;
																}
																});
					} 
					if(theOptions.id == "options")
					{
						$.binder.display.showOutside();
					}
				},				
				hideShowOptions: function(answerList, questionText)
				{
					$.binder.display.showInside();
					
					if(answerList.length >0)
					{
						if(questionText == "colours")
						{
							//$.binder.display.showColoursGroups(questionText, answerList);
						}
						else
						{
						
							if(questionText == "encapsulationclear_overlay")
							{
								$areaToConfigure = "outside"
							}
							else
							{
								
								if(questionText.indexOf("outer") > -1)
								{
									$areaToConfigure = "outside"
								}
								else
								{
									$areaToConfigure = "inside"
								}
							}
	
							
							if($('#' + questionText).length)
							{
								
								$('#' + questionText).show();
							
								$('li',$('#' + questionText)).hide();
								
								$('li',$('#' + questionText)).unbind('click');
							
								if(answerList.length > 0)
								{	
									
									$.each(answerList, function(key, value)
									{
										
										if(questionText == "capacity")
										{
											fullId = "";
											if(value.AnswerText.indexOf(" ") > -1)
											{
												tempInfo = value.AnswerText.split(" ");
												fullId = tempInfo[0]
											}
											else
											{
												fullId = value.AnswerText
											}									
											listID = fullId.substring(2,4) 									
										}
										else
										{
											listID = value.AnswerText.toLowerCase().replace(/,/gi,"").replace(/\)/gi,"").replace(/\(/gi,"").replace(/ - /gi,"_").replace(/ & /gi,"_").replace(/ /gi,"_");
										}									
										if($('#'+listID, $('#' + questionText)).length)
										{
											$('#'+listID, $('#' + questionText)).show();
										}
										else
										{
											$('ul',$('#' + questionText)).append('<li id="'+listID+'"><span>'+value.AnswerText+'</span></li>');
										}
										answer = value.AnswerId
										$('span',$('#'+listID, $('#' + questionText))).attr({"title": value.AnswerText });
										$('span',$('#'+listID, $('#' + questionText))).addClass(answer.toString());
									
									})	
									if(questionText != 'encap_printing')
									{
										$('li', $('#'+questionText)).bind('click', function() { $.binder.display.changeDisplay($('span',$(this)), questionText); return false; });
									}
									else
									{
										$('li', $('#'+questionText)).bind('click', function() { $.binder.display.changeDisplay($('span',$(this)), questionText); });
									}
								}							
							}
						}					
						$('.none',$('#' + questionText).parent()).hide();
					}
					else
					{
						//submitAnswers
						$('.none',$('#' + questionText).parent()).show();
						$('li',$('#' + questionText)).hide();
					}
	
					if($areaToConfigure == "outside" && $currentArea != "outside")
					{
	
						$.binder.display.showOutside();
					}
					else if($areaToConfigure == "outside" && $currentArea == "outside")
					{
						
					}
					else
					{
	
						$.binder.display.showInside();
					}
					if(questionText == 'encap_printing')
					{
						$('#encap_printing').hide()
					}
					
				},	
				createStepList: function()
				{
					//needs to be softcoded
				/*	steps[0] = {0:{"questionID":262,"name":"binder_size","defaultAnswer":""}};
					steps[1] = {0:{"questionID":264,"name":"mechanism","defaultAnswer":""}};
					steps[2] = {0:{"questionID":263,"name":"capacity","defaultAnswer":""}};
					steps[3] = {0:{"questionID":273,"name":"material_outer_range","defaultAnswer":""},1:{"questionID":274,"name":"material_outer_type","defaultAnswer":""}};
					
					steps[4] = {0:{"questionID":271,"name":"encapsulation_clear_overlay","defaultAnswer":""},1:{"questionID":284,"name":"encap_printing","defaultAnswer":""}};
					steps[6] = {0:{"questionID":268,"name":"spine_pocket","defaultAnswer":""},1:{"questionID":269,"name":"inside_front_pocket","defaultAnswer":""},2:{"questionID":270,"name":"inside_back_pocket","defaultAnswer":""}};
					steps[7] = {0:{"questionID":266,"name":"printing","defaultAnswer":""}};*/
					steps = {}
					/*
					steps[0] = { "id":"step1", "stepOptions":{0: {"type": "question", "id":262,"questionText":"binder_size"} } }
					steps[1] = { "id":"step2", "stepOptions":{0: {"type": "question", "id":264,"questionText":"mechanism"} } }
					steps[2] = { "id":"step3", "stepOptions":{0: {"type": "question", "id":263,"questionText":"capacity"} } }
					steps[3] = { "id":"step4", "stepOptions":{0: {"type": "question", "id":273,"questionText":"material_outer_range", "defaultOption":"2321"},1: {"type": "question", "id":274,"questionText":"material_outer_type"} } }
					steps[4] = { "id":"options", "stepOptions": {0: {"type": "group", "name": "Overlays", "stepOptions" : { 0: {"type": "question", "id":271,"questionText":"encapsulation_clear_overlay"}, 1: {"type": "question", "id":284,"questionText":"encap_printing"} } }, 1: {"type": "group", "name": "Pockets", "stepOptions" : { 0: {"type": "question", "id":268,"questionText":"spine_pocket"}, 1: {"type": "question", "id":269,"questionText":"inside_front_pocket"}, 2: {"type": "question", "id":270,"questionText":"inside_back_pocket"} } }, 2: {"type": "group", "name": "Print", "stepOptions" : { 0: {"type": "question", "id":266,"questionText":"printing"} } } } }
					steps[5] = { "id":"qty", "stepOptions": {0: {"type": "question", "id":null,"questionText":"qty"} } }
					*/
					steps[0] = { "id":"step2", "stepOptions":{0: {"type": "question", "id":538,"questionText":"binder_size"} } }
					steps[1] = { "id":"step3", "stepOptions":{0: {"type": "question", "id":540,"questionText":"mechanism"} } }
					steps[2] = { "id":"step4", "stepOptions":{0: {"type": "question", "id":539,"questionText":"capacity"} } }
					steps[3] = { "id":"step5", "stepOptions":{0: {"type": "question", "id":546,"questionText":"colours"} } }
					steps[4] = { "id":"options", "stepOptions": {0: {"type": "group", "name": "Overlays", "stepOptions" : { 0: {"type": "question", "id":545,"questionText":"encapsulation_clear_overlay"}, 1: {"type": "question", "id":548,"questionText":"encap_printing"} } }, 1: {"type": "group", "name": "Pockets", "stepOptions" : { 0: {"type": "question", "id":542,"questionText":"spine_pocket"}, 1: {"type": "question", "id":543,"questionText":"inside_front_pocket"}, 2: {"type": "question", "id":544,"questionText":"inside_back_pocket"}, 3: {"type": "question", "id":595,"questionText":"outer_pocket"} } }, 2: {"type": "group", "name": "Print", "stepOptions" : { 0: {"type": "question", "id":541,"questionText":"printing"} } } } }
					steps[5] = { "id":"qty", "stepOptions": {0: {"type": "question", "id":null,"questionText":"qty"} } }
					
				}			
			}
		} 
			 
		})
})(jQuery);

