var SocialShareType = 'clean';
var SocialShareImageSize = '16'; //only 16 and 32 are applicable



var SocialShare = {

	Tags: {

		Facebook: function(url, title){
			var link = 'http://www.facebook.com/sharer.php?u='+url+'&t='+title;
			var img = document.createElement('img');
			img.title = 'Facebook';
			img.alt = 'Facebook';
			img.src = 'share/web/images/socialshare/facebook_'+SocialShareImageSize+'.png';
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		},

		Twitter: function(url){
			var link = 'http://twitter.com/home?status=Currently reading '+url;
			var img = document.createElement('img');
			img.title = 'Twitter';
			img.alt = 'Twitter';
			img.src = 'share/web/images/socialshare/twitter_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		},

		Linkedin: function(url, title){
			var link = 'http://www.linkedin.com/shareArticle?mini=true&url='+url+'&title='+title;
			var img = document.createElement('img');
			img.title = 'LinkedIn';
			img.alt = 'LinkedIn';
			img.src = 'share/web/images/socialshare/linkedin_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		},

		Delicious: function(url, title){
			var link = 'http://delicious.com/save?v=5&noui&jump=close&url='+url+'&title='+title;
			var img = document.createElement('img');
			img.title = 'Delicious';
			img.alt = 'Delicious';
			img.src = 'share/web/images/socialshare/delicious_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});

			return img;
		},

		Technorati: function(url){
			var link = 'http://technorati.com/faves?add='+url;
			var img = document.createElement('img');
			img.title = 'Technorati';
			img.alt = 'Technorati';
			img.src = 'share/web/images/socialshare/technorati_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		},

		Stumbleupon: function(url, title){
			var link = 'http://www.stumbleupon.com/submit?url='+url+'&title='+title;
			var img = document.createElement('img');
			img.title = 'StumbleUpon';
			img.alt = 'StumbleUpon';
			img.src = 'share/web/images/socialshare/stumbleupon_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		},

		Google: function(url, title){
			/*
			var link = 'http://www.google.com/bookmarks/mark?op=edit&bkmk='+url+'&title='+title;
			var img = document.createElement('img');
			img.title = 'Google Bookmarks';
			img.alt = 'Google Bookmarks';
			img.src = 'share/web/images/socialshare/google_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
			*/
			var plus = document.createElement('g:plusone');
			plus.setAttribute('size', 'small');
			return plus;
		},

		Digg: function(url, title){
			var link = 'http://digg.com/submit?phase=2&url='+url+'&title='+title;
			var img = document.createElement('img');
			img.title = 'Digg';
			img.alt = 'Digg';
			img.src = 'share/web/images/socialshare/digg_'+SocialShareImageSize+'.png';
			$(img).attr('class', 'socialshare-img');
			$(img).click(function(){
				SocialShare.ShowSocial(link);
			});
			return img;
		}

	},

	Theme: {
		Clean: function(){

			var url = document.location;
			var title = document.title;

			$('#socialshare').append(SocialShare.Tags.Facebook(url, title));
			$('#socialshare').append(SocialShare.Tags.Twitter(url));
			$('#socialshare').append(SocialShare.Tags.Linkedin(url, title));
			$('#socialshare').append(SocialShare.Tags.Delicious(url, title));
			// $('#socialshare').append(SocialShare.Tags.Technorati(url));
			// $('#socialshare').append(SocialShare.Tags.Stumbleupon(url, title));
			$('#socialshare').append(SocialShare.Tags.Google(url, title));
			// $('#socialshare').append(SocialShare.Tags.Digg(url, title));

		}
	},

	Load: function(){

		if($('socialshare')){
			if(SocialShareType == 'clean'){
				SocialShare.Theme.Clean();
			}
		}

	},

	Show: function(link){
		$('socialshare-window').innerHTML = '';
		iframe = Element('iframe', {'class': '', title:'socialshare', src: link, height:'100%', width:'100%'});
		close = Element('a', {href: 'javascript:void(0);', title: 'Close window', onClick: 'SocialShare.Close()'});
		close.innerHTML = 'Close';
		Element.insert($('socialshare-window'), close);
		$('socialshare-window').insert(iframe);
		Effect.Appear('socialshare-window', {duration: 2.0});
	},

	ShowSocial: function(link){
		window.open (link,"Social","location=0,status=0,scrollbars=0,width=900,height=500");
	},

	Close: function(){
		Effect.Fade('socialshare-window', {duration: 2.0, afterFinish: function(){$('socialshare-window').innerHTML = '';}});
	}

}

$(document).ready(function(){
	SocialShare.Load();
});

