(function($) {
	$.fn.stSocialShare = function(options) {

		var opts = $.extend({}, $.fn.stSocialShare.defaults, options);

		return this.each(function() {
			/**
		   * Initialise
		   */
			var $self = $(this);
			var $links = $self.find('a'); // array of social links

	        $self.shareIconAry=[];
	
	        var init = function() {
	            $links.each(function(i) {
	                $self.shareIconAry[i] = new ShareIcon(i, $(this), $(this).width() + opts.rightPadding);
	
	                $(this).hover(function() { //mouse in
	                    return function(e) {
	                        $self.shareIconAry[i].$obj.stop();
	                        openItem($self.shareIconAry[i]);
	                    } ();
	
	                }, function() { //mouse out
	                    return function(e) {
	                        $self.shareIconAry[i].$obj.stop();
	                        closeItem($self.shareIconAry[i]);
	                    } ();
	                });
	
	                closeItem($self.shareIconAry[i]);
	            });
	        };
	
	        var openItem = function(obj) {
	            obj.$obj.animate({ width: obj.startWidth }, opts.openSpeed);
	        };
	
	        var closeItem = function(obj) {
	            obj.$obj.animate({ width: '0' }, opts.closeSpeed);
	        };
	
	        var ShareIcon = function(id, $obj, startWidth) {
	            this.id = id;
	            this.$obj = $obj;
	            this.startWidth = startWidth;
	        };
			
			init();
	      
		});
	};

	$.fn.stSocialShare.defaults = {
        openSpeed: 100,
        closeSpeed:600,
        rightPadding:20
	};
})(jQuery);

