// file for thermometer

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

var totalCount = 0;
function updateTotal()	{
	var maxShared = 50000;
	var maxPixelHeight = 200;
	//totalCount = 0;
	var origCount = totalCount;
	if(totalCount > 50000) totalCount= 50000;  /// don't let it go over 50000
	var actualCountPixels = parseInt((maxPixelHeight*totalCount)/maxShared);
	$('#shareCount_meter_unshared').css({
		"top": "0px",
		//"height": (maxPixelHeight - actualCountPixels) + "px"
		"height": maxPixelHeight + "px"   // leave full height other one covers it
	});
	$('#shareCount_meter_shared').animate({
		"top": (maxPixelHeight - actualCountPixels) + "px",
		"height": actualCountPixels
	},2000);
	$('#shareCount_meter_marker').animate({
		"top": (maxPixelHeight - actualCountPixels - 6 ) + "px"
	},2000);
	$('#sharedSiteCount').html(addCommas(origCount) + "&nbsp");
	$('div#shareCount_meter_unshared, div#shareCount_meter_marker').show();
	$('div#shareCount_meter_shared').show(); 
	
}
function getSocialCounts()	{
	var domainURL = "http://vaccines.com" ;   // hard coded per META og:url tag to match
	var fb_count = 0;
	var tw_count = 0;
	var count_about = 0;
	var count_aboutVaccine = 0;
	var count_educate = 0;
	var count_hepB = 0;
	var count_hpv = 0;
	var count_flu = 0;
	var count_measles = 0;
	var count_whooping = 0;
	var count_polio = 0;
	var count_privacy = 0;
	var count_protect = 0;
	var count_search = 0;
	var count_sitemap = 0;
	var count_vaccinations = 0;
	var count_questions = 0;
	var count_adults = 0;
	var count_safety = 0;
	var count_infants = 0;
	var count_teens = 0;
	var count_references = 0;
	var count_seniors = 0;
	var count_why = 0;
	var count_fact01 = 0;
	var count_fact02 = 0;
	var count_fact03 = 0;
	var count_fact04 = 0;
	var count_fact05 = 0;
	var count_fact06 = 0;
	var count_fact07 = 0;
	var count_fact08 = 0;
	var count_fact09 = 0;
	var count_fact10 = 0;
	var count_fact11 = 0;
	var count_fact12 = 0;

	// defining variable - page 
	var fb_API = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://vaccines.com'&format=json&callback=?";
	var fb_about = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/educate-others.cfm'&format=json&callback=?";
	var ct_aboutVaccine = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/about-vaccines.cfm'&format=json&callback=?";
	var ct_educate = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/educate-others.cfm'&format=json&callback=?";
	var ct_hepB = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/hepatitis-b-vaccine.cfm'&format=json&callback=?";
	var ct_hpv = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/hpv-human-papillomavirus-vaccine.cfm'&format=json&callback=?";
	var ct_flu = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/influenza-vaccine.cfm'&format=json&callback=?";
	var ct_measles = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/measles-history.cfm'&format=json&callback=?";
	var ct_whooping = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/pertussis-whooping-cough-vaccine.cfm'&format=json&callback=?";
	var ct_polio = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/polio-vaccine.cfm'&format=json&callback=?";
	var ct_privacy = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/privacy-policy.cfm'&format=json&callback=?";
	var ct_protect = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/protect-your-family.cfm'&format=json&callback=?";
	var ct_search = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/search-results.cfm'&format=json&callback=?";
	var ct_sitemap = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/sitemap.cfm'&format=json&callback=?";
	var ct_vaccinations = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccinations.cfm'&format=json&callback=?";
	var ct_questions = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccine-questions-answers.cfm'&format=json&callback=?";
	var ct_adults = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccines-adults.cfm'&format=json&callback=?";
	var ct_safety = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccine-safety.cfm'&format=json&callback=?";
	var ct_infants = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccines-infants-young-children.cfm'&format=json&callback=?";
	var ct_teens = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccines-pre-teens.cfm'&format=json&callback=?";
	var ct_references = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccines-references.cfm'&format=json&callback=?";
	var ct_seniors = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/vaccines-seniors.cfm'&format=json&callback=?";
	var ct_why = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate.cfm'&format=json&callback=?";
	var ct_fact01 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-01.cfm'&format=json&callback=?";
	var ct_fact02 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-02.cfm'&format=json&callback=?";
	var ct_fact03 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-03.cfm'&format=json&callback=?";
	var ct_fact04 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-04.cfm'&format=json&callback=?";
	var ct_fact05 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-05.cfm'&format=json&callback=?";
	var ct_fact06 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-06.cfm'&format=json&callback=?";
	var ct_fact07 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-07.cfm'&format=json&callback=?";
	var ct_fact08 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-08.cfm'&format=json&callback=?";
	var ct_fact09 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-09.cfm'&format=json&callback=?";
	var ct_fact10 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-10.cfm'&format=json&callback=?";
	var ct_fact11 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-11.cfm'&format=json&callback=?";
	var ct_fact12 = "http://api.facebook.com/method/fql.query?query=select total_count,like_count,comment_count,share_count,click_count from link_stat where url='http://www.vaccines.com/why-vaccinate-fact-12.cfm'&format=json&callback=?";	
	// defining variable - twitter 
	var tw_API = "http://urls.api.twitter.com/1/urls/count.json?url=" + domainURL + "&callback=?";
	
	// Facebook
	$.ajax({
		url: fb_API,
		async: false,
		dataType: "json",
		success: function(fb_result) {
			 var fbResults = fb_result;
			 fb_count = fbResults[0].total_count;
			// this does the math
			totalCount += fb_count;
			// this does the math

			//this call for twitter numbers
			$.ajax({
				url: tw_API,
				async: false,
				dataType: "json",
				success: function(tw_result) {
					 var twResults = tw_result;
					 tw_count = twResults.count;
					 // this does the math
					 totalCount += tw_count;
					 // this does the math
					 			//this call for about-immyounity numbers
								$.ajax({
									url: fb_about,
									async: false,
									dataType: "json",
									success: function(about_result) {
										 var aboutResults = about_result;
										 count_about = aboutResults.count;
										 // this does the math
										 totalCount += count_about;
										 // this does the math
										//this call for about-vaccine numbers
										$.ajax({
											url: ct_aboutVaccine,
											async: false,
											dataType: "json",
											success: function(aboutVaccine_result) {
												 var aboutVaccine = aboutVaccine_result;
												 count_aboutVaccine = aboutVaccine.count;
												 // this does the math
												 totalCount += count_aboutVaccine;
												 // this does the math
												//this call for about-vaccine numbers
												$.ajax({
													url: count_educate,
													async: false,
													dataType: "json",
													success: function(educate_result) {
														 var educateResult = educate_result;
														 count_educate = educateResult.count;
														 // this does the math
														 totalCount += count_educate;
														 // this does the math
														$.ajax({
															url: count_hepB,
															async: false,
															dataType: "json",
															success: function(hepB_result) {
																 var hepBResult = hepB_result;
																 count_hepB = hepBResult.count;
																 // this does the math
																 totalCount += count_hepB;
																 // this does the math
																 $.ajax({
																	url: count_hpv,
																	async: false,
																	dataType: "json",
																	success: function(hpv_result) {
																		 var hpvResult = hpv_result;
																		 count_hpv = hpvResult.count;
																		 // this does the math
																		 totalCount += count_hpv;
																		 // this does the math
$.ajax({
	url: count_flu,
	async: false,
	dataType: "json",
	success: function(flu_result) {
		var fluResult = flu_result;
		count_flu = fluResult.count;
		// this does the math
		totalCount += count_flu;
		// this does the math
$.ajax({
	url: count_measles,
	async: false,
	dataType: "json",
	success: function(measles_result) {
		var measlesResult = measles_result;
		count_measles = measlesResult.count;
		// this does the math
		totalCount += count_measles;
		// this does the math
$.ajax({
	url: count_whooping,
	async: false,
	dataType: "json",
	success: function(whooping_result) {
		var whoopingResult = whooping_result;
		whooping_measles = whoopingResult.count;
		// this does the math
		totalCount += count_whooping;
		// this does the math
$.ajax({
	url: count_polio,
	async: false,
	dataType: "json",
	success: function(polio_result) {
		var polioResult = polio_result;
		count_polio = polioResult.count;
		// this does the math
		totalCount += count_polio;
		// this does the math
$.ajax({
	url: count_privacy,
	async: false,
	dataType: "json",
	success: function(privacy_result) {
		var privacyResult = privacy_result;
		count_privacy = privacyResult.count;
		// this does the math
		totalCount += count_privacy;
		// this does the math
$.ajax({
	url: count_protect,
	async: false,
	dataType: "json",
	success: function(protect_result) {
		var protectResult = protect_result;
		count_protect = protectResult.count;
		// this does the math
		totalCount += count_protect;
		// this does the math
$.ajax({
	url: count_search,
	async: false,
	dataType: "json",
	success: function(search_result) {
		var searchResult = search_result;
		count_search = searchResult.count;
		// this does the math
		totalCount += count_search;
		// this does the math
$.ajax({
	url: count_sitemap,
	async: false,
	dataType: "json",
	success: function(sitemap_result) {
		var sitemapResult = sitemap_result;
		count_sitemap = sitemapResult.count;
		// this does the math
		totalCount += count_sitemap;
		// this does the math
$.ajax({
	url: count_vaccinations,
	async: false,
	dataType: "json",
	success: function(vaccinations_result) {
		var vaccinationsResult = vaccinations_result;
		count_vaccinations = vaccinationsResult.count;
		// this does the math
		totalCount += count_vaccinations;
		// this does the math
$.ajax({
	url: count_questions,
	async: false,
	dataType: "json",
	success: function(questions_result) {
		var questionsResult = questions_result;
		count_questions = questionsResult.count;
		// this does the math
		totalCount += count_questions;
		// this does the math
$.ajax({
	url: count_adults,
	async: false,
	dataType: "json",
	success: function(adults_result) {
		var adultsResult = adults_result;
		count_adults = adultsResult.count;
		// this does the math
		totalCount += count_adults;
		// this does the math
$.ajax({
	url: count_safety,
	async: false,
	dataType: "json",
	success: function(safety_result) {
		var safetyResult = safety_result;
		count_safety = safetyResult.count;
		// this does the math
		totalCount += count_safety;
		// this does the math
$.ajax({
	url: count_infants,
	async: false,
	dataType: "json",
	success: function(infants_result) {
		var infantsResult = infants_result;
		count_infants = infantsResult.count;
		// this does the math
		totalCount += count_infants;
		// this does the math
$.ajax({
	url: count_teens,
	async: false,
	dataType: "json",
	success: function(teens_result) {
		var teensResult = teens_result;
		count_teens = teensResult.count;
		// this does the math
		totalCount += count_teens;
		// this does the math
$.ajax({
	url: count_references,
	async: false,
	dataType: "json",
	success: function(references_result) {
		var referencesResult = references_result;
		count_references = referencesResult.count;
		// this does the math
		totalCount += count_references;
		// this does the math
$.ajax({
	url: count_seniors,
	async: false,
	dataType: "json",
	success: function(seniors_result) {
		var seniorsResult = seniors_result;
		count_seniors = seniorsResult.count;
		// this does the math
		totalCount += count_seniors;
		// this does the math
$.ajax({
	url: count_why,
	async: false,
	dataType: "json",
	success: function(why_result) {
		var whyResult = why_result;
		count_why = whyResult.count;
		// this does the math
		totalCount += count_why;
		// this does the math
$.ajax({
	url: count_fact01,
	async: false,
	dataType: "json",
	success: function(fact01_result) {
		var fact01Result = fact01_result;
		count_fact01 = fact01Result.count;
		// this does the math
		totalCount += count_fact01;
		// this does the math
$.ajax({
	url: count_fact02,
	async: false,
	dataType: "json",
	success: function(fact02_result) {
		var fact02Result = fact02_result;
		count_fact02 = fact02Result.count;
		// this does the math
		totalCount += count_fact02;
		// this does the math
$.ajax({
	url: count_fact03,
	async: false,
	dataType: "json",
	success: function(fact03_result) {
		var fact03Result = fact03_result;
		count_fact03 = fact03Result.count;
		// this does the math
		totalCount += count_fact03;
		// this does the math
$.ajax({
	url: count_fact04,
	async: false,
	dataType: "json",
	success: function(fact04_result) {
		var fact04Result = fact04_result;
		count_fact04 = fact04Result.count;
		// this does the math
		totalCount += count_fact04;
		// this does the math
$.ajax({
	url: count_fact05,
	async: false,
	dataType: "json",
	success: function(fact05_result) {
		var fact05Result = fact05_result;
		count_fact05 = fact05Result.count;
		// this does the math
		totalCount += count_fact05;
		// this does the math
$.ajax({
	url: count_fact06,
	async: false,
	dataType: "json",
	success: function(fact06_result) {
		var fact06Result = fact06_result;
		count_fact06 = fact06Result.count;
		// this does the math
		totalCount += count_fact06;
		// this does the math
$.ajax({
	url: count_fact07,
	async: false,
	dataType: "json",
	success: function(fact07_result) {
		var fact07Result = fact07_result;
		count_fact07 = fact07Result.count;
		// this does the math
		totalCount += count_fact07;
		// this does the math
$.ajax({
	url: count_fact08,
	async: false,
	dataType: "json",
	success: function(fact08_result) {
		var fact08Result = fact08_result;
		count_fact08 = fact08Result.count;
		// this does the math
		totalCount += count_fact08;
		// this does the math
$.ajax({
	url: count_fact09,
	async: false,
	dataType: "json",
	success: function(fact09_result) {
		var fact09Result = fact09_result;
		count_fact09 = fact09Result.count;
		// this does the math
		totalCount += count_fact09;
		// this does the math
$.ajax({
	url: count_fact10,
	async: false,
	dataType: "json",
	success: function(fact10_result) {
		var fact10Result = fact10_result;
		count_fact10 = fact10Result.count;
		// this does the math
		totalCount += count_fact10;
		// this does the math
$.ajax({
	url: count_fact11,
	async: false,
	dataType: "json",
	success: function(fact11_result) {
		var fact11Result = fact11_result;
		count_fact11 = fact11Result.count;
		// this does the math
		totalCount += count_fact11;
		// this does the math
$.ajax({
	url: count_fact12,
	async: false,
	dataType: "json",
	success: function(fact12_result) {
		var fact12Result = fact12_result;
		count_fact12 = fact12Result.count;
		// this does the math
		totalCount += count_fact12;
		// this does the math
		// ajax call goes here
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
		}, 
			error: function() {
			totalCount += 0;
	}
});
																	}, 
																	error: function() {
																		totalCount += 0;
																	}
																});
															}, 
															error: function() {
																totalCount += 0;
															}
														});
													}, 
													error: function() {
														totalCount += 0;
													}
												});

										 //updateTotal();
									}, 
									error: function() {
										totalCount += 0;
									}
								});
										 //updateTotal();
									}, 
									error: function() {
										totalCount += 0;
									}
								});
					 updateTotal();
				}, 
				error: function() {
					totalCount += 0;
				}
			});
		}, 
		error: function() {
			totalCount += 0;
		}
		});		
	// Twitter
}	

$(document).ready( function (){
	if($('#shareCount_container').length)	{    // only if the thermometer exists
		getSocialCounts();
	}
});

