// JavaScript Document
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: 
			{
				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(" ",""), "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID}
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace(" ","");
						}
						else
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames.replace("current", "").replace("headerOption", "").replace("colourList", "").replace(" ",""), "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID}
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").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(" ","");
						}
						else
						{
							$answers[currentQuestion] = {};
							$answers[currentQuestion] = {"id": classNames, "text":$answerText,"unformattedText":$answerUnformattedText, "menuID":menuID} 				
							answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace(" ","");
						}					
					}
	
					$.display.makeActive($(clickedItem), 'configurator_wrapper')
				
					switch(menuID)
					{
						case 'binder_size': $.binder.display.changeBinderDisplay(currentID); break;
						case 'capacity': $.binder.display.changeCapacityDisplay(currentID); break;
						case 'mechanism': $.binder.display.changeMechanismDisplay(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 'material_outer_type' : $.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 'material_outer_range' : $.binder.display.changeColourList($(clickedItem), answerID); break;
						case 'printing': $.binder.display.changePrintOptions(currentID); break;
					}
					
				},
				changePrintOptions: function(currentID)
				{
					$('.selectedPrint').html($('#'+currentID).text() + ' selected')
				},
				changeColourList: function(currentItem, answerID)
				{
					//$.binder.display.showLoader();
					$.binder.display.showLoader();
					setTimeout(function() { $.binder.display.doChangeColourList(currentItem, answerID)},200);
					
				},
				doChangeColourList: function(currentItem, answerID)
				{
					$.binder.display.removeColour();
					currentQuestion = $.configurator.findCurrentQuestion('material_outer_range', currentItem,-1);
					$('li',$('#config_options')).css({ 'background-color' : '#CCC' });
					$('.current',$('li',$('#config_options'))).removeClass('current')
					$($(currentItem).parent()).css({ 'background-color' : '#FFF' });
					$(currentItem).addClass('current')
					nextQuestion = parseInt(currentQuestion) + 1;
					answer = $.winman.answer(answerID);
					questionlist = $.winman.returnVisibleOptions(steps[$stepNumber].stepOptions[nextQuestion].id);
					$.binder.display.showColours('material_outer_type', questionlist);
					
					$.binder.display.hideLoader();
				},
				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)
				{
					$('#config_prod_preview').css('visibility','visible');
					$('.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($('.inside').is(':hidden'))
						{
							$.binder.display.showInside();	
						}	
					}
					else
					{
						if($('.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(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.makeInactive($('#'+$wrapper+' span'));
							$.display.makeActive($('#'+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(" ", "_") == "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(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.makeInactive($('#'+$wrapper+' span'));
							$.display.makeActive($('#'+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(" ","");		
								}
								else
								{
									$answers[currentQuestion] = {};
									$answers[currentQuestion] = {"id": 5089, "text":'None Selected',"unformattedText":'None Selected', "menuID":menuID} 				
									answerID = classNames.replace("current", "").replace("colourList", "").replace("headerOption", "").replace(" ","");	
								}
								return;
							}
							$wrapper = section+'_'+location+'_pocket';
							$.display.makeInactive($('#'+$wrapper+' span'));
							$.display.makeActive($('#'+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.makeInactive($('#'+menuID+' span'));
					$.display.makeActive($('#'+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.makeInactive($('#'+menuID+' span'));
					$.display.makeActive($('#'+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()
				{
					$('.outside').hide();
					$('#outsideLink').removeClass('selected');
					$('#insideLink').addClass('selected');
					$('.inside').show();
				},
				showOutside: function()
				{
					$('.outside').show();
					$('#outsideLink').addClass('selected');
					$('#insideLink').removeClass('selected');
					$('.inside').hide();
				},
				showColours: function(questionText, answerList)
				{
					$('li', $('#'+questionText)).remove();
					$.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(")","");
						}
						newHtml = '<li><span id="'+colourCode.replace("#","")+'" style="background-color:'+colourCode+'" class="'+value.AnswerId.toString()+' colourList" title="'+answername.replace('[','(').replace(']',')')+'"></span></li>';
						$('ul',$('#' + questionText)).append(newHtml)
					})
				
					$.display.makeOpacity($('span:not(.headerOption)', $('li',$('#configurator_wrapper'))), false);
					
					$('span', $('li', $('#'+questionText))).bind('click', function() { $.binder.display.changeDisplay($(this), questionText) });
					$('span:not(.headerOption)', $('li', $('#'+questionText,$('#configurator_wrapper')))).hover(function() { if($(this).is('.current')) {} else{ $.display.makeOpacity($(this), true) }}, function() {  if($(this).is('.current')) {}else{ $.display.makeOpacity($(this), false) }} ) 
				},
				makeStepActive: function(stepID)
				{
					
					$pos = $('.breadLine').index($('#'+stepID+'BreadLine')) - 1;
			
					if($pos == -1)
					{
						$pos ++;	
					}
					
					$('.breadLine:gt('+$pos+')').removeClass('activeLine');
					$('img',$('.breadImage:gt('+$pos+')'),$('#config_bread')).each(function() { $(this).attr({'src': '/img/configImgs/bread_image.png'}); })
					
					$('#'+stepID+'BreadLine').addClass('activeLine');
					$('img',$('#'+stepID+'BreadImage')).attr({'src': '/img/configImgs/bread_image_active.png'});
					
					$('span',$('#config_tabs')).removeClass("current");
					$('#'+stepID, $('#config_tabs')).addClass("current");
					$('#config_tabs').show();
					$('#config_bread').show();
				},
				showLoader: function()
				{
					$numTimes = $('#loader').attr('attrlang');
					if($numTimes == undefined)
					{
						$numTimes = 1;	
					}
					else
					{
						$numTimes = parseInt($numTimes) + 1;
					}
					
					$('#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 = "Order " + quantity + " for &pound;" + parseFloat(strDiscountPerUnit).toFixed(2) + "<br>";
						}
						else
						{	
							strBreakPointText = "Order " + quantity + " for &pound;" + parseFloat(strPricePerUnit).toFixed(2) + "<br>";
						}
						$.each(breakPoints.PriceBreak, function(key, values) {
												if(values.Discounted != undefined)
												{
													strBreakPointText = strBreakPointText + "Order " + values.Quantity + " for &pound;" + parseFloat(values.Discounted).toFixed(2) + " (&pound;" + (parseFloat(values.Discounted) /  values.Quantity).toFixed(2) + " per unit) <br>"; 	
												}
												else
												{
													strBreakPointText = strBreakPointText + "Order " + values.Quantity + " for &pound;" + parseFloat(values.Price).toFixed(2) + " (&pound;" + (parseFloat(values.Price) /  values.Quantity).toFixed(2) + " per unit) <br>"; 	
												}
										 
									 
									 })
						
						
						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($('#discount').is(':visible'))
						{											 
							$discount = $('#discount').html()
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:10px">Price breakpoints may not reflect the '+$discount+' web discount</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>');	
						}
						/*
						
						$('#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")
								{
									steps[$stepNumber].stepOptions[questionNum].answer = value.id;
									steps[$stepNumber].stepOptions[questionNum].answerText = value.text
									steps[$stepNumber].stepOptions[questionNum].text = value.unformattedText
								}
								else
								{						
									groupNum = $.binder.configurator.getGroupFromQuestion(value.menuID, -1);
									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 = null;				
					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
					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 == 1)
						{
							
						}
						else if($subStepNumber < $numSubSteps)
						{
							if($.configurator.getObjectSize($answers) == 0)
							{
								alert("You need to select an answer for this step");	
							}
							else
							{	
								$subStepNumber++;
								$menu = steps[4]['stepOptions'][$subStepNumber]['name'].toLowerCase();
								if($menu == 'print')
								{
									$menu = 'printing';
								}							
								$.binder.configurator.changeOptions($menu, null);							
							}					
						}*/
						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');
							$('#quantityinput').show();
							$stepNumber = $stepNumber + 1;
							$.binder.configurator.setUpHelpLink('quantity')
						}
					}
					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')
						}
						else
						{	
							$.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('');
					$('#start_over').hide();
					
					$.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()
				{
					$answersToDelete = steps[$stepNumber];
					$answers = {};
					switch($stepNumber)
					{
						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]);
								
							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]);
							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);
								});
								
							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);
										});
									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" });	
										}
									break;	
									case 2:
										$('#configuratorFile').val('');
										$uploadeFile = null;
										$originalFile = null;
										$('#dummyFileName').val('');
									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;
							$('.selectedPrint').html('');
							$('#uploadMessage').html('');
							$('.fileBrower').val('');
						case 5:
								
								$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)
							break;
							
					}
					
					
					
					if($stepNumber == 0)
					{
						$('#start_over').hide();	
					}
					$('#next_step').show();	
					
					$.binder.display.hideLoader();
				},			
				startOver: function()
				{
					$.binder.display.showLoader();
					setTimeout('$.binder.configurator.doStartOver()',200)
				},
				setupConfigurator: function()
				{
					$productID = 31074;
					$itemType = 'binder';
					

					$stepNumber = 0;
					$.binder.display.showLoader();
					$('#next_step').show();
					$('.menuContent').hide();
					$('#start_over').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(); });
						$('#start_over').bind('click', function(){ $.binder.configurator.previousStep(); });
						$('#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 == 'material_outer_type')
																					{
																						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 />';	
																													}
																													
																											
																										//pockets[valuess.questionText] = valuess.text;
																										//properties['Pockets'] = properties['Pockets'] + valuess.questionText + ': ' + (valuess.text == undefined) ? 'None Selected<br>' : valuess.text;//pockets	
																															 })
																					}
																					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;
				},
				calculatePrice: function(quantity)
				{
					binderPropertiesList = $.binder.configurator.binderProperties();
					json = $.winman.finish(quantity, binderPropertiesList);
					setTimeout(function() { $.binder.configurator.doCalculatePrice(quantity) },100)
				},
				doCalculatePrice: function(quantity)
				{
					
					$('#next_step').hide();
					
					
					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");
						
						$('#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, #BasketConfigKey2').val($configuration);
						$('#BasketConfigKey').val($configuration);
						
						$('#BasketLongDesc').val(fullDescription);
						if($uploadeFile == null)
						{
						$uploadeFile = "";	
						}
						//$('#BasketFileName, #BasketFileName2').val($uploadeFile);
						$('#BasketFileName').val($uploadeFile);
						
						
						$('#seedId').val($seedId)
						$('#configuredId').val(newProductId)
						$('#BasketSizeSelect').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 = "Order " + quantity + " for &pound;" + parseFloat(strDiscountPerUnit).toFixed(2) + "<br>";
						}
						else
						{	
							strBreakPointText = "Order " + quantity + " for &pound;" + parseFloat(strPricePerUnit).toFixed(2) + "<br>";
						}
						$.each(breakPoints.PriceBreak, function(key, values) {
																if(values.Discounted != undefined)
																{
																	strBreakPointText = strBreakPointText + "Order " + values.Quantity + " for &pound;" + parseFloat(values.Discounted).toFixed(2) + " (&pound;" + (parseFloat(values.Discounted) /  values.Quantity).toFixed(2) + " per unit) <br>"; 	
																}
																else
																{
																	strBreakPointText = strBreakPointText + "Order " + values.Quantity + " for &pound;" + parseFloat(values.Price).toFixed(2) + " (&pound;" + (parseFloat(values.Price) /  values.Quantity).toFixed(2) + " per unit) <br>"; 	
																}
														 
													 
													 })
						
						if($('#discount').is(':visible'))
						{											 
							$discount = $('#discount').html()
							$('.breakpointText').html(strBreakPointText + '<span style="font-size:10px">Price breakpoints may not reflect the '+$discount+' discount</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>');
						}
							//$('#BasketProperties').val(description)						
						binderPropertiesList['fullDescription'] = fullDescription;
						$encodedString = $.toJSON(binderPropertiesList);
						//$('#BasketProperties, #BasketProperties2').val($encodedString.replace(/undefined/gi,'"None selected"'))
						$('#BasketProperties').val($encodedString.replace(/undefined/gi,'"None selected"'))
						$('body').append('<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1071874380/?value=1.00&amp;label=A3s4CJTE3QEQzIKO_wM&amp;guid=ON&amp;script=0"/>');

						$('#next_step').hide();
					}
				},
				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' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/step_1_guide.png', 'title' :'Dimensions Guide' }); break;
						case 'mechanism' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/step_2_guide.png', 'title' :'Mechanism Guide' }); break;
						case 'capacity' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/step_3_guide.png', 'title' :'Capacity Guide' }); break;
						case 'material_outer_range' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/step_4_guide.png', 'title' :'Colour Range Guide' }); break;
						case 'encapoverlay' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/overlays_notes.png', 'title' :'Overlays Guide' }); break;
						case 'pockets' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/pockets_notes.png', 'title' :'Pockets Guide' }); break;
						case 'print' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/artwork_quote.png', 'title' :'Artwork Guide' }); break;
						case 'quantity' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/quantity_notes.png', 'title' :'Quanitity Guide' }); break;
						case 'quote' : 	$('img', $('#help_me')).attr({'src' : '/img/configImgs/your_quote_notes.png', 'title' :'Quote Guide' }); break;
					}
					$('#help_me').bind('click', function() { $.binder.display.help(questionText); })
			
				},
				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)
					{
						$('.overlays').hide();
						$('.pockets').hide();					
						$('.print').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'); } )
						$('#outside_pockets').bind('click', function() { $.binder.configurator.changeOptions('pockets', 'outside'); } )
						
						//$.binder.configurator.bindMenuClicks();
						$.binder.display.makeStepActive(stepOptions.id);
						$.binder.configurator.getOptions(stepOptions);		
						$('.overlays').show();
						//$('#overlays').css({'background-color':'#FFF'});
						$('.pockets').hide();					
						$('.print').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);		
					}
					
					
				},
				changeOptions: function(buttonClicked, subButtonClicked)
				{
					$.binder.display.showLoader();
					setTimeout(function(){$.binder.configurator.doChangeOptions(buttonClicked, subButtonClicked)},200)
				},
				doChangeOptions: function(buttonClicked, subButtonClicked)
				{
				
					if(buttonClicked == "overlays")
					{
						$.binder.configurator.setUpHelpLink('encapoverlay');
						$.binder.display.showOutside();
						//$('#overlays').css({'background-color':'#FFF'});
						//$('#pockets').css({'background-color':'#CCC'});
						//$('#print').css({'background-color':'#CCC'});
						
						$('#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').show();
						$('.pockets').hide();
						$('.print').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")
					{
						$('#subStep2BreadLine').addClass('subActiveLine');
						$('img',$('#subStep2BreadImage')).attr({'src': '/img/configImgs/bread_image_active.png'})
						$('#subStep3BreadLine').removeClass('subActiveLine');
						$('img',$('#subStep3BreadImage')).attr({'src': '/img/configImgs/bread_image.png'})
						$('.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').css({'background-color':'#FFF'});
							$('#outside_pockets').css({'background-color':'#CCC'});
							$('.outerPockets').hide();
							$('.innerPockets').show();	
							$.binder.display.showInside();
						}
						else
						{
							$('#outside_pockets').css({'background-color':'#FFF'});
							$('#inside_pockets').css({'background-color':'#CCC'});
							$('.innerPockets').hide();
							$('.outerPockets').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
					{
						$.binder.configurator.setUpHelpLink('print');
						$.binder.display.showInside();
						$('#subStep2BreadLine').addClass('subActiveLine');
						$('img',$('#subStep2BreadImage')).attr({'src': '/img/configImgs/bread_image_active.png'})
						$('#subStep3BreadLine').addClass('subActiveLine');
						$('img',$('#subStep3BreadImage')).attr({'src': '/img/configImgs/bread_image_active.png'})
						//$('#overlays').css({'background-color':'#CCC'});
						//$('#pockets').css({'background-color':'#CCC'});
						//$('#print').css({'background-color':'#FFF'});
						$('.headerOption', $('#overlays')).css({'font-weight' : 'normal'})
						$('.headerOption', $('#pockets')).css({'font-weight' : 'normal'})
						$('.headerOption', $('#print')).css({'font-weight' : 'bold'})
						
						$('.overlays').hide();
						$('.pockets').hide();
						$('.print').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')
						{
							$('#artwork').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(" ","");
							
							
						}
						else
						{
							$('#artwork').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")
						{
							$.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);
															
																	$.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 == "material_outer_type")
						{
							$.binder.display.showColours(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();
								
								$('span', $('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());
									
									})	
									$.display.makeOpacity($('span:not(.headerOption)', $('li',$('#configurator_wrapper'))), false);
									$('span', $('li', $('#'+questionText))).bind('click', function() { $.binder.display.changeDisplay($(this), questionText) });
									$('span:not(.headerOption)', $('li', $('#'+questionText))).hover(function() { if($(this).is('.current')) {} else{ $.display.makeOpacity($(this), true) }}, function() {  if($(this).is('.current')) {}else{ $.display.makeOpacity($(this), false) }} ) 
								}							
							}
						}					
						$('.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":"step1", "stepOptions":{0: {"type": "question", "id":538,"questionText":"binder_size"} } }
					steps[1] = { "id":"step2", "stepOptions":{0: {"type": "question", "id":540,"questionText":"mechanism"} } }
					steps[2] = { "id":"step3", "stepOptions":{0: {"type": "question", "id":539,"questionText":"capacity"} } }
					steps[3] = { "id":"step4", "stepOptions":{0: {"type": "question", "id":546,"questionText":"material_outer_range", "defaultOption":"5101"},1: {"type": "question", "id":547,"questionText":"material_outer_type"} } }
					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);