(function($){
	
	// HC Rotating Banner JQuery Plugin - MD0911
		
	$.fn.hbanner = function(options) {
		
		// Prevent Instance Collisions
		if (this.length > 1){
			this.each(function() { $(this).hbanner(options) });
			return this;
		}
		
		// Plugin Defaults
		var settings = {
			'slide_time'	:  	5000,
			'slide_speed'	:	1000,
			'navigation'	:	true,
			'navAlwaysOn'	:	false,
			'pauseOnHover'	:	true,
			'animation'     :	true
		};

		return this.each(function() {        
			
			// Overwrite Defaults
			if (options) { $.extend(settings, options); }
			
			// Local Reference to Instantiation			
			var master = $(this);
			
			// Set first paging child to active
			$(master).children(".paging").children("a:first").addClass("active");
			// Make Banner Sliders Visible
			$(master).show();
			// Resize Image Reel
			var imageWidth = $(master).children(".window").width();
			var imageSum = $(master).children('.window').children('.image_reel').children('a').size();
			var imageReelWidth = imageWidth * imageSum;
			var play = null;
			$(master).children(".window").children(".image_reel").css({'width' : imageReelWidth});
			
			// Slide Rotation Function
			var rotate = function(parent){
				var triggerID = $active.attr("rel") - 1;
				var image_reelPosition = triggerID * imageWidth;
				$(parent).children(".paging").children("a").removeClass('active');
				$active.addClass('active');
				if(!settings['animation']){
					$(parent).children(".window").children(".image_reel").css({
						left: -image_reelPosition
					});
				} else {
					$(parent).children(".window").children(".image_reel").animate({ 
						left: -image_reelPosition
					}, {speed: settings['slide_speed'], easing: 'linear'});
				}
			}; 

			// Slide Selection Function
			var rotateSwitch = function(parent){	
				play = setInterval(function(){ 
					// Set Active Slide
					$active = $(parent).children('.paging').children('a.active').next();
					if ($active.length === 0) {
						$active = $(parent).children('.paging').children('a:first');
					}
					rotate(parent);
				}, settings['slide_time']);
			};
			
			// Enable/Disable Pause on Hover
			if (settings['pauseOnHover']) {
				$(master).children(".window").children(".image_reel").children("a").hover(function() {
					clearInterval(play);
				}, function() {
					rotateSwitch(master);
				});	
			}
			
			// Enable/Disable Navigation
			if (settings['navigation']) {
				if (!settings['navAlwaysOn']) {
					$(master).mouseenter(function() {
						$(master).children(".paging").fadeIn("fast");
					});
					$(master).mouseleave(function() {
						$(master).children(".paging").fadeOut("fast");	
					});
				} else {
					$(master).children(".paging").show();	
				}
			}
			
			// Register Click Event for Paging Anchors
			$(master).children(".paging").children("a").bind('click', function(e){
				$active = $(e.currentTarget);
				clearInterval(play);
				rotate(master);
				rotateSwitch(master);
				return false;
			});
			
			// Init Rotation
			rotateSwitch(master);
			
		});
	
	};

})(jQuery);
