(function($) {
	$.fn.sliderBox = $.fn.sliderbox = function(){
		initSliderBox = function(el)
		{
			el.first = 0;
			el.last = $(el).children(".sliderbox_content").children(".sliderbox_box").size() - 1;
			$(el).children(".sliderbox_content").css("height","12.9em");
			$(el).children().children(".sliderbox_box").css("position","absolute").css("right","0px").css("top","0px");
			
			el.currentbox = 0;
			initBox(el);
		}
		
		goNav = function(el, direction)
		{
			if (direction == 'left'){
				if (el.currentbox > el.first){
					showBox(el, el.currentbox - 1, direction);
				}else{
					showBox(el, el.last, direction);
				}
			} else {
				if (el.currentbox < el.last){
					showBox(el, el.currentbox + 1, direction);
				}else{
					showBox(el, el.first, direction);
				}
			}
		}
		
		pickBox = function(el, number)
		{
			if (number > el.currentbox){
				showBox(el, number, 'right');
			} else {
				showBox(el, number, 'left');
			}
		}
		
		initBox = function(el)
		{
			offscreen = $(el).width() * 1.5;
			el.boxen = $(el).children(".sliderbox_content").children(".sliderbox_box");
			el.boxen.not(":eq(0)").css('right', '-' + offscreen + 'px');
			el.selected_icon = $($(el).children(".sliderboxNav").children().children(".navcircle")[0]).attr('src');
			el.unselected_icon = $($(el).children(".sliderboxNav").children().children(".navcircle")[1]).attr('src');
			$(el).children(".sliderboxNav").children().children(".navcircle").filter(":eq(0)").attr('src',el.selected_icon);
			$(el).children(".sliderboxNav").children().children(".navcircle").not(":eq(0)").attr('src',el.unselected_icon);
		}
		
		showBox = function(el,number, direction)
		{	
			offscreen = $(el).width() * 1.5;
			if (direction == "left"){
				el.boxen.not(":eq("+(el.currentbox)+")").css('right', '+' + offscreen + 'px');
				push_off = '-=' + offscreen + 'px';
				
			} else {
				el.boxen.not(":eq("+(el.currentbox)+")").css('right', '-' + offscreen + 'px');
				push_off = '+=' + offscreen + 'px';
				
			}
			
			el.boxen.filter(":eq("+(number)+")").animate({ "right":"0px" },{"duration": 1000});
			el.boxen.filter(":eq("+(el.currentbox)+")").animate({"right":push_off},{"duration": 1000});
			
			el.currentbox = parseInt(number);
			
			$(el).children(".sliderboxNav").children().children(".navcircle").filter(":eq("+(number)+")").attr('src',el.selected_icon);
			$(el).children(".sliderboxNav").children().children(".navcircle").not(":eq("+(number)+")").attr('src',el.unselected_icon);
		}
		this.each(
			function()
			{
				if(this.nodeName.toLowerCase()!= "div") return;
				initSliderBox(this);
			}
		)
		return this;
		
	}
})(jQuery);
