/**
 * @author Greg
 */
(function($){

    $.fn.extend({ 
        
  
        VisibleShare: function(options){
        	
        	var defaults = { 
        		buttons : 'facebook,twitter,email,rss',
        		
        			
        	};
            
            var options =  $.extend(defaults, options);
            
        	return this.each(function() {
        		
				var buttons = options.buttons.split(',');
				for(var i=0;i<buttons.length;i++){
					method = buttons[i];
					
					URL = window.location.href;
					TITLE = document.title;
					DESCRIPTION = $('head meta[name=description]').attr('content');
					
					href = vsFormat[method];
					href = href.replace("{TITLE}"		, encodeURIComponent(TITLE));
					href = href.replace("{URL}"			, encodeURIComponent(URL));
					href = href.replace("{DESCRIPTION}"	, encodeURIComponent(DESCRIPTION));
					
					$('<a></a>').attr('href',href).html(method).addClass(method).appendTo(this);
				}
        		
        		$('a',this).click(function(e){
        			var link = this; 
        			e.preventDefault();
        			if($(this).hasClass('twitter') || $(this).hasClass('facebook')){
        				window.open( $(link).attr('href'), "Partager", "status = 0, height = 400, width = 500, resizable = 0" );
        			}else{
        				$.colorbox({
							href:	$(link).attr('href'),
							title:  "Partager",
					        height: 500,
					        width:  600,
					        iframe:true
						}); 
        			}
        			
        		});
        		
            });
        	
        }

    });
    
})(jQuery);



var vsFormat			= Array();
vsFormat['digg'] 		= "http://digg.com/submit?phase=2&url={URL}&title={TITLE}";
vsFormat['linkedin'] 	= "http://www.linkedin.com/shareArticle?mini=true&url={URL}&title={TITLE}&summary={DESCRIPTION}&source=";
vsFormat['sphere'] 		= "http://www.sphere.com/search?q=sphereit:{URL}";
vsFormat['technorati'] 	= "http://www.technorati.com/faves?add={URL}";
vsFormat['delicious'] 	= "http://del.icio.us/post?url={URL}&title={TITLE}";
vsFormat['yahoo'] 		= "http://myweb2.search.yahoo.com/myresults/bookmarklet?u={URL}&t={TITLE}";
vsFormat['google'] 		= "http://www.google.com/bookmarks/mark?op=edit&bkmk={URL}&title={TITLE}";
vsFormat['magnolia'] 	= "http://ma.gnolia.com/bookmarklet/add?url={URL}&title={TITLE}";
vsFormat['live']		= "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url={URL}&title={TITLE}&top=1";
vsFormat['facebook'] 	= "http://www.facebook.com/share.php?u={URL}";
vsFormat['twitter'] 	= "http://twitter.com/?status={TITLE}%20-%20{SHORTURL}";
vsFormat['stumbleupon'] = "http://www.stumbleupon.com/submit?url={URL}&title={TITLE}";
vsFormat['myspace']		= "http://www.myspace.com/Modules/PostTo/Pages/?u={URL}";
vsFormat['email']		= "/index/share/embedded/1/title/{TITLE}";
vsFormat['rss']			= "/rss";

/*
 $('div.share').delegate('a','click',function(e){
		e.preventDefault();
		if($(this).hasClass('email')){
			var url = $(this).attr('href');
			url = url + '/embedded/1';
			////console.debug(url);
			$.colorbox({
				href:	url,
				title:  "Partager/share",
		        height: 500,
		        width:  600,
		        iframe:true
			}); 
		}
		
		if($(this).hasClass('twitter')){
			var url = $(this).attr('href')+'?';
			var params = [];
			if($(this).attr('data-url')){
				params.push('url='+encodeURIComponent($(this).attr('data-url')));
			}else{
				params.push('url='+encodeURIComponent(window.location.href));
			}
			if($(this).attr('data-text')){
				params.push('text='+encodeURIComponent($(this).attr('data-text')));
			}
			if($(this).attr('data-via')){
				params.push('via='+encodeURIComponent($(this).attr('data-via')));
			}
			if($(this).attr('data-related')){
				params.push('related='+encodeURIComponent($(this).attr('data-related')));
			}
			if($(this).attr('data-count')){
				params.push('count='+encodeURIComponent($(this).attr('data-count')));
			}
			if($(this).attr('data-lang')){
				params.push('lang='+encodeURIComponent($(this).attr('data-lang')));
			}
			
			var url = url + params.join('&');
			window.open( url, "Twitter", "status = 0, height = 400, width = 500, resizable = 0" );

		}

		if($(this).hasClass('facebook')){
			var url = $(this).attr('href');
			window.open( url, "Twitter", "status = 0, height = 400, width = 500, resizable = 0" );
		}
	});
}); 
 */

