(function($){
	$.fn.jshare = function(custom) {
var defaults = {
				
				jsharedir			:	'jshare/',	// Set the directory for the jshare files like style.css & script.js
				
				highlight			:	true,		// Highlight share icon on hover?
			
				buttons				:	"",	// Default buttons to display
				iconsdir			:	'jshare/images/icons/',	//  Default is jsharedir + images/icons/
				imageextension		:	"png",		// Icon image format (jpg, png, gif, etc...)
		
				blanktarget			:	false,		// Open links on new tab/window?
				stickybutton		:	true,		// Add the sticky button on the side?
				emailform			:	false,		// Disply email form?
			
				shareurl			:	'',			// URL to share (Default is your current page's URL)
				sharetitle			:	'',			// Page title to share (Default is your current page's title)
			
				overlay				:	true,		// cover up the background?
				overlayopacity		:	0.5,
				overlaycolor		:	'#000',
		
				speedin				:	1,		// Set durations of fadein in milliseconds
				speedout			:	1			// Set durations of fadeout in milliseconds

		  };
		  
var settings	= $.extend({}, defaults, custom);

// Add the stylesheet to the head if using jshare
$("head").append("<link />");
$("head").children(":last").attr({
								"rel": "stylesheet",
								"type": "text/css",
								"href": settings.jsharedir + 'style.css'
});



var jshare_box = [ // jshare box HTML
				  '<div id="jshare_box">',
				  '<div id="jshare_close">',
				  '</div>',
				  '<div id="jshare_content"><div id="share_content">',
				  '<div class="jshare_title"><strong>Hu-Friedy SWERV<sup>3</sup></strong> Release Date Announcement </div>',
				  '<div id="jshare_main">',
				  '</div><div id="jshare_email">',
				  '</div></div></div></div>'
				  ];


overlay	= $('<div id="jshare-overlay" />').click(function() {  // jshare close function
														  $('#jshare_box').fadeOut(settings.speedout);
														  overlay.fadeOut(settings.speedout);
														  $('#jshare_email').fadeOut(settings.speedout, function(){
														  $('#jshare_main').fadeIn(settings.speedin);
																												 });
														  });

if(settings.overlay) { // if overlay true, add opacity and colour or set opacity to 0
				overlay.css({'background-color' : settings.overlaycolour, 'opacity' : settings.overlayopacity});
} else {
				overlay.css({'opacity' : '0.0'});
}

		// sticky button settings
var jbutton = $('<a href="#" id="jshare_button" title="Coming Soon"><img src="' + settings.jsharedir + 'images/jbutton.png" border="0" /></a>');
jbutton.click(function() { // When jbutton is clicked
						$('#jshare_box').fadeIn(settings.speedin);
						overlay.fadeIn(settings.speedin);
						});


$('body').append(  // If using sticky button, add these HTMl to body
				jshare_box.join(''), // Join jshare box HTML and display
				$(settings.stickybutton ? jbutton : ' ').fadeIn('slow'), // Fade in sticky button if true
				overlay // Add overlay
);




close_button = $('<a href="javascript:void(0);"><img border="0" src="' + settings.jsharedir + 'images/jshare_close.png" alt="close" /></a>').click(function() {
														  $('#jshare_box').fadeOut(settings.speedout);
														  overlay.fadeOut(settings.speedout);
														  $('#jshare_email').fadeOut(settings.speedout, function(){
														  $('#jshare_main').fadeIn(settings.speedin);
																												 });
														  }).appendTo('#jshare_close');


$('.jshare').click(function() { // When jshare class is clicked
							$('#jshare_box').fadeIn(settings.speedin);
							overlay.fadeIn(settings.speedin);
							});

var target = settings.blanktarget ? 'target="_blank"' : ''; // If target _blank

		// Get meta keywords
		var jshare_keywords;
		function jshare_metakeywords() { 
			if(jshare_description === undefined){
				metaCollection = document.getElementsByTagName('meta'); 
				for (i=0;i<metaCollection.length;i++) { 
					nameAttribute = metaCollection[i].name.search(/keywords/);
					if (nameAttribute!= -1) { 
						jshare_keywords = metaCollection[i].content;
						return jshare_keywords; 
					} 
				} 
			}else{
				return jshare_keywords;
			}
		} 
		
		// Get meta description
		var jshare_description;
		function jshare_metadescription() { 
			if(jshare_description === undefined){
				metaCollection = document.getElementsByTagName('meta'); 
				for (i=0;i<metaCollection.length;i++) { 
					nameAttribute = metaCollection[i].name.search(/description/);
					if (nameAttribute!= -1) { 
						jshare_description = metaCollection[i].content;
						return jshare_description; 
					} 
				} 
			}else{
				return jshare_description;
			}
		} 

		// Get URL to share
		function jshare_url(){
			if(settings.shareurl) { // if share url is set
				return settings.shareurl;
			} else { 
			return document.location.href;
			}
		}
		
		function jshare_title(){
			if(settings.sharetitle) {
				return settings.sharetitle;
			} else {
				return document.title;
			}
		}
		
		// Encode url
		function encodeURL(string) {
			if(string === undefined){
				return "";
			}
			return string.replace(/\s/g, '%20').replace('+', '%2B').replace('/%20/g', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
		}
		
		
		
if(settings.highlight) { // If highlight true
	$("#jshare_main a").fadeTo("fast", 0.7).hover(
												   function(){$(this).fadeTo("fast", 1.0);},
												   function(){$(this).fadeTo("fast",0.7);}
												   );
	
}
		// returns the jQuery object to allow for chainability.
		return this;
	};
	
	
})(jQuery);

function print_page(){
	$('#jshare-overlay').fadeOut('slow');
	$('#jshare_box').fadeOut('slow', function() {
											  window.print();
											  });
}
function bookmark_us() {
	alert('Press ctrl + D to bookmark');
}
function email_this() {
	$('#jshare_main').fadeOut('fast', function() {
											   $('#jshare_email').fadeIn('slow');
											   });
}


