var $j = jQuery.noConflict();

jQuery(document).ready(function($){

	// quick search text change
	var strText = 'Quick search...';
	$('#categoryString').css('color','#cccccc');
	$('#categoryString').css('font-style','italic');
	$('#categoryString').attr("value",strText);
	$('#categoryString').focus(function(){
		if($(this).attr("value")==strText){
			$(this).css('color','#000000');
			$(this).css('font-style','normal');
			$(this).attr("value",'');
		}
	});
	$('#categoryString').blur(function(){
		if($(this).attr("value")=='' || $(this).attr("value")==strText){
			$(this).css('color','#cccccc');
			$(this).css('font-style','italic');
			$(this).attr("value",strText);
		}
	});

	// home page main search text change
	
	var strHomeText = 'Type here...';
	$('#searchTxt').css('color','#cccccc');
	$('#searchTxt').css('font-style','italic');
	$('#searchTxt').attr("value",strHomeText);
	$('#searchTxt').focus(function(){
		if($(this).attr("value")==strHomeText){
			$(this).css('color','#000000');
			$(this).css('font-style','normal');
			$(this).attr("value",'');
		}
	});
	$('#searchTxt').blur(function(){
		if($(this).attr("value")=='' || $(this).attr("value")==strHomeText){
			$(this).css('color','#cccccc');
			$(this).css('font-style','italic');
			$(this).attr("value",strHomeText);
		}
	});
	$('#searchTxt,.stdInput').hover(function(){
		$(this).css('background-color','#efefef');
	},function(){
		$(this).css('background-color','#ffffff');
	});

	$("#searchTxt").autocomplete(
		site_path+"results.php",
		{
			width:300,
			onItemSelect:findValue,
			onFindValue:findValue,
			formatItem:formatItem
		}
	);

});


function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the URL as the form action
	if( !!li.extra ){
		jQuery('#searchFrm').attr("action",li.extra[0]);
		 var sValue = li.extra[1];
	}else{
		// otherwise, let's just display the value in the text box
		 var sValue = li.selectValue;
	}

	jQuery("#searchTxt").attr('value',sValue);
	jQuery('#searchFrm').submit();
}


function formatItem(row) {
	return row[0];
}
