/*
	Initilize the search
	This sits in /includes/plugins/function.print_search.php
	below where the form is drawn
*/
function init_search() {
	var type_buttons = $("#ask_a_question, #search_for_answers, #members_browse");
	var go_button = $("#search #go");
	var search_input = $("#search_input");
	var new_action = 'search';
	var typed_in = false;

	var default_text =
	{
		search: "Enter keywords",
		ask: "Enter your question",
		members: "Enter member name"
	};
	if(!COBRAND) // If it's not a a cobrand site, add these hints.
	{
		default_text.search += " (diet, gardening, etc.)";
		default_text.ask += "  (Why is the sky blue?)";
	}
	var default_search =
	{
		search: "diet",
		ask: "Why is the sky blue?",
		members: "AB-Joel"
	};

	set_text(new_action);

	$('#user_search').submit(function()
	{
		if(!typed_in)
		{
			search_input.val('');
		}		
	});

	// Submit when they hit return
	search_input.keyup(function(e)  
	{
		if(e.keyCode == 13)
		{
			this.form.search.value = $.trim(this.form.search.value); 
			this.form.submit();
		}
		textCounter(search_input[0], 255);
	});

	// if typed_in = false clear the text, change the color, and marked typed in
	search_input.click(function() 
	{
		if(!typed_in)
		{
			search_input.css({color: 'black'});
			search_input.val('');
			typed_in = true;
		}
		
	});


	search_input.blur(function() 
	{
		if(search_input.val() == '')
		{
			typed_in = false;
			set_text(new_action);
		}
	});
	
	// Changes which type
	type_buttons.unbind();
	type_buttons.click( function()
	{
		type_buttons.animate({height: 32}, "fast");
		$(this).animate({height: 44}, "fast");

		new_action = new_section = this.id.split("_")[0]; // Either: search, ask, members
		
		go_button.fadeOut("fast", function()
		{
			set_text(new_action);
			go_button.removeClass();
			go_button.addClass(new_action);
			go_button.fadeIn("fast");
			//go_button.parent().attr("action", "/"+new_action ); // Set the page
			$('#user_search').attr("action", "/"+new_action ); // Set the page
			
			// Make input box bigger depending on type
			if(new_action != 'ask') // Make normal
			{
				search_input.animate({height: 35}, 'slow');
				search_input.css({fontSize: '26px'});
			}
			else // Make large box and smaller font
			{
				search_input.animate({height: 120}, 'slow');
				search_input.css({fontSize: '18px'});
			}
		});
	});
	
	function set_text(action)
	{
		if(!typed_in)
		{
			search_input.css({color: '#ccc'});
			search_input.val(default_text[action]);
		}
	} 


}


