$(document).ready( function(){
	$('.hover_button').hover(
			function(){
				$(this).css('background-position','bottom left' );
			},
			function(){
				$(this).css('background-position','top left' );
			}
		);
	$('#main_menu').find('li').hover(
			function(){
				if( ! $(this).hasClass('active') && !$(this).hasClass('search') ){
					$(this).css('background-color','#666' );
				}
			},
			function(){
				if( ! $(this).hasClass('active') && !$(this).hasClass('search') ){
					$(this).css('background-color','#000' );
				}
			}
		);
	$('#research_make').change( function(){
		x = 1;
		$.ajax( {
			type: "POST",
			url: "/vehicle/find_by_manufacturer",
			data: {
				id: $(this).val()
			},
			success: function( data ){
				$('#research_model').html( data );
			}
		});
	});

	$('#research_model').change( function(){
		t = $('#research_model :selected').text();
		t = t.replace("/","","g");
		arr = t.split(" ");
		new_arr = new Array();
		new_arr.push(arr.shift());
		new_arr.push( $('#research_make :selected').text() );
		new_arr = new_arr.concat( arr );
		t = new_arr.join("-");
		v = $(this).val();
          modelSelected( v, t );
	});

	$('#site_search').change( startSearch );
	$('#site_search').focus( function(){
	   $('#site_search').val("");
	});
	$('#search_icon').click( startSearch );

     $('flash_message').fadeOut("slow");
});

function startSearch(){
	   keywords = $("#site_search").val().split(" ");
	   search_url = "/search/"+keywords.join("/");
	   document.location = search_url;
}

function modelSelected( v, t ){
     document.location = '/vehicle/show/'+t+"__"+v;
}

