(function($) {
	$.fn.sliderBox = $.fn.sliderbox = function(speed, duration){
		initSliderBox = function(el, speed, duration)
		{
			el.content = $(el).children("ul");
			el.size = parseInt(el.content.children("li").size());
			el.speed = speed;
			el.duration = (duration == null) ? 10 : duration;
			$(el).css({"width":"100%", "overflow":"hidden", "position":"relative"});

			buildNav(el);

			el.content.prepend("<li></li>")
				.css({"width":"2000%", "position":"relative", "z-index":"1", "display":"block", "padding-left":"0", "left":'-100%'})
				.children("li").css({"width":"5%", "float":"left", "list-style":"none", "display":"block"});
			el.status_bar.css('width', '100px').children().css('width', '100px');

			bar_anim(el);
			$(el).hover(function(){el.status_bar.children('div').stop(true, false);},function(){bar_anim(el);});
		}
		
		buildNav = function(el)
		{
			var children = el.content.children("li");
			var output_text = '<div class=\"sliderboxNav\"><div class="sliderboxNavMain">'+
				'<a href="javascript:goNav($(\'#'+$(el).attr('id') +'\')[0] , \'left\')">&laquo;</a> ';
			$.each(children, function(index, box){
				output_text += '<a href="javascript:showBox($(\'#'+$(el).attr('id') +'\')[0] , \''+ index + '\')" class="direct_buttons">'+ (index + 1) +'</a> '
			});
			output_text += '<a href="javascript:goNav($(\'#'+$(el).attr('id') +'\')[0] , \'right\')">&raquo;</a></div><div class = "progress_box"><div class="progress_bar">&nbsp;</div></div></div> '
			$(el).append(output_text);
			$(el).children(".sliderboxNav").children('.sliderboxNavMain').children('.direct_buttons').filter(":eq(0)").addClass('active_icon');
			el.status_bar = $(el).children('.sliderboxNav').children('.progress_box');
		}
		
		bar_anim = function(el)
		{
			if (el.duration == 0){
				el.status_bar.children('div').css({'display':'none'});
				return
			}else{
				var rem_width = parseInt(el.status_bar.children('div').width());
				el.status_bar.children('div').animate({"width" : "2px"},
					{"duration": (rem_width * 10 * el.duration), "complete": function(){
						setTimeout(function(){goNav(el, 'right');}, 10);
				}});
			};
		}
		
		goNav = function(el, direction)
		{
			showBox(el, (((((el.currentbox == null) ? 0 : el.currentbox) + ((direction == 'left') ? -1 : 1) + el.size) % el.size)));
		}

		showBox = function(el,number)
		{	
			el.status_bar.children('div').stop(true, false);
			anim_string = (number == 0) ? '-100%' : ("-" + ((number * 100)+100) + "%");
			el.content.animate({"left": anim_string}, {"easing": 'swing', "duration": el.speed, 'complete': function(){
				el.status_bar.children('div').css('width', '100px');
				bar_anim(el);
			}});

			el.currentbox = parseInt(number);
			$(el).children(".sliderboxNav").children('.sliderboxNavMain').children().removeClass('active_icon').filter('.direct_buttons').filter(":eq("+(number)+")").addClass('active_icon');
		}
		this.each(
			function()
			{
				if(this.nodeName.toLowerCase()!= "div") return;
				initSliderBox(this, speed, duration);
			}
		)
		return this;
		
	}
})(jQuery);