(function($){
	$.fn.sapeblock = function(options){
		var options = $.extend({
			separator: '<br>',
			key: '',
			image: false,
			classes: {
				item: 'sape-item',
				host: 'sape-host',
				title: 'sape-title',
				image: 'sape-image',
				hover: 'sape-hover'
			}
		}, options);	
		
		getScreen = function(u,k){
			if(u.indexOf('\/\/') == -1) u = 'http://'+u;
			return 'http://images.websnapr.com/?size=s&amp;key=' + encodeURIComponent(k) + '&amp;hash=' + encodeURIComponent(websnapr_hash) + '&amp;url=' + encodeURIComponent(u);
		};
				
		return this.each(function(){
			var s = $(this).html();
			if(s.indexOf('\<\!--') == -1 && s){
				if(s.indexOf(options.separator) == -1) options.separator = options.separator.toUpperCase();
				var a = s.split(options.separator);
				$(this).html('');
				for(var i = 0; i < a.length; i++){
					$(this).append('<div class="' + options.classes.item + '">' + a[i] + '<\/div>');
				}
				$(this).find('.' + options.classes.item).each(function(){
					var l = $(this).find('a').attr('href');
					var h = l.substr(l.indexOf('\/\/') + 2);								
					if(h.indexOf('\/') != -1) h = h.substr(0,h.indexOf('\/'));
					h = h.toLowerCase();
					if(options.image){
						$(this).prepend('<div class="' + options.classes.image + '"><a href="' + l + '"><img src="' + getScreen(h, options.key) + '" border="0" alt="' + h + '"><\/a><\/div>');
						$('.' + options.classes.image).find('img').hover(function(){
							$(this).addClass(options.classes.hover);
						},function(){
							$(this).removeClass(options.classes.hover);
						}); 
					}else{
						var t = $(this).find('a').html();
						t = t.substr(0,1).toUpperCase() + t.substr(1);
						$(this).prepend('<div class="' + options.classes.title + '"><a href="' + l + '">'+t+'<\/a><\/div>');
					}
					
					$(this).append('<div class="' + options.classes.host + '">' + h + '<\/div>');
				});
			}
		});
	};
})(jQuery);
