/**
 *	Merge all the basic initialization of jQuery Plugins,
 *	trying to reduce in page javascript, and ease up mantainance of diff templates.
 *	requires all basic jQUery modules to be loaded first.	
 *
 *
 *	This file init's- 
 *	jQuery Hint, jQuery AutoComplete, jQuery IE7/IE6 fixes (For QuickSearch Bar)
 *	jQuery Highlight (For Search results)
 */
 
 
 /*Don't wait till document ready here*/
 handleQuickSearch();
 
$(document).ready(function(){
	
	//Highlight declaration
	highLightRows('.rRow');

});


/*To highlight rows when mouse over, requires jquery*/
function highLightRows(sRows)
{
	var oRows = $(sRows);
	if (oRows.length == 0) return false;
	
	/*add a top border to first row*/
	oRows.filter(':first').hover(
		function(){ if (!$(this).hasClass("nochange")) $(this).addClass("topborder"); },
		function(){ $(this).removeClass("topborder"); }
	);

	oRows.hover(
		function(){ if (!$(this).hasClass("nochange")) $(this).addClass("apphighlight"); },
		function(){ $(this).removeClass("apphighlight"); }
	);
	
}

/*Hide, show the quick search bottom bar*/
function handleQuickSearch()
{
	//ready to roll
	if ($('#area1').attr("checked") && ($("#key").val() == "" || $('#key').hasClass('blur')) && !$('#qsBottom').hasClass('noHide'))
	$('#qsBottom').hide();
	else
	return false;
	
	$('#key').focus(function(){
		
		var objVis = $('#qsBottom:visible');
	
		if( objVis.length === 0)
		$('#qsBottom').slideDown('fast');
	});
}

/*Auto */
function enableAutoComplete()
{
	//auto complete function settings
	//url the proxy should get data from
	var strURL = '';
	//location of the proxy file/ keyword file to load the suggestions from
	var strKeyFile = gblStrKeyFile;
	//specify which html input id will have auto suggest
	var strInputId = 'key';
	//width and height
	var dimensions = {width:350,height:150};
	//Format how should the end result look like
	function formatItem(row){
		return row[0];
	}
	/* try not to change below */
	//extra parameters for the jQuery plugin to send to proxy
	var aryExtraParams = {'url':strURL};
	
	//Initialize with settings, width and height of the suggest box can be modified below
	if ($('#'+strInputId).attr('autosuggest') != 'off')
	{
		jQuery('#' + strInputId).autocomplete(strKeyFile, {
			width: dimensions.width,
			scrollHeight: dimensions.height,
			matchContains: true,
			formatItem: formatItem,
			extraParams: aryExtraParams
		});
	}
}
