	var active = "#mapping";

function titlecase(original)
{
	
	var o_split = original.split(" ");
	//this probably isn't a complete list of words that shouldn't be capitalized
	var special_words = new Array('and', 'the', 'to', 'for', 'is', 'in', 'a', 'at', 'an', 'from', 'by', 'if', 'of');
	for (i=0;i<o_split.length;i++) {
		if (i == 0) {
			//always capitalize the first word
			o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
		}
		else if(special_words.indexOf(o_split[i]) < 0) { 
		  	o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
		}
	}
	return o_split.join(' ');
	
}


$(function()
{
       $("#mapping").fadeOut(2500 , function()
       {
       	active = "#form";
		$("#form").fadeIn("slow");
		$("#mappingSmall").fadeIn("slow");
		
       });

   $("#queryMe").click(function ()
   {
 	  
       return doQuery();
   });
   $("#aboutMapping").click(function ()
   {
   	if (active == "#about")
   		return false;
   		
   	$(active).fadeOut("slow" , function()
       {
       	active = "#about";
		$(active).fadeIn("slow");
       	
          	
       });
       return false;
   });
   /*
   $("#mappingSmall").click(function ()
   {
   	if (active == "#form")
   		return false;

   	$(active).fadeOut("slow" , function()
       {
       	active = "#form";
		$(active).fadeIn("slow");
       	
          	
       });
       return false;


   });
   */
   
   $("#return").click(function ()
   {
       $(active).fadeOut("slow" , function()
       {
       	active = "#app";
		$(active).fadeIn("slow");
		fixDivs();
		redrawCanvas();
       });
       return false;
   });    
   
   $("#q").keypress(function (e) {
   	if (e.which == 13)
   	       doQuery();
   });
   
});   
function doQuery()
{
       $(active).fadeOut("slow" , function()
       {

		$("#aboutMapping").fadeIn("slow");
       
       	active = "#app";
           init(titlecase($("#q").val()));
       });
return false;
}
