/*
 * jQuery SpitLoop
 * Copyright 2010 Jake Lauer with Clarity Design (isthatclear.com)
 * Released under the MIT and GPL licenses.
 */
		(function($){
			$.fn.SpitLoot = function(options) {

				var defaults = {
					action:'show',
					fadeSpeed: 200,
					x: 10,
					y:10,
					anchor: 'cursor'
				};

				var options = $.extend(defaults, options);

				return this.each(function() {
					if (options.action == 'show') {
						$('.SpitLootContainer').remove();
						$('body').append('<div class="SpitLootContainer"></div>');
						var $container = $('.SpitLootContainer');
						$container.css({
							position:'absolute',
							top:0,
							left:0,
							opacity:0,
							display:'none'
						});
	
						//Display
						var $SLRefStr = $(this).attr('rel');
						var $SLRef = $('body').find($SLRefStr);
						$container.html($SLRef.clone());
						if ( (options.anchor=='cursor'||options.anchor=='this') || ($(options.anchor).size()>0) ){
							if (options.anchor == 'cursor') {
								$('html').mousemove(function(e){
									$container.css({
										top: e.pageY + options.y,
										left: e.pageX + options.x
									});
								});
							} else if (options.anchor == 'this'){
								$container.css({
									top: $(this).offset().top + options.y,
									left: $(this).offset().left + $(this).width() + options.x
								});
							} else {
								if ($(options.anchor).size() > 0) {
									$container.css({
										top: $(options.anchor).offset().top + options.y,
										left: $(options.anchor).offset().left + $(options.anchor).width() + options.x
									});
								} else {
									alert('SpitLoot anchor does not exist or is empty');
								}
							}
							$container
								.show()
								.stop()
								.animate({opacity:1}, options.fadeSpeed);
						}
					} else {
						var $container = $('.SpitLootContainer');
						$container
							.stop()
							.animate({opacity:0}, options.fadeSpeed, 
								function(){
									$(this).remove();
								}
							);
					}
					
					
				});
				

			};

		})(jQuery);
