/**
* Returns the content value of a META tag for a given name.
*/

function getmetaContents(mn){ 
  var m = document.getElementsByTagName('meta'); 
  for(var i in m){ 
   if(m[i].name == mn){ 
     return m[i].content; 
   } 
  } 
}



/**
* Provides an easy method for sharing the current page over social networks extracting from META tags
*
* @param {String} socialSite Name of the target sharing site - currently facebook, twitter, myspace, digg, delicious, stumbleupon or reddit. Will use e-mail if none is defined.
* @param {String} urlAppend Optional. Any additional parameters you need to append to the URL string (useful for lightboxes).
* @param {Boolean} newWindow Optional. Determines whether the link opens in a new window. Default value is true.
*
*/

function shareLink(socialSite, urlAppend, newWindow) {
	
	if (newWindow === undefined) {newWindow = true;}
	if (urlAppend === undefined) {urlAppend = '';} else {urlAppend = "&"+urlAppend;}
	var pageTitle = encodeURIComponent(getmetaContents('title'));
	var pageDesc = encodeURIComponent(getmetaContents('description'));
	var pageUrl = encodeURIComponent (document.location.href);

	switch (socialSite.toLowerCase()) {
		case "facebook": link = 'http://www.facebook.com/sharer.php?u='+pageUrl+'&t='+pageTitle+urlAppend; break;
		case "twitter": link = 'http://twitter.com/home?status='+pageTitle+': '+pageUrl; break;
		case "myspace": link = 'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+pageUrl+'&t='+pageTitle+'&c='+pageDesc+urlAppend; break;
		case "digg": link = 'http://digg.com/submit?phase=2&url='+pageUrl+'&title='+pageTitle+urlAppend; break;
		case "delicious": link = 'http://delicious.com/save?url='+pageUrl+'&title='+pageTitle+urlAppend; break;
		case "stumbleupon": link = 'http://www.stumbleupon.com/submit?url='+pageUrl+'&title='+pageTitle+urlAppend; break;
		case "reddit": link = 'http://reddit.com/submit?url='+pageUrl+'&title='+pageTitle+urlAppend; break;
		default: link = 'mailto:?subject='+pageTitle+'&body='+pageDesc+'%0A%0A'+pageUrl;
	}

	//alert(link);
	if (newWindow) {
		window.open(link, '_blank');
	} else {
		window.location.href = link;
	}
}