﻿
// write out social bookmarks
document.write('<div id="socialSharing"><ul class="share">');
document.write('<li><strong>SHARE:</strong></li>');
document.write('<li><a id="delicious" title="Share this page with Delicious" href="javascript:shareArticle(0)">Del.icio.us</a></li>');
document.write('<li><a id="digg" title="Share this article with Digg"  href="javascript:shareArticle(1)">Digg</a></li>');
document.write('<li><a id="google" title="Share this article with Google" href="javascript:shareArticle(2)">Google</a></li>');
document.write('<li><a id="yahoo" title="Share this article with Yahoo" href="javascript:shareArticle(3)">Yahoo!</a></li>');
document.write('<li><a id="facebook" title="Share this article with Facebook" href="javascript:shareArticle(4)">Facebook</a></li>');
document.write('<li><a id="linkedin" title="Share this article with LinkedIn" href="javascript:shareArticle(5)">LinkedIn</a></li>');
document.write('</ul></div>');

// encode url
var articleURL = encodeURIComponent(document.location.href);

// escape characters in title
var articleTitle = escape(document.title);

// declare popup variable
var popupWin = '';

// create popup window
function shareArticleWin(URLAddress)
{
	if (!popupWin.closed && popupWin.location){
		popupWin.location.href = URLAddress;
	}
	else{
		popupWin = window.open(URLAddress,'ShareArticlePopUp','width=700px,height=500px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=100');
		if (!popupWin.opener) popupWin.opener = self;
	}
	if (window.focus) {popupWin.focus()}
	return false;
}

// close popupWin
function closePopUp() {
	if (!popupWin.closed && popupWin.location){
		if (popupWin.location.href == articleURL)	//if it's the same url as what was bookmarked, close the win
		popupWin.close();
	}
}

// main function - switch case for each Social Bookmarking site
// Site = bookmark site base url
// Below variable account for different sites using different parameters for url, title, etc.
//  Url = variable to pass in querystring for url
//  title = variable to pass in querystring for title
//  Return = variable to pass in querystring for Return
//  Other = variable to pass in querystring for any Other variables needed
function shareArticle(sites){
	switch(sites){
		case 0:	// Delicious
			var Site = "http://del.icio.us/post?v=4&noui&jump=close&";
			var Url = "url";
			var Title = "title";
			var Return = "";
			var Other = "";	
			break
		case 1:	// Digg
			var Site = "http://digg.com/remote-submit?phase=2&";
			var Url = "url";
			var Title =  "title";
			var Return =  "";
			var Other = "";
			break
		case 2:	// Google
			var Site = "http://www.google.com/bookmarks/mark?op=add&";
			var Url = "bkmk";
			var Title = "title";
			var Return = "";
			var Other = "";
			break
		case 3:	// Yahoo
			var Site = "http://myweb2.search.yahoo.com/myresults/bookmarklet?";
			var Url = "u";
			var Title = "t";
			var Return = "";
			var Other = "&d=&ei=UTF-8";
			break
		case 4:	// Facebook
			var Site = "http://www.facebook.com/sharer.php?";
			var Url = "u";
			var Title = "t";
			var Return = "";
			var Other = "";
			break
		case 5:	// Linkedin
			var Site = "http://www.linkedin.com/shareArticle?mini=true&";
			var Url = "url";
			var Title = "title";
			var Return = "";
			var Other = "";
			break
		default:
	}
    // Build the URL
	var URLAddress = Site + Url + "=" + articleURL + "&" + Title + "=" + articleTitle + Other ;
	if (Return != "")
		{var URLAddress = URLAddress + "&" + Return + "=" + articleURL;}
    
    // Call popup
    shareArticleWin(URLAddress);
}