//---------------------------------------------------------------------------------------------//
// declare array for tracking open items

var open_array = new Array();
var more_info = new Array();

$( document ).ready(
	function(){
				
		//---------------------------------------------------------------------------------------------//
		// apply functionality to submit button
		
		$( "#submit_button" ).click(
			function(){
				
				// get information
				
				var get_info = $( "#finder_input" ).val();
				
				find_engine( get_info );
				
			}
		);
		
		$( "#finder_form" ).submit(
			function(){
				
				// get information
				
				var get_info = $( "#finder_input" ).val();
				
				find_engine( get_info );
				
				return false;
				
			}
		);
		/*$( "#results1_moreinfo_link" ).click(
			function(){
				close_moreinfo ();
				// show more information for result
			show_moreinfo( "#finder_results1_moreinfo");
				
			}
		);
		$( "#results2_moreinfo_link" ).click(
			function(){
				close_moreinfo ();
				// show more information for result
			show_moreinfo( "#finder_results2_moreinfo");
				
			}
		);
		$( "#results3_moreinfo_link" ).click(
			function(){
				close_moreinfo ();
				// show more information for result
			show_moreinfo( "#finder_results3_moreinfo");
				
			}
		);
		$( "#results4_moreinfo_link" ).click(
			function(){
				close_moreinfo ();
				// show more information for result
			show_moreinfo( "#finder_results4_moreinfo");
				
			}
		);*/
		$( "#enlarge_engine_info1" ).click(
			function () {
				$("#results_1").toggleClass("results_specs_enlarge");
			$("#results_1 > span").toggleClass("results_title_enlarge");
				if ($(this).text() == "Enlarge Information Above") {
			$(this).text("Shrink Information Above");
			$("#results_1 > img:first").attr("src","img/engine_finder/engine_1_enlarged.jpg");
				} else {
				$(this).text("Enlarge Information Above");
				$("#results_1 > img:first").attr("src","img/engine_finder/engine_1.jpg");
				}
			}
		);
		$( "#enlarge_engine_info2" ).click(
			function () {
			$("#results_2").toggleClass("results_specs_enlarge");
			$("#results_2 > span").toggleClass("results_title_enlarge");
				if ($(this).text() == "Enlarge Information Above") {
			$(this).text("Shrink Information Above");
			$("#results_2 > img:first").attr("src","img/engine_finder/engine_2_enlarged.jpg");
				} else {
				$(this).text("Enlarge Information Above");
				$("#results_2 > img:first").attr("src","img/engine_finder/engine_2.jpg");
				}
			}
		);
		$( "#enlarge_engine_info3" ).click(
			function () {
			$("#results_3").toggleClass("results_specs_enlarge");
			$("#results_3 > span").toggleClass("results_title_enlarge");
				if ($(this).text() == "Enlarge Information Above") {
			$(this).text("Shrink Information Above");
			$("#results_3 > img:first").attr("src","img/engine_finder/engine_3_enlarged.jpg");
				} else {
				$(this).text("Enlarge Information Above");
				$("#results_3 > img:first").attr("src","img/engine_finder/engine_3.jpg");
				}
			}
		);
		$( "#enlarge_engine_info4" ).click(
			function () {
			$("#results_4").toggleClass("results_specs_enlarge");
			$("#results_4 > span").toggleClass("results_title_enlarge");
				if ($(this).text() == "Enlarge Information Above") {
			$(this).text("Shrink Information Above");
			$("#results_4 > img:first").attr("src","img/engine_finder/engine_4_enlarged.jpg");
				} else {
				$(this).text("Enlarge Information Above");
				$("#results_4 > img:first").attr("src","img/engine_finder/engine_4.jpg");
				}
			}
		);
		$( "#bottombtn1" ).click(
			function(){
				close_results();
				// shows engine information on home page
			show_result( "#results_1" );
				
			}
		);
		$( "#bottombtn2" ).click(
			function(){
				close_results();
				// shows engine information on home page
			show_result( "#results_2" );
				
			}
		);
		$( "#bottombtn3" ).click(
			function(){
				close_results();
				// shows engine information on home page
			show_result( "#results_3" );
				
			}
		);
		$( "#bottombtn4" ).click(
			function(){
				close_results();
				// shows engine information on home page
			show_result( "#results_4" );
				
			}
		);
		
	}
);

function find_engine ( sent_info )
{
	
	// close current results groups
	
	if ( open_array.length > 0 )
	{
		
		close_results();
		
	}
	
	// catch empty and non-number entries
	
	if ( sent_info == "" )
	{
		
		show_result( "#results_empty" );
		
	} else
	{
		
		if ( isNaN( sent_info ) )
		{
			
			show_result( "#results_number" );
			
		} else
		{
			
			// determine proper group
			
			var find_check = false;
			
			if ( sent_info > 5499 && sent_info < 15001 )
			{
				find_check = true;
				show_result( "#results_1" );
			}
			
			if ( sent_info > 1999 && sent_info < 7001 )
			{
				find_check = true;
				show_result( "#results_2" );
			}
			
			if ( sent_info > 1399 && sent_info < 3101 )
			{
				find_check = true;
				show_result( "#results_3" );
			}
			
			if ( sent_info > 599 && sent_info < 2701 )
			{
				find_check = true;
				show_result( "#results_4" );
			}
			
			if ( find_check == false )
			{
				show_result( "#results_none" );
				
			}
			
		}	
		
	}
	
	
}

function close_results ()
{
	
	for ( var i=0; i<=open_array.length; i++ )
	{
		
		var current_get = open_array.pop();
				
		//$( current_get ).animate( { opacity: 'hide' }, 250 );
		$( current_get ).hide( 500 );
		
	}
			
}

function show_result ( sent_object )
{
	
	//$( sent_object ).animate( { opacity: 'show' }, 500 );
	$( sent_object ).show( 500 );
	
	open_array.push( sent_object );
	
}

/*function close_moreinfo ()
{
	
	for ( var i=0; i<=more_info.length; i++ )
	{
		
		var current_info = more_info.pop();
				
		//$( current_get ).animate( { opacity: 'hide' }, 250 );
		$( current_info ).hide( 500 );
		
	}
			
}

function show_moreinfo ( sent_object )
{
	
	//$( sent_object ).animate( { opacity: 'show' }, 500 );
	$( sent_object ).show( 500 );
	
	more_info.push( sent_object );
	
}*/