$(document).ready(function(){
	updateSwitches();
	$('.textbox').change(function(){
		
		updateSwitches();
		
	});	
	
	function updateSwitches(){
		var cardSideVal = $('#cardSide').val();
		var accumulationStyle = $('#accumulation').val();
		var motorVal = $('#motor').val();
		var option = $('#func').val();

		var settingMatrix=[
			[1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 22, 33, 44, 55, 66],
			[2, 0, 1]
		];

		setDip1();
		setDip2(cardSideVal);
		setDip3(accumulationStyle);
		setDip45(option);
		setDip67(motorVal);

		//Set Dip Switch Number 1
		function setDip1(){
			$('#dip1').css('background-color', 'green');
		}

		//Set Dip Switch Number 2
		function setDip2(direction){
			if(direction == 1){
				$('#dip2').css('background-color', 'green');
			}
			else{
				$('#dip2').css('background-color', 'red');
			}
		}

		//Set Dip Switch Number 3
		function setDip3(accumulation){
			if(accumulation == 1){
				$('#dip3').css('background-color', 'red');
			}
			else{
				$('#dip3').css('background-color', 'green');
			}
		}

		//Set Dip Switch Number 4 & 5
		function setDip45(optionFunction){
			var dip4 = settingMatrix[optionFunction - 1][1];
			var dip5 = settingMatrix[optionFunction - 1][2];

			if(dip4==0){
				$('#dip4').css('background-color', 'red');
			}
			else{
				$('#dip4').css('background-color', 'green');
			}

			if(dip5==0){
				$('#dip5').css('background-color', 'red');
			}
			else{
				$('#dip5').css('background-color', 'green');
			}
		}

		//Set Dip Switch Number 6 & 7
		function setDip67(motor){
			if(motor == 1){
				$('#dip6').css('background-color', 'red');
				$('#dip7').css('background-color', 'red');
			}
			else{
				$('#dip6').css('background-color', 'green');
				$('#dip7').css('background-color', 'green');
			}
		}
	};
});
	