 	function sellBack()
  	{
  			questionId++;
  			var total1 = random(20)*random(10)*5;
			var tip1 = 2;
			var tip2 = random(20)+5;
			var x = total1 * (tip1/100);
			while(Math.round(x) != x)
			{
				tip1++;				
				x = total1 * (tip1/100);
			}
			var first = x + total1;			
			var y = first * (tip2/100);
			var second = first + y;
			
			first = makeMoney(first);
			second = makeMoney(second);
			var answer = "The first sale was for " + first + ". The second was for " + second + "."; 
			var q = 'A man sells his ' + makeMoney(total1) + ' product for ' + tip1 + '% extra to a second man. The second man sells it again for ' + tip2 + '% more. How much was the second sale?';
			$("#questions").append('<li id="' + questionId + '">' + edit(q) + '<span class="answer">' + answer + '</span></li>');
  	}

	var questionId = 0;
	var m;	
	var oldText = "";
  	google.setOnLoadCallback(function() 
  	{
		initMenus();	     
		$("#possibleCombinationsButton").click(function(){
			questionId++;
			var layers = $('#possibleCombinationsSelect').val();
			var level = $('input[name="possibleCombinations"]:checked').val();
			var p = getPerson();
			var q = p.name + " had ";
			var combos = new Array();
			combos[0] = new Array("breads","meats","condiments","veggies");   
			combos[1] = new Array("pants","shirts","hats","shoes");
			combos[2] = new Array("body types","rims","paint jobs","stereos");
			var n = new Array();
			var x = random(combos.length-1);
			var a = 1;
			for( var i = 0; i < layers; i++ )
			{
				n[i] = random(5);				
				if( i == layers-1)
				{
					q += " and " + n[i] + " " + combos[x][i] + ". ";				
				}
				else
				{	
					q += n[i] + " " + combos[x][i] + ", "; 
				}
				a *= n[i];
			}
			switch(level)
			{
				case '0':
					q += "How many combinations is this?";
					break;
				case '1':
					var days = a + (random(10)-5);
					q += "Is this enough for a different " + "combination" + " every day for " + days + " days?";
					if( a >= 14 ){
						a = "Yes, since there are " + a  + " combinations."; }
					else{
						a = "Nope, only has " + a + " combinations.";}
					break;
				case '2':
					q += "Would adding one more " + combos[x][1] + ", give " + p.name + " enough combinations to last a whole month without repeating?";
					n[1]++;
					a = 1;
					for(var k=0;k<layers;k++ )
					{ 
						a *= n[k];					
					}
					if( a >= 30 ){
						a = "Yes, since there would be " + a  + " combinations.";}
					else{
						a = "No, since there would be only " + a  + " combinations.";}
					break;
				default:
					break;
			}
			$("#questions").append('<li id="' + questionId + '">' + edit(q) + "<span class='answer'>" + a + '</span></li>');			
		});
		$("#jarButton").click(function(){
			questionId++;
			var level = $('input[name="jar"]:checked').val();
			var e = "";
			var total = random(10) + 10;
			var q = "There are " + total + " marbles in a jar. ";
			var a ="";
			var runningTotal = total;
			var x = random(Math.floor(runningTotal/2));
			runningTotal -= x;
			var y = random(runningTotal-1);
			runningTotal -= y;
			var z = runningTotal;
			var xc = color();
			q += x + " of the marbles are " + xc;
			var yc = color();
			q += ", " + y + " of the marbles are " + yc;
			var zc = color();
			q += ", " + z + " of the marbles are " + zc + ". ";
			switch(level)
			{
			case '1':
			q += "What is the probability of pulling out a " + yc + " marble?";			
			a = simplify(y, total); 
			break;
			case '2':
			q += "What is the probability of picking a " + yc + " marble, replacing it, and then picking a " + xc + " marble?";
			var n2 = y * x;
			var d2 = total * total;			
			a = simplify(n2, d2);
			break;
			case '3':
			q += "What is the probability of picking a " + yc + " marble, not replacing it, and then picking a " + xc + " marble?";			
			var nn2 = y * x;
			var dd2 = total * (total-1);
			a = simplify(nn2, dd2);
			break;
			default:
				break;
			}
			q = edit(q);
			$("#questions").append('<li id="' + questionId + '">' + edit(q) + "<span class='answer'>" + a + '</span></li>');			

		});
  		 $("#geoProbabilityButton").click(function()
		{
			questionId++;
			
			var m = measurement(measure,"big");	
			
			var v1Type = $("#pShape1").val();
			var v2Type = $("#pShape2").val();			
			
			var s1_v1 = (Math.ceil(Math.random()*11) + Math.ceil(Math.random()*11) + 2);
			var s1_v2 = (Math.ceil(Math.random()*11) + Math.ceil(Math.random()*11) + 2);

			var s2_v1 = Math.floor(Math.random()*s1_v1);
			var s2_v2 = Math.floor(Math.random()*s1_v2);
			
			if( v1Type == "triangle" )
			{
				if( v2Type == "rectangle" )
				{
					s2_v1 = Math.floor(Math.random()*Math.ceil(s1_v1*0.5));
					s2_v2 = Math.floor(Math.random()*Math.ceil(s1_v2*0.5));
				}
			}
			
			if( s2_v1 === 0 )
				{s2_v1++;}
			if (s2_v2 === 0 )
				{s2_v2++;}
			
			var a1 = 0;
			var a2 = 0;
			
			var v1words = "";
			var v2words = "";
			
			if( v1Type == "rectangle" )
			{
				a1 = s1_v1 * s1_v2;
				v1words = "rectangle with length " + s1_v1 + m + " and height " + s1_v2 + m; 
			}
			else if( v1Type == "circle" )
			{
				a1 = s1_v1 * s1_v1 * 3.14;
				a1 = Math.round(a1);
				v1words = "circle with radius " + s1_v1 + m;
			}
			else
			{
				a1 = 0.5 * s1_v1 * s1_v2;
				v1words = "triangle with height " + s1_v1 + m + " and base " + s1_v2 + m;
			}

			if( v2Type == "rectangle" )
			{
				a2 = s2_v1 * s2_v2;
				v2words = "rectangle with length " + s2_v1 + m + " and height " + s2_v2 + m; 
			}
			else if( v2Type == "circle" )
			{
				a2 = s2_v1 * s2_v1 * 3.14;
				a2 = Math.round(a1);
				v2words = "circle with radius " + s2_v1 + m;
			}
			else
			{
				a2 = 0.5 * s2_v1 * s2_v2;
				v2words = "triangle with height " + s2_v1 + m + " and base " + s2_v2 + m;
			}
			
			var answer = "The probability of hitting the inner shape is = " + reduce(a2,a1); 

			$("#questions").append('<li id="' + questionId + '"><p class="edit">Inside of a ' + v1words + ' is a ' + v2words + '. What is the probability of throwing a dart and hitting the inner shape? </p><span class="answer">' + answer + '</span> </li>');			
		return false;

		});
  		  $("#fractionAnalogy").click(function(){
  		  		questionId++;  		
  		  		var question = "";
  		  		var answer = "";
  		  		var easy = $('#proportionEasy').is(':checked');
  		  		var word = $('#proportionWord').is(':checked');
				var geo = $('#proportionGeo').is(':checked');
	  	  		var a = "";
				var p = "";
				var denom = 0;
				var num = 0;
				var d2 = 0;
  		  		while(true)
  		  		{
	  		  		denom = random(20) + 5;
  			  		num = random(denom-1);
  			  		d2 = denom;
  		  			while( true )
  		  			{
	  		  			d2 = random(15) + 5;
		  		  		if( d2 != denom )
		  		  		{ break; }
	  			  	}
  		  			var fract = formatFraction(num,denom);
  		  			var step1 = num * d2;
					answer = simplify(step1,denom);
					question = fract + " = " + formatFraction("x",d2);
					var x = step1 / denom;
					//this is a whole number! let's keep it :) 
					if( x == Math.round(x) )
					{
						if( easy && isMultipleOf(denom,d2))
						{
							break;
						}
						else if( !isMultipleOf(denom, d2 ) && num/denom != 0.5 )
						{
							break;
						}
					}
				}
				if( word )
				{
					a = verbNoun();
					p = person();						
					question = "<p class='edit'>" + p + " can " + a[0] + " " + num + " " + a[1] + " in " + denom + " minutes. How many can " + p + " " + a[0] + " in " + d2 + " minutes?</p>" ;
					answer += " " + a[1];
				}				
				if(geo)
				{
					var m = " m";
					var file = "";
					$('#loader').show();
					$.ajax({
					      url: "http://www.automathmagic.com/shapes/rectangle.php",
					      type: "get",
					      data: ({l: num, w: denom, m: m }),
					      async:false,
					      success: function(pp){
							file = pp;
							$('#loader').hide();			
					      }
					   }
					);
					question = "These shapes are similar. Find the missing length.<br>"
					question += "<img src='http://www.automathmagic.com/shapes/" + file + "' />";
					$('#loader').show();
					$.ajax({
					      url: "http://www.automathmagic.com/shapes/rectangle.php",
					      type: "get",
					      data: ({l: answer, w: d2, m: m, v:'true' }),
					      async:false,
					      success: function(pp){
							file = pp;
							$('#loader').hide();			
					      }
					   }
					);
					question += "<img src='http://www.automathmagic.com/shapes/" + file + "' />";					
				}
				answer = "<span class='answer'>" + answer + "</span>";
				$("#questions").append('<li id="' + questionId + '">' + question + answer + '</li>');
				return false;
  		  });
  		
  		$('#sellbackButton').click(function(){sellBack();});

		$("#mostLikelyLetterButton").click(function()
		{
			var word = $("#word").val();
			var letters = countLetters(word);
			var likelyLetter = "";
			var max = -1;
			var plural = 0;
			var total = word.length;
			for (var i in letters)
			{
				if( letters[i] > max )
				{
					likelyLetter = i;
					max = letters[i];
				}
				else if( letters[i] == max )
				{
					likelyLetter += "</em> and <em>" + i;
					plural = true;
				}
			}
			var answer = "<span class='answer'>Most likely letter is <em>" + likelyLetter + "</em> with a probability of " + reduce( max , total) + ".</span>";
			$("#questions").append('<li>Which letter in <em>' + word + '</em> is most likely to be pulled?' + answer + "</li>");	
			
		return false;

		});

		$("#secondLetterButton").click(function()
		{
			var replace = $('#replaceSecondLetter').is(':checked');
			var word = $("#secondWord").val();
			var letters = countLetters(word);
			var likelyLetter = "";
			var max = 0;
			var total = word.length;
			var randy = Math.floor(Math.random()*total);
			var n = 0;
			var m = Math.floor(Math.random()*total);
			var o = Math.floor(Math.random()*total);

			if(word.charAt(m) == word.charAt(o))
			{
				if( n === 0 )
				{
					n++;
				}
				else
				{
					n--;
				}
			}

			firstP = 0;
			secondP = 0;

			var question = "The first letter pulled from <em>" + word + "</em> is ";

					question += word.charAt(randy) + ". ";
					if( !replace )
					{
						question += "Don't put that letter back. ";
						letters[word.charAt(randy)]--;
						total--;
					}
					else
					{
						question += "Put that letter back. ";
					}
					question += "Which is more likely to be pulled out next: <em>";	

					question += word.charAt(m) + "</em> or <em>";
					firstP = letters[word.charAt(m)];

					question += word.charAt(o) + "</em>?";
					secondP = letters[word.charAt(o)];
					
			var answer = "<span class='answer'>Most likely letter is ";
			if( firstP > secondP ) {
				answer +=  word.charAt(m) + " - " + reduce(firstP, total) + " versus " + reduce(secondP, total);}
			else if( firstP < secondP ){
				answer += word.charAt(o) + " - " + reduce(secondP, total) + " versus " + reduce(firstP, total);}
			else{
				answer += "neither! They're equal:" + reduce(secondP, total);}
				
			$("#questions").append('<li>' + question + answer + "</li>");	
			
		return false;

		});


	var t = setTimeout("autosave()", 30000); 
	return false;
});

