(function($){
	
	$.fn.searchProjects = function(){

		return this.each(function(){

			$(this).hover(
				function(){

					$this		= $(this);
					$options	= $this.next();

					clearTimeout($('a.select').data('time_out_id'));

					$('div.options').hide();
					$options.slideToggle(400).find('a.option').click(function(event){
						event.preventDefault();
						$option = $(this);
	
						var id	= $option.attr('rel');
						var tag	= $option.text();
	
						if(tag != undefined && tag != ''){
							$this.text(tag).css('color', '#000').prev('input').val(id);
							$options.slideUp(400);
						}
	
					});
	
				},
				function(){

					$this		= $(this);
					$options	= $this.next();

					var time_out_id = setTimeout(function(){ $options.slideUp(400); }, 1000);
					$('a.select').data('time_out_id', time_out_id);

					$options.hover(
						function(){
							clearTimeout($('a.select').data('time_out_id'));
						},
						function(){
							$options.delay(1000).slideUp(400);
						}
					);

				}
			);

			$(this).click(function(event){ event.preventDefault(); });

		});

	};

	$.fn.startProjectSearch = function(){

		return this.each(function(){

			$(this).click(function(event){
				event.preventDefault();
				$(this).parents('form').submit();
			});

		});

	};

	$.fn.gotoProjectDetails = function(){

		return this.click(function(event){
			$this = $(this);

			var $goto = $this.children('input[name="data[link]"]').val();
			window.location = $goto;

		});

	};

})(jQuery);
