(function($){
	
		var that, items;

		function slideFirst() {
			slideItem($(that).children("a").first());			
		}
		
		function slideItem(el) {
			
			var width, marginLeft, total;
			
			marginLeft = el.css("marginLeft").replace("px", "");
			marginLeft = (marginLeft === "auto") ? 0 : parseFloat(marginLeft);
			width = parseFloat(el.outerWidth(true)) - marginLeft;
			total = width + marginLeft;
			
			if (width > 0) {
				
				var toLeft, totalTime;
				
				toLeft = width * -1;
				totalTime = total * 20;
					
				el.animate({ marginLeft: toLeft }, totalTime, "linear", function() {
					$(this).detach();
					this.style.cssText = "";
					that.append($(this));
					if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
						var filter = this.style.filter;
						this.style.filter = "";
						this.style.filter = filter;
					}
					slideFirst();
				});
			} else {
				slideFirst();
			}
		}
		
		function IEFix() {
			that.find("img").each(function() {
		       
				var origSrc = this.src;
					
				this.src = "";
					
				this.onload = function() {
						
					var src, width, height;
								
					src = this.src;
					width = this.width;
					height = this.height;
					this.onload = null;
						
					this.src = "/wp-content/themes/toolbox/img/trans.gif";
					this.style.width = width;
					this.style.height = height;
					this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + src + "')";
					//$(this).fadeTo(0, .3);	
				}
				
				this.src = origSrc;
			});
		}
	
	$.fn.slider = function() {
	
		return this.each(function() {        
				
			that = $(this);
			that.shuffle();
			
			that.find("img").hoverIntent(function() {
				var animated = $(that).children("a").first();
				animated.stop(true);
				if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version, 10) > 8)) {
					$(this).fadeTo(500, 1);					
				}
			}, function() {
				if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version, 10) > 8)) {
					$(this).fadeTo(500, .3);
				}
				slideFirst();
			});
			    
			slideFirst();
		
			if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
				IEFix();
			}
			
			if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version, 10) > 8)) {
				that.find("img").fadeTo(0, .3);
			}
		});
	}
	
})(jQuery);
