$(document).ready(function() {
  /*USER TOOL TIP*/
  $('.toolTipBtn').live('click', function() {
	//remove all others
	$('.toolTip').remove();
	
	cID = $(this).attr('cid');
	linkWidth = $(this).width();
	linkPos = $(this).offset();
		linkTop = linkPos.top + 14;
		linkLeft = linkPos.left;
	
	title = $(this).text();
	if($(this).attr('toolTitle') &&  $(this).attr('toolTitle') != '') {
		title = $(this).attr('toolTitle');
	}
	
	
	links = buildToolTipLinks($(this).attr('contactType'), cID);
		
	$('body').append('<div class="toolTip" ttCID="'+cID+'"><div class="toolTipArrow"><img src="/images/tooltipArrow.gif"></div><div class="toolTipInfoBox"><div class="toolTipContactName">'+title+'</div><div class="toolTipContactLinks">'+links+'</div><div class="toolTipClose">x</div></div></div>');
	
		
	boxWidth = $('[ttCID="'+cID+'"]').width();
	$('[ttCID="'+cID+'"]').css('top', linkTop+'px');
	
	linkLeft = linkLeft - (boxWidth/2);
	linkLeft = linkLeft + (linkWidth/2);
	$('[ttCID="'+cID+'"]').css('left', linkLeft+'px');
  });	
	
	
  $('.toolTipClose').live('click',function() {
	  $('.toolTip').remove();
  });
  
  
  function buildToolTipLinks(contactType, cid) {
	switch(contactType) {
		case 'contacts_clients':
		  output = '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client&cid='+cid+'">Profile</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client-todos&cid='+cid+'">Things To Do</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
	
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client-notes&cid='+cid+'">Notes</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/notes/?p=add-new&cid='+cid+'">Post a Note</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client-news&cid='+cid+'">History</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client-documents&cid='+cid+'">Documents</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-client-properties&cid='+cid+'">Properties</a></div>';		
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  

		  output = output + '<div class="toolTipExtraWrapper">';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=edit-client&cid='+cid+'">Edit</a></div>';
		  output = output + '<div class="toolTipLink"><a class="contactDelete" cid="'+cid+'" href="javascript:void(0);">Delete</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>'; 

	
		  return output;
	  	  break;
		  
		  
		  
		case 'contacts_realtors':
		  output = '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-realtor&cid='+cid+'">Profile</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-realtor-todos&cid='+cid+'">Things To Do</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
	
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-realtor-notes&cid='+cid+'">Notes</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/notes/?p=add-new&cid='+cid+'">Post a Note</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-realtor-news&cid='+cid+'">History</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-realtor-documents&cid='+cid+'">Documents</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div class="toolTipExtraWrapper">';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=edit-realtor&cid='+cid+'">Edit</a></div>';
		  output = output + '<div class="toolTipLink"><a class="contactDelete" cid="'+cid+'" href="javascript:void(0);">Delete</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>'; 
		  
		  return output;
	  	  break;
		  
		  
		case 'contacts_associates':
		  output = '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-associate&cid='+cid+'">Profile</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-associate-todos&cid='+cid+'">Things To Do</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
	
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-associate-notes&cid='+cid+'">Notes</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/notes/?p=add-new&cid='+cid+'">Post a Note</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-associate-news&cid='+cid+'">History</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=view-associate-documents&cid='+cid+'">Documents</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  

		  output = output + '<div class="toolTipExtraWrapper">';
		  output = output + '<div class="toolTipLink"><a href="/cp/contacts/?p=edit-associate&cid='+cid+'">Edit</a></div>';
		  output = output + '<div class="toolTipLink"><a class="contactDelete" cid="'+cid+'" href="javascript:void(0);">Delete</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>'; 

		  
		  return output;
	  	  break;
		  
		case 'listing':
		  output = '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/listings/?p=view-listing&lid='+cid+'">Overview</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/listings/?p=view-listing-todos&lid='+cid+'">Things To Do</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
	
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/listings/?p=imageupload&lid='+cid+'">Photos</a></div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/listings/?p=view-listing-documents&lid='+cid+'">Documents</a></div>';
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
		  
		  output = output + '<div>';
		  output = output + '<div class="toolTipLink"><a href="/cp/listings/?p=view-listing-history&lid='+cid+'">History</a></div>';
		  
		  output = output + '<br clear="all" />';
		  output = output + '</div>';
	
		  return output;
	  	  break;
	}
  }
  /*END -USER TOOL TIP*/
});
