var enableToolTip1Hide = true;
var enableToolTip2Hide = true;
var enableToolTip3Hide = true;

var toolTipInfo2 = 0;
//	TODO	These functions should be re-factored
/**
 * 
 */
function delayhideToolTip1(){
	enableToolTip1Hide = true;
	setTimeout("hideToolTip1()",100);
}		
/**
 * 
 */
function delayhideToolTip2(){
	enableToolTip2Hide = true;
	setTimeout("hideToolTip2()",100);
}
/**
 * 
 */
function delayhideToolTip3(){
	enableToolTip3Hide = true;
	setTimeout("hideToolTip3()",100);
}		
/**
 * 
 */
function hideToolTip1(){
	if(!enableToolTip1Hide)return;
	$('#tooltip1').hide();
}						
/**
 * 
 */
function hideToolTip2(){
	if(!enableToolTip2Hide)return;
	$('#tooltip2').hide();
}
/*
 * 
 */
function hideToolTip3(){
	if(!enableToolTip3Hide)return;
	$('#tooltip3').hide();
}			
/**
 *	
 */
function displayTooltip() {
	setupToolTip('#tooltip1',['#y_name','#y_email'],delayhideToolTip1,function(){enableToolTip1Hide = false;$('#tooltip1').show();});
	setupToolTip('#tooltip2',['#f_name','#f_email'],delayhideToolTip2,function(){enableToolTip2Hide = false;$('#tooltip2').show();});
	setupToolTip('#tooltip3',['#c_name','#c_email'],delayhideToolTip3,function(){enableToolTip3Hide = false;$('#tooltip3').show();});
	
	//  Allow the click functionality to work on the tooltips
	$('#contact_list_link,.add_recipient_contact_link').bind('mouseenter',function(e){
	  $("#f_name, #f_email").unbind('blur',delayhideToolTip2);
	});
	
	$('#contact_list_link,.add_recipient_contact_link').bind('mouseleave',function(e){
	  $("#f_name, #f_email").blur(delayhideToolTip2);
	});
	
	$('.add_contributor_contact_link').bind('mouseenter',function(e){
	  $("#c_name,#c_email").unbind('blur',delayhideToolTip3);
	});
	
	$('.add_contributor_contact_link').bind('mouseleave',function(e){
	  $("#c_name,#c_email").unbind('blur',delayhideToolTip3);
	});
}
/**
 *	@param	tooltip						The name of the tooltip e.g. '#tooltip2' 
 *	@param	fields						An array of fields that should show the tooltip on focus
 *														and hide it on blur.
 *	@param	hideFuntion				The function that will hide the tooltip
 *	@param	showFunction			The function that will reveal the tooltip
 *
 */
function setupToolTip(tooltip,fields,hideFuntion,showFunction){
	
	//	Hide the tool tip initially
	$(tooltip).hide();
	
	//	Enable the hide action for all the fields
	for(var i=0;i<fields.length;i++){
		$(fields[i]).bind('blur',hideFuntion);
	}
	
	//	Enable the show action when focused on the field
	for (var i = 0; i < fields.length; i++) {
		$(fields[i]).bind('focus',showFunction);
  }
	
}					