// Social Media Buttons

var page_url, allpages, mediaButtonsTop;
var page_url=unescape(location.href);
if (location.hostname == "www.dentalfreeway.com" || location.hostname == "www.medicalfreeway.com") {
	page_url = "http:/\/"+location.hostname + page_url.substr(page_url.lastIndexOf('/'))
}
var siteURL = "http:/\/"+location.hostname+"/"
var homePage = "http:/\/"+location.hostname+"/index.asp"

function initSocialMedia() {

	$.getScript("https://apis.google.com/js/plusone.js");
	$.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function() {
		window.fbAsyncInit = function() {FB.init({status: true, cookie: true, xfbml: true});}; 	FB.Event.subscribe('edge.create', function(targetUrl) { _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);});
	});
	$.getScript("http://platform.twitter.com/widgets.js", function(){
		twttr.events.bind('tweet', function(event) { if (event) { var targetUrl;  if (event.target && event.target.nodeName == 'IFRAME') { targetUrl = extractParamFromUri(event.target.src, 'url'); }_gaq.push(['_trackSocial', 'twitter', 'tweet', targetUrl]); }});
	});
	
	var output = '<div style="width: 100%; padding-top: 10px;">';
	output += '  <div style="width: 36px; float: left;"><div class="g-plusone" data-size="medium" data-count="false"></div></div>';
	output += '  <div style="width: 50px; margin-right: 2px; float: left; overflow: hidden;"><div id="fb-root"></div><fb:like href="" send="false" layout="button_count" width="40" show_faces="false" font=""></fb:like></div>';
	output += '  <div style="width: 60px; float: left;"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a></div>';
	output += '  <div style="clear: both;"></div>';
	output += '</div>';
	
	
	if ($("#content_main").length > 0) {
		if (mediaButtonsTop) {
			if($("#content_main > h1:first").length != 0) {
				$(output).insertAfter("#content_main > h1");  
			} else {
				$("#content_main").prepend(output);   
			}
		} else {
			$("#content_main").append(output);   
		}
	} else {
		if (mediaButtonsTop) {
			if($("#content_main_home > h1:first").length != 0) {
				$(output).insertAfter("#content_main_home > h1");  
			} else {
				$("#content_main_home").prepend(output);   
			}
		} else {
			$("#content_main_home").append(output);   
		}
	}
}


// Implement socialmedia code as long as the current page is the homepage
if (page_url == siteURL || page_url == homePage) {
	checkjQuery(initSocialMedia);
} else if (allpages) {
	checkjQuery(initSocialMedia);
}
