﻿/* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
* MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
*
* Version: 0.1
*
* Requires:
*   jQuery 1.2+
*/
//(function($) {
//	$.fn.boxShadow = function(xOffset, yOffset, blurRadius, shadowColor) {
//		if (!$.browser.msie) return;
//		return this.each(function(){
//			$(this).css({
//				position:	"relative",
//				zoom: 		1,
//				zIndex:		"2"
//			});
//			$(this).parent().css({
//					position:	"relative"
//			});
//			
//			var div=document.createElement("div");
//			$(this).parent().append(div);

//			var _top, _left, _width, _height;
//			if (blurRadius != 0) {
//				$(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius="+(blurRadius)+", enabled='true')");
//				_top = 		yOffset-blurRadius-1;
//				_left =		xOffset-blurRadius-1;
//				_width =		$(this).outerWidth()+1;
//				_height =	$(this).outerHeight()+1;
//			} else {
//				_top = 		yOffset;
//				_left =		xOffset;
//				_width = 	$(this).outerWidth();
//				_height = 	$(this).outerHeight();
//			}
//			$(div).css({
//				top: 			_top,
//				left:			_left,
//				width:		_width,
//				height:		_height,
//				background:	shadowColor,
//				position:	"absolute",
//				zIndex:		1
//			});
//			
//	  });
//	};
//})(jQuery);

(function ($) {
	// bron: http://placenamehere.com/article/384/css3boxshadowininternetexplorerblurshadow/
	$.fn.boxShadow = function (blurRadius, shadowColor) {

		// alleen bij IE uitvoeren
		if (!$.browser.msie) return;

		// geen schaduw bij IE 6 en lager
		if ($.browser.version < 7) return;

		return this.each(function () {

			var elm = $(this),
				id = elm.attr("id"),
				pos = $(elm).position(),
				topcorrection = 6,
				leftcorrection = 6;

			// controleren of div waar een schaduw omheen moet een id heeft, zo niet, dan gaan we gillen :)
			if (id.length == 0) {
				alert(elm.attr("class") + ' has no ID!!!');
			}

			// kijken of schaduw div al bestaat, zo niet aanmaken
			if ($("#shadow_" + id).length == 0) {
				elm.after("<div class='ie-shadow' id='shadow_" + id + "'></div>");
			}

			$('#shadow_' + id).css({
				width: $(elm).outerWidth() + blurRadius,
				height: $(elm).outerHeight() + blurRadius,
				left: pos.left - leftcorrection,
				top: pos.top - topcorrection,
				position: "absolute",
				zIndex: 0,
				background: shadowColor,
				display: "block",
				filter: "progid:DXImageTransform.Microsoft.Blur(PixelRadius='" + blurRadius + "', MakeShadow='true', ShadowOpacity='0.2')"
			}).css("opacity", "0.4");
		});
	};
})(jQuery);
