/* Copyright (c) 2010 Christian Pfeiffer (christian.pfeiffer.k@gmail.com || http://www.fancydesign.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Last Change: 2010-11-18
 * Version: 1.01
 * 
 */

 
(function($){
	

	$.fn.share = function(options) {
		var defaults = {			
			url: 			window.location,								// url of social bookmark, default is current url, use 'http://www.example.com' for individual url	
			title:			$('title').html(),								// title of social bookmark, default is window title, use 'example' for individual title	
			description: 	$('meta[name=description]').attr("content"),	// description of social bookmark, default is <meta>-description, use 'example' for individual description							
			tags:			$('meta[name=keywords]').attr("content"),		// tags of social bookmark, default is <meta>-keywords, use 'example' for individual tags
			services:		['all'], 										// 'all' for [all] services, or ['facebook', 'delicious', ..] for specific services	
			img_size:		16,												// width and height of <img>-tag (px)
			img_alt: 		'$service',										// alt-text of <img>-tag, $service will be replaced by the name of the service
			a_target:		'_blank',										// target-attribute of <a>-tag
			a_title:		'share on $service'								// title-attribute of <a>-tag, $service will be replaced by the name of the service							
   		};			
   		var options = $.extend(defaults, options);			
   		return this.each(function() {			
			var target = $(this);			
			var services = {
				facebook:	['http://www.facebook.com/sharer.php?u=' + escape(options.url) + '&t=' + options.title, 'http://www.dnamodels.com/assets/facebook.jpg', 'http://www.dnamodels.com/assets/facebook_black.jpg'],
				twitter:	['http://twitter.com/home?status=' + options.title + ':+' + options.url, 'http://www.dnamodels.com/assets/twitter.jpg', 'http://www.dnamodels.com/assets/twitter_black.jpg'],
				delicious: 	['http://del.icio.us/post?url=' + options.url + '&title=' + options.title + '&tags=' + options.tags + '&notes=' + options.description, 'http://www.delicious.com/favicon.ico'],	
				digg:		['http://digg.com/submit?phase=2&url=' + options.url + '&title=' + options.title, 'http://cdn1.diggstatic.com/img/favicon.a015f25c.ico'],			
				google:		['http://www.google.com/bookmarks/mark?op=add&bkmk=' + options.url + '&title=' + options.title + '&labels=' + options.tags + '&annotation=' + options.description, 'http://www.google.com/favicon.ico'],
				yahoo:		['http://bookmarks.yahoo.com/toolbar/savebm?u=' + options.url + '&t=' + options.title + "&d=" + options.description, 'http://l.yimg.com/i/i/eu/aut/favic1.ico'],
				misterwong:	['http://www.mister-wong.com/index.php?action=addurl&bm_url=' + options.url + '&bm_description=' + options.title + '&bm_tags=' + options.tags + '&bm_notice=' + options.description, 'http://www.mister-wong.de/favicon.ico'],
				netvibes:	['http://www.netvibes.com/share?url=' + options.url + '&title=' + options.title, 'http://cdn.netvibes.com/favicon.ico'],
				linkedin:	['http://www.linkedin.com/shareArticle?mini=true&url=' + options.url + '&title=' + options.title + '&source=&summary=' + options.description, 'http://www.linkedin.com/img/favicon_v2.ico'],				
				stumbleupon:['http://www.stumbleupon.com/submit?url=' + options.url + '&title=' + options.title, 'http://cdn.stumble-upon.com/favicon.ico']
			}		
			if(options.services == "all") { 
				options.services = new Array();
			    for(n in services) options.services.push(n);				
			}		
			$.each(options.services, function(index, service) { 				
				if(services[service] != undefined) {
					
					var content = '<a href="' + services[service][0] + '"';
					if(options.target != "") content += ' target="' + options.a_target + '"';
					if(options.title != "") content += ' name="' + (options.a_title).replace(/\$service/g, this) + '"';
					content += '><img class="rollover_share" src="' + services[service][1] + '" hover="'+services[service][2] +'"';  
					content += ' class="rollover"';						
					content += ' /></a>';										
					target.append(content);
					
					/*
					var content = '<img class="rollover" src="' + services[service][1] + '" hover="'+services[service][2] +'"';  
					content += ' class="rollover"';						
					content += ' />';
					*/										
					//target.append(content);
				}
				//setrollover(services[service][2],  options.a_title);
				
			});
			
			
			$(".rollover_share").hover(function() {
			
		        var currentImg = $(this).attr('src');
		        $(this).attr('src', $(this).attr('hover'));
		        $(this).attr('hover', currentImg);
		    }, function() {
		        var currentImg = $(this).attr('src');
		        $(this).attr('src', $(this).attr('hover'));
		        $(this).attr('hover', currentImg);
		    });
			
			
  		});
 	};  
})(jQuery);
