(function($){
	$.fn.jfan = function(custom) {
var defaults = {
		  	highlight: true,
			buttons: "digg,stumbleupon,delicious,facebook,yahoo",
			imagedir: "images/",
			imageextension: "gif",
			blanktarget: true
		  };
var settings 		= $.extend({}, defaults, custom);
var jsocial 		= this;

		// Set target attribute
var target = settings.blanktarget ? 'target="_blank"' : '';
		
		// Write social icons to browser
var buttons = settings.buttons.split(",");
		for ( key in buttons ) {
			var name = buttons[key];
			var url = jafan[buttons[key]];
			if(url != undefined){
				url = url.replace("{TITLE}"			, urlencode(jsocial_title()));
				url = url.replace("{URL}"			, urlencode(jsocial_url()));
				url = url.replace("{KEYWORDS}"		, urlencode(jsocial_metakeywords()));
				url = url.replace("{DESCRIPTION}"	, urlencode(jsocial_metadescription()));
		var sociallink = '<a ' + target + ' href="' + url + '" class="jfan_button"><img border="0" src="' + settings.imagedir + name + '.' + settings.imageextension + '" alt="' + name + '" /></a>';
				
				this.append(sociallink);
			}
			
		}
		
		// If highlight bind mousehover and mouseout
		if(settings.highlight){
			// Trigger focus animation
			this.find(".jfan_button").bind("mouseover", function(){
				$(this).siblings().stop().animate({"opacity": 0.2}, 500);
			});
			
			this.find(".jfan_button").bind("mouseout", function(){
				$(this).siblings().stop().animate({"opacity": 1}, 500);
			});
		}
		
		// Meta keywords
var jsocial_keywords;
		function jsocial_metakeywords() { 
			if(jsocial_description == undefined){
				metaCollection = document.getElementsByTagName('meta'); 
				for (i=0;i<metaCollection.length;i++) { 
					nameAttribute = metaCollection[i].name.search(/keywords/);
					if (nameAttribute!= -1) { 
						jsocial_keywords = metaCollection[i].content;
						return jsocial_keywords; 
					} 
				} 
			}else{
				return jsocial_keywords;
			}
		} 
		
		// Meta description
		var jsocial_description;
		function jsocial_metadescription() { 
			if(jsocial_description == undefined){
				metaCollection = document.getElementsByTagName('meta'); 
				for (i=0;i<metaCollection.length;i++) { 
					nameAttribute = metaCollection[i].name.search(/description/);
					if (nameAttribute!= -1) { 
						jsocial_description = metaCollection[i].content;
						return jsocial_description; 
					} 
				} 
			}else{
				return jsocial_description;
			}
		} 
		
		// Title
		function jsocial_title(){
			return document.title;
		}
		
		// Url
		function jsocial_url(){
			return document.location;
		}
		
		// Encode url
		function urlencode(string) {
			return escape(string).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
		}
		
		function highlight(element, state){
			
			if(state){
				element.style.opacity = 1;
				element.childNodes[0].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100);";
			}else{
				element.style.opacity = highlight_opacity/100;
				element.style.filter = "alpha(opacity=20)";
				element.childNodes[0].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + highlight_opacity + ");";
			}
		}

		
		// returns the jQuery object to allow for chainability.
		return this;
	}
	
})(jQuery);

// Format list
var jafan			= Array();
jafan['nujij']	 	= "http://nujij.nl"
jafan['ekudos'] 	= "http://www.ekudos.nl";
jafan['digg'] 		= "http://digg.com";
jafan['linkedin'] 	= "http://www.linkedin.com/companies/792971";
jafan['sphere'] 	= "http://www.sphere.com";
jafan['technorati'] = "http://www.technorati.com";
jafan['delicious'] 	= "http://del.icio.us";
jafan['furl'] 		= "http://furl.net";
jafan['netscape'] 	= "http://www.netscape.com";
jafan['yahoo'] 		= "http://myweb2.search.yahoo.com";
jafan['google'] 	= "http://www.google.com";
jafan['newsvine'] 	= "http://www.newsvine.com";
jafan['reddit'] 	= "http://reddit.com";
jafan['blogmarks'] 	= "http://blogmarks.net";
jafan['magnolia'] 	= "http://ma.gnolia.com";
jafan['live']		= "https://favorites.live.com";
jafan['tailrank'] 	= "http://tailrank.com";
jafan['facebook'] 	= "http://www.facebook.com/#!/pages/Narhex-Australia/121362187884376?ref=sgm";
jafan['twitter'] 	= "http://twitter.com/Narhex";
jafan['blogger'] 	= "http://blogger.com";
jafan['rss'] 		= "#";
jafan['stumbleupon']= "http://www.stumbleupon.com";
jafan['bligg'] 		= "http://www.bligg.nl";
jafan['symbaloo'] 	= "http://www.symbaloo.com";
