var DynamicDropShadows = new Class({
	Extends : general,
	Implements : [Options , Events],
	options: {
		shadowStyleClass	: 'dropShadowBackground', 
		xOffset				: '',
		yOffset				: '', 
		shadowOpacity		: '',
		softShadow			: '', 
		cycleFallOff		: '', 
		allSideShadow		: '',
		shadowDistance		: '', 
		allSideClass		: 'allSideShadowBackground'
	},

	
	initialize: function(elements, options) {
		//set default values if no parameters given
		this.setOptions(options);
		xOffset = $pick(this.options.xOffset, 10);
		yOffset = $pick(this.options.yOffset, 10);
		shadowOpacity = $pick(this.options.shadowOpacity, .8);
		softShadow = $pick(this.options.softShadow, true);
		cycleFallOff = $pick(this.options.cycleFallOff, .1);
		allSideShadow = $pick(this.options.allSideShadow, false);
		shadowDistance = $pick(this.options.shadowDistance, 3);
		
		//get the elements
		$$(elements).each(function(current) {
			var container = current.clone().empty().injectBefore(current).adopt(current).setStyles({
				'position': 'relative'
				});
		
			current.setStyles({
				position: 'absolute',
				height: current.getSize().y+'px',
				top: 0,
				left: 0,
				margin: 0,
				padding: 0
			});
		
			//first shadow needs to be a solid rectangle
			var shadow = current.clone().empty().injectBefore(current).addClass(this.options.shadowStyleClass).setOpacity(shadowOpacity);
			if(this.options.allSideShadow) {
				shadow.setStyles({
					top: (current.getStyle('top').toInt() + yOffset - shadowDistance) + 'px',
					left: (current.getStyle('left').toInt() + xOffset - shadowDistance) + 'px',
					width: (shadow.getStyle('width').toInt() + shadowDistance * 2 + xOffset) + 'px',
					height: (shadow.getStyle('height').toInt() + shadowDistance * 2 + yOffset) + 'px'
				})
			} else {
				shadow.setStyles({
					top: (current.getStyle('top').toInt() + yOffset) + 'px',
					left: (current.getStyle('left').toInt() + xOffset) + 'px'
				})
			}
			
			//additional shadow layers only need to be 1px in size to not overlap the big shadow
			var counter = 0;
			var tempOpacity = shadowOpacity;
	
			while(this.options.softShadow && (tempOpacity - this.options.cycleFallOff).round(2) > 0) {
				tempOpacity = (tempOpacity - this.options.cycleFallOff).round(2);

				if(this.options.allSideShadow) {
					//shadow on every side
					var shadowFrame = shadow.clone().removeClass(this.options.shadowStyleClass).addClass(this.options.allSideClass).setOpacity(tempOpacity).injectBefore(current).setStyles({
						height: (shadow.getStyle('height').toInt() + counter * 2) + 'px',
						width: (shadow.getStyle('width').toInt() + counter * 2) + 'px',
						top: (shadow.getStyle('top').toInt() - counter - 1) + 'px',
						left: (shadow.getStyle('left').toInt() - counter - 1) + 'px',
						'background-color': 'transparent'
					});
				} else {
					//shadow only right and bottom
					//vertical shadow
				
					var vShadow = shadow.clone().setOpacity(tempOpacity).injectBefore(current).setStyles({
						top: (shadow.getStyle('top').toInt() + counter + 1) + 'px',
						left: (shadow.getStyle('left').toInt() + shadow.getStyle('width').toInt() + counter) + 'px',
						height: (shadow.getStyle('height').toInt() - 1) + 'px',
						width: '1px'
					});
					
						//console.log(vShadow);
					//horizontal shadow
					var hShadow = shadow.clone().setOpacity(tempOpacity).injectBefore(current).setStyles({
						top: (shadow.getStyle('top').toInt() + shadow.getStyle('height').toInt() + counter) + 'px',
						left: (shadow.getStyle('left').toInt() + counter + 1) + 'px',
						width: (shadow.getStyle('width').toInt() - 1) + 'px',
						height: '1px'
					});
					//corner shadow
					if((tempOpacity - cycleFallOff).round(2) > 0) {
						var cShadow = hShadow.clone().setOpacity((tempOpacity - cycleFallOff).round(2)).injectBefore(current).setStyles({
							left: (hShadow.getStyle('left').toInt() + hShadow.getStyle('width').toInt()) + 'px',
							width: '1px'
						});
					}
				}
				counter++;
			}
		}.bind(this));
	}
});