/******************************
* Dynamic vCard for new Publisher v1.1
* by Derrick Gall
* Last Updated by Derrick Gall (February 4th, 2010)
******************************/
$(function(){
	// Get supposed file name (based on file name)
	if (FSSitePath) {
		name = FSFilename;
	} else {
		name = location.pathname;
	}
	
	// Isolate name
	name = name.replace(/.*\/([^\.]*)\.[^\.]*$/gi, '$1');
	
	// Check if vCard exists
	$.ajax({
		type: 'GET',
		url: FSSitePath + '../../content/includes/vCards/' + name + '.vcf',
		success: function(data){
			var vcfURL = FSSitePath + '../../content/includes/vCards/' + name + '.vcf';
			// Add vCard to DOM
			$('div.attorneyProfileVCard')
				.before('<div class="attorneyProfileVCardLabel">vCard:</div>')
				.html('<a id="getVCard" href="' + vcfURL + '"><img alt="Vcard" src="' + FSSitePath + '/design/images/vcard.gif" border="0"></a>');
			$('#getVCard').click(function(e){
				e.preventDefault();
				// Prompt user about vCard compatibility
				if (window.confirm('A vCard is a way of saving this person\'s information to your local email address book. \n\n If you have Outlook 2000, Groupwise 5.5, or Outlook Express 5, click OK, then select Download File from Current Location. \n\nThen follow your email program instructions to add the data to your address book.')) window.location = vcfURL;
			});
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			if (XMLHttpRequest.status == 404) return false;
		}
	});
});
