/* ================================================================
Free for use

The original version of this short url script
is available at http://www.nuff-respec.com/technology/social-bookmarking-madness
Copyright (c) 2005-2007 Daniel Bulli. All rights reserved.
This code may be modified in any way to fit your requirements.
=================================================================== */

var SocialBookmarking = 
{
	'initted':false,
	'cssfile':"/external/Madness/c/default.css", //default css file
	
	/**
	 * init SocialBookmarking 
	 * (no need to call directly, unless not using default css above)
	 *
	 * @access	public
	 * @param	boolean	whether or not to add css file
	 * @param	string	path to css file
	 * @return	
	 */	
	init:function(dontAddCss,cssFile) 
	{
		this.initted = true;
		
		//default set + order
		this.whichones =  ["delicious","digg","technorati","reddit","stumbleupon"];
		
		//default bookmarks
		this.bookmarks = new Object();

		
		this.addBookmark('ask','http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url=%%URL%%&title=%%TITLE%%','ask');
		this.addBookmark('backflip','http://www.backflip.com/add_page_pop.ihtml?url=%%URL%%&title=%%TITLE%%','backflip');
		this.addBookmark('blinkbits','http://blinkbits.com/bookmarklets/save.php?v=1&source_url=%%URL%%&title=%%TITLE%%','blinkbits');
		this.addBookmark('blinklists','http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url=%%URL%%&Title=%%TITLE%%','blinklists');
		this.addBookmark('blogmarks','http://blogmarks.net/my/new.php?mini=1&simple=1&url=%%URL%%&title=%%TITLE%%','blogmarks');		
		this.addBookmark('bluedot','http://bluedot.us/Authoring.aspx?u=%%URL%%&t=%%TITLE%%','bluedot');
		this.addBookmark('bumpzee','http://www.bumpzee.com/bump.php?u==%%URL%%&t=%%TITLE%%','bumpzee');
		this.addBookmark('citeulike','http://www.citeulike.org/posturl?url=%%URL%%&title=%%TITLE%%','citeulike');
		this.addBookmark('comments','http://co.mments.com/track?url=%%URL%%&title=%%TITLE%%','comments');
		this.addBookmark('delicious','http://del.icio.us/post?v=4&noui&jump=close&url=%%URL%%&title=%%TITLE%%','del.icio.us');
		this.addBookmark('delirous','http://de.lirio.us/rubric/post?uri=%%URL%%&title=%%TITLE%%','delirous');
		this.addBookmark('digg','http://digg.com/submit?phase=2&url=%%URL%%&title=%%TITLE%%','digg');
		this.addBookmark('diigo','http://www.diigo.com/post?url=%%URL%%&title=%%TITLE%%','diigo');
		this.addBookmark('dropjack','http://www.dropjack.com/submit.php?url=%%URL%%&title=%%TITLE%%','dropjack');
		this.addBookmark('dzone','http://www.dzone.com/links/add.html?url=%%URL%%&title=%%TITLE%%','dzone');
		this.addBookmark('excites','http://www.excites.com/save_link/?url=%%URL%%&title=%%TITLE%%','excites');
		this.addBookmark('facebook','http://www.facebook.com/share.php?u=%%URL%%&t=%%TITLE%%','facebook');
		this.addBookmark('fark','http://cgi.fark.com/cgi/fark/submit.pl?new_url=%%URL%%&new_comment=%%TITLE%%','fark');
		this.addBookmark('feedmelinks','http://feedmelinks.com/categorize?from=toolbar&op=submit&url=%%URL%%&name=%%TITLE%%','feedmelinks');
		this.addBookmark('furl','http://www.furl.net/storeIt.jsp?u=%%URL%%&t=%%TITLE%%','furl');
		this.addBookmark('google','http://www.google.com/bookmarks/mark?op=add&bkmk=%%URL%%&title=%%TITLE%%','google');
		this.addBookmark('gravee','http://www.gravee.com/account/bookmarkpop?u=%%URL%%&t=%%TITLE%%','gravee');
		this.addBookmark('hyper','http://www.hyperlinkomatic.com/lm2/add.html?LinkUrl=%%URL%%&LinkTitle=%%TITLE%%','hyper');
		this.addBookmark('jigg','http://www.jigg.in/submit.php?url=%%URL%%&title=%%TITLE%%','jigg');
		this.addBookmark('kinja','http://kinja.com/id.knj?url=%%URL%%&title=%%TITLE%%','kinja');
		this.addBookmark('linkagogo','http://www.linkagogo.com/go/AddNoPopup?url=%%URL%%&title=%%TITLE%%','linkagogo');
		this.addBookmark('live','https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=%%URL%%&title=%%TITLE%%','live');
		this.addBookmark('magnolia','http://ma.gnolia.com/bookmarklet/add?url=%%URL%%&title=%%TITLE%%','magnolia');
		this.addBookmark('misterwong','http://www.mister-wong.com/addurl/?bm_url=%%URL%%&bm_description=%%TITLE%%','misterwong');
		this.addBookmark('netscape','http://www.netscape.com/submit/?U=%%URL%%&T=%%TITLE%%','netscape');
		this.addBookmark('netvous','http://www.netvouz.com/action/submitBookmark?url=%%URL%%&title=%%TITLE%%','netvous');
		this.addBookmark('newsvine','http://www.newsvine.com/_tools/seed&save?u=%%URL%%&t=%%TITLE%%','newsvine');
		this.addBookmark('rawsugar','http://www.rawsugar.com/tagger/?turl=%%URL%%&tttl=%%TITLE%%','rawsugar');
		this.addBookmark('reddit','http://reddit.com/submit?url=%%URL%%&title=%%TITLE%%','reddit');
		this.addBookmark('rojo','http://www.rojo.com/add-subscription/?resource=%%URL%%','rojo');
		this.addBookmark('segnalo','http://segnalo.alice.it/post.html.php?url=%%URL%%&title=%%TITLE%%','segnalo');
		this.addBookmark('shadows','http://www.shadows.com/bookmark/saveLink.rails?page=%%URL%%&title=%%TITLE%%','shadows');
		this.addBookmark('simpy','http://www.simpy.com/simpy/LinkAdd.do?href=%%URL%%&title=%%TITLE%%','simpy');
		this.addBookmark('slashdot','http://slashdot.org/bookmark.pl?url=%%URL%%&title=%%TITLE%%','slashdot');
		this.addBookmark('smarking','http://smarking.com/editbookmark/?url=%%URL%%&title=%%TITLE%%','smarking');
		this.addBookmark('sphere','http://www.sphere.com/search?q=sphereit:%%URL%%','sphere');
		this.addBookmark('spurl','http://www.spurl.net/spurl.php?url=%%URL%%&title=%%TITLE%%','spurl');
		this.addBookmark('squidoo','http://www.squidoo.com/lensmaster/bookmark?%%URL%%','squidoo');
		this.addBookmark('stumble','http://www.stumbleupon.com/submit?url=%%URL%%&title=%%TITLE%%','stumbleupon');
		this.addBookmark('tailrank','http://tailrank.com/share/?text=&link_href=%%URL%%&t=%%TITLE%%','tailrank');
		this.addBookmark('technorati','http://technorati.com/faves/?add=%%URL%%','technorati');
		this.addBookmark('thisnext','http://www.thisnext.com/pick/new/submit/sociable/?url=%%URL%%&title=%%TITLE%%','thisnext');
		this.addBookmark('wink','http://wink.com/_/tag?url=%%URL%%&doctitle=%%TITLE%%','wink');
		this.addBookmark('wists','http://wists.com/s.php?c=&r=%%URL%%&title=%%TITLE%%','wists');
		this.addBookmark('yahoomyweb','http://myweb2.search.yahoo.com/myresults/bookmarklet?u=%%URL%%&t=%%TITLE%%','yahoomyweb');
		this.addBookmark('ybmk','http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=%%URL%%&t=%%TITLE%%','ybmk');
		this.addBookmark('zurpy','http://tag.zurpy.com/?box=1&url=%%URL%%&title=%%TITLE%%','zurpy');
		
		//all purpose ones
		this.addBookmark('addthis','http://www.addthis.com/bookmark.php?pub=addthis&url=%%URL%%&title=%%TITLE%%','addthis');
		this.addBookmark('socialiser','http://ekstreme.com/socializer/?url=%%URL%%&title=%%TITLE%%','socialiser');		

		if(!dontAddCss)
		{		
			cssFile = (cssFile) ? cssFile : this.cssfile;
			this.addCSS(cssFile);
		}
	},

	/**
	 * add a new css file to document
	 *
	 * @access	public
	 * @param	string	path to css file
	 * @return	
	 */	
	addCSS: function(cssFile)
	{
		if(!this.initted) this.init();
		
		//no css provided
		if (!cssFile) return;		
		
		try
		{
			var headID = document.getElementsByTagName("head")[0];         
			var cssNode = document.createElement('link');
			cssNode.type = 'text/css';
			cssNode.rel = 'stylesheet';
			cssNode.href = cssFile;
			cssNode.media = 'screen';
			headID.appendChild(cssNode);
		}
		catch(e){}
	},

	/**
	 * replace a div with certain ID
	 *
	 * @access	public
	 * @param	string	div id
	 * @param	string	url of page (only set if different than current page)
	 * @param	string	title of page (only set if different than current page)
	 * @param	array	array of strings of bookmarks to show (only set if different than default)
	 * @return	
	 */	
	replaceDIV: function(divID,url,title,whichones)
	{
		if(!this.initted) this.init();	
		divID = (divID) ? divID : 'social_bookmarking';
		if(document.getElementById && document.getElementById(divID))
		{
			document.getElementById(divID).innerHTML = this.getBookmarks(url,title,whichones);
		}
	},
	
	

	/**
	 * Writes out unordered list of bookmarks
	 *
	 * @access	public
	 * @param	string	url of page (only set if different than current page)
	 * @param	string	title of page (only set if different than current page)
	 * @param	array	array of strings of bookmarks to show (only set if different than default OR 'ALL')
	 * @return	
	 */	
	writeBookmarks: function(url,title,whichones)
	{
		if(!this.initted) this.init();
		document.write(this.getBookmarks(url,title,whichones));
	},
	
	
	/**
	 * Retrieved HTML for unodered list
	 *
	 * @access	public
	 * @param	string	url of page (only set if different than current page)
	 * @param	string	title of page (only set if different than current page)
	 * @param	array	array of strings of bookmarks to show (only set if different than default)
	 * @return	HTML Unordered list
	 */	
	getBookmarks: function(url,title,whichones,classname)
	{
		if(!this.initted) this.init();
		var classname = (classname) ? classname : 'social_bookmarks'
		var out = '<ul class="'+ classname + '">';
		
		whichones_u = (whichones && whichones != 'all') ? whichones : this.whichones;

		var l = whichones_u.length;
	
		if(whichones != 'all')
		{
			for( var i=0; i < l; i++ ) 
			{
				if(this.bookmarks[whichones_u[i]])
				{
					out += ''+this.getBookmarkItem(this.bookmarks[whichones_u[i]],url,title)+'';
				}
			}
		}
		else
		{
			for(var bookmark in this.bookmarks) 
			{
				out += ''+this.getBookmarkItem(this.bookmarks[bookmark],url,title)+'';
			}		
		}
		out += '</ul>';
		return out;
	},
	

	/**
	 * Retrieve bookmarkitem
	 *
	 * @access	public
	 * @param	object	bookmark object
	 * @param	string	url of page (only set if different than current page)
	 * @param	string	title of page (only set if different than current page)
	 * @return	HTML href link
	 */		
	getBookmarkItem: function(bookmark,url,title)
	{
		if(!this.initted) this.init();
		
		var url   = (url) ? encodeURIComponent(url) : encodeURIComponent(location.href);
		var title = (title) ? encodeURIComponent(title) : encodeURIComponent(document.title);
		
		var out =  '<li class="' + bookmark.css + '"><a href="' + bookmark.url + '" title="'+bookmark.title+'"><span>' + bookmark.title + '</span></a></li>';
		out = out.replace('%%TITLE%%',title);
		out = out.replace('%%URL%%',url);
		return out;
	},	
	
	/**
	 * Add a new bookmark object to default list
	 *
	 * @access	public
	 * @param	string	bookmark identifier
	 * @param	string	bookmark url
	 * @param	string	bookmark title
	 * @param	string	bookmark css file (if blank uses which)
	 * @return	
	 */	
	addBookmark: function(which,url,title,css)
	{
		if(!this.initted) this.init();
		var info = new Object();
		info.which	= (which)  ? which : '';
		info.title	= (title) ? title : '';
		info.url	= (url)   ? url : null;
		info.css	= (css)   ? css : info.which;		
		this.bookmarks[which] =  info;
	}
};