jQuery.noConflict();
(function($) { 
  $(function() {
    
	$('.facebookShare').click(function(e) {
		e.preventDefault();
		
		FB.login(function(response) {
			if (response.authResponse) {
				 FB.api('/me', function(response) {
					var docTitle = document.title;
					var breadcrumb = $('.breadcrumb a').html().split(' ');
					if (breadcrumb.length > 0) {
						docTitle += ' - ' + breadcrumb[breadcrumb.length-1];
					}
					
					//fix full url / domains
					var imgSrc = $('.post img').attr('src');
					if (imgSrc.indexOf('http') == -1) {
						imgSrc = 'http://' + document.location.hostname + imgSrc.substring(imgSrc.indexOf('/', 7));
					}
					
					if (imgSrc == '') {
						//default image
					}
					
					var obj = {
					  method: 'feed',
					  link: document.location.href,
					  picture: imgSrc,
					  name: docTitle,
					  caption: $('h1').html(),
					};
					
					function callback(response) {
					  console.log("Post ID: " + response['post_id']);
					}
					
					FB.ui(obj, callback);
				   
				 });
			} else {
			 	console.log('User cancelled login or did not fully authorize.');
			}
		}, {scope: 'publish_stream'});
	});
	
	
  });
})(jQuery);


