function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function insertAfter( referenceNode, newNode )
{
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

document.write('<div id="fb-root"></div>');
document.write('<scr'+'ipt src="http://connect.facebook.net/en_US/all.js#appId=188876454493337&amp;xfbml=1"></scr'+'ipt>');
document.write('<scr'+'ipt src="http://platform.twitter.com/widgets.js" type="text/javascript"></scr'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4dd190dc2dc61e02"></scr'+'ipt>');

var socialScripts = {
	init: function()
	{
		var pageName = document.getElementById('pageName');
		if (pageName&&!document.getElementById('main_heading'))
		{
			var socialDiv = document.createElement('div');
			socialDiv.id = 'social';
			insertAfter(pageName, socialDiv);
			document.getElementById('social').style.height = '30px';
			
			var addthis_config = {"data_track_clickback":true};
			socialDiv = document.getElementById('social');

			// Twitter Share Button
			socialDiv.innerHTML += '<div style="float: left; margin-right: 10px;"><a href="http://twitter.com/share?text=Check out this page on tbc.edu!&count=none" class="twitter-share-button">Tweet</a></div>';
			// AddThis Sharing Toolbox
			socialDiv.innerHTML += '<div class="addthis_toolbox addthis_default_style " style="float: left; margin-right: 10px;"><a class="addthis_counter addthis_pill_style"></a></div>';
			// Facebook Like Button
			socialDiv.innerHTML += '<fb:like href="http://www.facebook.com/trinitybaptistcollege" send="false" layout="button_count" width="150" show_faces="false" font="arial"></fb:like></div>';
		}
	}
}
socialScripts.init();

var fb_publisher = {
	init: function()
	{
		try {if (fb_publish_info) fb_publisher.publish();}
		catch(err) {return false;}
	},
	publish: function()
	{
		FB.ui(
			{
				method: 'feed',
				name: fb_publish_info.name,
				link: fb_publish_info.link,
				picture: fb_publish_info.picture,
				caption: fb_publish_info.caption,
				description: fb_publish_info.description,
				message: fb_publish_info.message
			},
			function(response) {
				if (response && response.post_id) {
				} else {
					return false;
				}
			}
		);
	}
}

//addLoadEvent(fb_publisher.init);

var publishPrompt = {
	init: function()
	{
		try {if (fb_publish_info) publishPrompt.create();}
		catch(err) {return false;}
	},
	create: function()
	{
		var publishDiv = document.createElement('div');
		publishDiv.setAttribute('id', 'publish_div');
		if (document.getElementById('main_heading'))
		{
			insertAfter(document.getElementById('main_heading'), publishDiv);
			publishDiv.innerHTML =
				'<div style="float: left;width: 400px;margin: 10px 10px 10px;border:solid 1px #bbb;padding:5px;text-align: center;">'+
				'<h4 style="float: left;">Share TBC on Facebook!</h4>'+
				'<a href="#" id="fb_publish_button" style="background: #3B5999; color: #FFF;display: block;padding: 7px;width: 150px;text-align: center;text-decoration: none;font-size: 12px;float: right;margin: 10px 8px 0 0;border:outset 1px;font-weight: bold;">Spread the Word</a>'+
				'</div>';
		} else if (document.getElementById('social')) {
			insertAfter(document.getElementById('social'), publishDiv);
			publishDiv.innerHTML =
				'<div style="float: left;width: 480px;margin-bottom: 10px;border: solid 1px;padding:10px;">'+
				'<h4>Share This on Facebook!</h4>'+
				'<a href="#" id="fb_publish_button" style="background: #3B5999; color: #FFF;display: block;padding: 7px;width: 150px;text-align: center;text-decoration: none;font-size: 12px;float: right;margin: 10px 0 0 0;border:outset 1px;font-weight: bold;">Preview Your Post!</a>'+
				'</div>';
		} 
		document.getElementById('fb_publish_button').onclick = function() {fb_publisher.publish();};
	}
}

addLoadEvent(publishPrompt.init);
