(function($) {
	$.fn.bg = function(options)	{
		// on resize re-calculate
		//$(window).resize(function(){$(this).bg(options)});
		
		var defaults = {
			depth: 15,
			cursor_depth: 100
		};

		var opts = $.extend(defaults, options);

		var layers = [];
		var num_layers = $('div', this).length;

		var cx = $(window).width() / 2;
		var cy = $(window).height() / 2;

		if (num_layers > 0)
		{
			var layers_depth = opts.depth / num_layers;

			$('div', this).each(function(){
				var i = layers.length;
				var layer_depth = layers_depth + layers_depth * i; // skip 0
				layers[i] = {
					depth: layer_depth,
					ratio: layer_depth / opts.cursor_depth,
					layer: $(this)
				};
			});

			$('body').mousemove(function(e){
				// center point - cursor point
				var dx = e.pageX - cx;
				var dy = e.pageY - cy;

				for (i in layers)
				{
					var layer = layers[i];
					
					var lx = dx * layer.ratio;
					var ly = dy * layer.ratio;

					layer.layer.css('left', (Math.round(lx * 30) / 100) + 'px');
					layer.layer.css('top', ((Math.round(ly * 30) / 100)+90) + 'px');
				}
			});
		}

		return this;
	}
})(jQuery);

