var loc = document.location.href

var pgtitle = document.title

function findLinkByHref(href) {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].href == href) return i;
	}
	return -1;
}

function getTrackingImage(url, network){
	if(!url){
		url = window.location.pathname;
	}
	if(url.indexOf("/") == 0){
		url = url.replace("/", "");
	}
	while(url.indexOf("/") != -1){
		url = url.replace("/", "_");
	}
	url = url.replace(".shtml", "");
	url += "_"+network+'.gif?' + (new Date()).getTime();

	return url;
}

function trackShareAction(network){
	var trackingImg = new Image;
	trackingImg.src = "/images/tracking/" + getTrackingImage(false, network);
	//window.open(trackingImg.src, "share test");
}


function shareLink(linkId) {
	if (document.links.length > 0) {
		if (linkId == 'facebook' || linkId == 'facebook2') {
			trackShareAction('facebook');
			if (document.getElementById) {
				document.getElementById('facebook').href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
				document.getElementById('facebook2').href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
			}
			else if (document.all) {
				document.all['facebook'].href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
				document.all['facebook2'].href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['facebook'].href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
				document.links['facebook2'].href = 'http://www.facebook.com/sharer.php?u=' + loc + '&t=' + pgtitle;
			}
		}
		if (linkId == 'myspace' || linkId == 'myspace2') {
			trackShareAction('myspace');
			if (document.getElementById) {
				document.getElementById('myspace').href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
				document.getElementById('myspace2').href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
			}
			else if (document.all) {
				document.all['myspace'].href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
				document.all['myspace2'].href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['myspace'].href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
				document.links['myspace2'].href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + loc + '&t=' + pgtitle;
			}
		}
		if (linkId == 'digg' || linkId == 'digg2') {
			trackShareAction('digg');
			if (document.getElementById) {
				document.getElementById('digg').href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
				document.getElementById('digg2').href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
			}
			else if (document.all) {
				document.all['digg'].href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
				document.all['digg2'].href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['digg'].href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
				document.links['digg2'].href = 'http://digg.com/submit?url=' + loc + '&title=' + pgtitle;
			}
		}
		if (linkId == 'delicious' || linkId == 'delicious2') {
			trackShareAction('delicious');
			if (document.getElementById) {
				document.getElementById('delicious').href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
				document.getElementById('delicious2').href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
			}
			else if (document.all) {
				document.all['delicious'].href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
				document.all['delicious2'].href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['delicious'].href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
				document.links['delicious2'].href = 'http://delicious.com/save?url=' + loc + '&title=' + pgtitle;
			}
		}
		if (linkId == 'stumble' || linkId == 'stumble2') {
			trackShareAction('stumble');
			if (document.getElementById) {
				document.getElementById('stumble').href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
				document.getElementById('stumble2').href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
			}
			else if (document.all) {
				document.all['stumble'].href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
				document.all['stumble2'].href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['stumble'].href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
				document.links['stumble2'].href = 'http://www.stumbleupon.com/submit?url=' + loc + '&title=' + pgtitle;
			}
		}
		if (linkId == 'twitter' || linkId == 'twitter2') {
			trackShareAction('twitter');
			if (document.getElementById) {
				document.getElementById('twitter').href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
				document.getElementById('twitter2').href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
			}
			else if (document.all) {
				document.all['twitter'].href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
				document.all['twitter2'].href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['twitter'].href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
				document.links['twitter2'].href = 'http://twitter.com/home?status=' + pgtitle + ':+' + loc;
			}
		}
		if (linkId == 'buzz' || linkId == 'buzz2') {
			trackShareAction('buzz');
			if (document.getElementById) {
				document.getElementById('buzz').href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
				document.getElementById('buzz2').href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
			}
			else if (document.all) {
				document.all['buzz'].href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
				document.all['buzz2'].href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
			}
			else {
				var index = findLinkByHref('#');
				if (index > -1)
				document.links['buzz'].href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
				document.links['buzz2'].href = 'http://www.google.com/reader/link?url=' + loc + '&title=' + pgtitle;
			}
		}
	}
}





