(function($){
	jQuery.fn.blossom = function(options){
		
		var defaults = {
			speed:  200,
			ratio:  0.95,
			opacity: 0.8
		};
		var opts = $.extend(defaults,options);
		
		return this.each(function(){
			/**
			 * 'this' er det valgte elementet. 'target' settes standard til elementet,
			 * men kan overstyres til ett/flere vilkårlig valgt element(er) (avhenger av selector).
			 */			 
			var $shooter = $(this);
			var def = {
				target: $shooter
			};
			var oo = $.extend({},def,opts);
			
			oo.target.each(function(){
				/**
				 * 'this' er nå det enkelte 'target'
				 */
				var $target = $(this);
				
				if($target.attr("rel")!="set"){
					$target.attr("rel","set");
					var d = {};
					var ooo = $.extend({},d,oo);
					var expandedWidth = $target.width();
					var expandedHeight = $target.height();
					var shrunkWidth = Math.round(expandedWidth*ooo.ratio);
					var shrunkHeight = Math.round(expandedHeight*ooo.ratio);
					
					$target.attr("expWidth",expandedWidth);
					$target.attr("expHeight",expandedHeight);
					$target.attr("shrWidth",shrunkWidth);
					$target.attr("shrHeight",shrunkHeight);
					
					/*setter en div rundt hvert target, med dimensjon lik targets opprinnelige størrelse*/
					$target
						.width(shrunkWidth)
						.height(shrunkHeight)
						.css({
							opacity: ooo.opacity,
							position: "absolute",
							top: Math.round(expandedHeight/2-shrunkHeight/2) + "px",
							left: Math.round(expandedWidth/2-shrunkWidth/2) + "px",
						})
						.wrap('<span></span>')
						.parent()
							.width(expandedWidth)
							.height(expandedHeight)
							.css({
								display: "block",
								position: "relative"
							});
				}
								
			});
			
			$shooter.hover(function(){
				oo.target.each(function(){
					/*expand*/
					var $this = $(this);
					var wBig = $this.attr("expWidth");
					var hBig = $this.attr("expHeight");
					$this.animate({
						width: wBig + "px",
						height: hBig + "px",
						top: 0,
						left: 0,
						opacity: 1
					},{
						queue: false,
						duration: oo.speed
					});
				});
			},function(){
				oo.target.each(function(){
					var $this = $(this);
					var wBig = $this.attr("expWidth");
					var hBig = $this.attr("expHeight");
					var wSmall = $this.attr("shrWidth");
					var hSmall = $this.attr("shrHeight");
					$this.animate({
						width: wSmall + "px",
						height: hSmall + "px",
						top: Math.round(hBig/2 - hSmall/2) + "px",
						left: Math.round(wBig/2 - wSmall/2) + "px",
						opacity: oo.opacity
					},{
						queue: false,
						duration: oo.speed
					});
				});
			});
			
			
		});
		
	};
})(jQuery);
