function carouselWrapper (args) {
//Define some variables
args.visibleSlides = args.visibleSlides?args.visibleSlides:1;
args.circular = args.circular!=undefined?args.circular:true;
args.orientation = args.orientation?args.orientation:'horizontal';
if (args.effect=='fade'||args.visibleSlides > 1) args.circular = false;

var car_inc = car_inc!=undefined?car_inc:0;
if (car_timeout == undefined) var car_timeout = [];
car_timeout[car_inc] = '';
var car_w = args.carouselWrap;
var car_c = args.carouselContent;
var car_s = car_c+' > div';
var car_ctrl = args.carouselControl?args.carouselControl:false;
var car_j = args.carouselControl?args.carouselControl+' .jumpers':false;
var car_h = args.hideControls!=undefined?args.hideControls:true;
var dynamic = args.dynamic!=undefined?args.dynamic:false;


//setup window load function so images are loaded before we start
Event.observe(window,"load",function () {
	//if this is a circular slide show and the visibleSlide number is 1 then duplicate the first slide at the end of the slide wrapper
	if (args.circular&&args.visibleSlides==1) {
		var scrap = $$(car_s)[0];
		$$(car_c)[0].insert("<"+scrap.tagName+">"+scrap.innerHTML+"</"+scrap.tagName+">");//elements weren't working as expected here so string was an alternative
	}

	slideCount = $$(car_s).length;
        //Add class "last" to the last slide
        $$(car_s)[slideCount-1].addClassName('last');
	//Set dynamic width to slide container so we don't have to do the math when we add a slide
	viewportWidth = 0, totalWidth = 0, slideTemp = $$(car_s);
        function completeWidth(ob) {return Number(ob.getStyle('margin-left').replace(/[a-z]/ig,''))+Number(ob.getStyle('margin-right').replace(/[a-z]/ig,''))+ob.getWidth();};
	if (args.orientation=='horizontal') {
		if (!dynamic) {
            for (x=0;x<slideCount;x++) {
                slideTemp[x].setStyle({'float':'left'});
                totalWidth += completeWidth(slideTemp[x]);
                if (x+1 <= args.visibleSlides) viewportWidth += completeWidth(slideTemp[x]);
            }
            $$(car_c)[0].setStyle({width:totalWidth+'px'});
            
            //uncomment below line if you want slides wrapper to be auto sized based on visible slide count and first (all) slide widths
            if (slideCount >= args.visibleSlides) $$(car_w)[0].setStyle({width:viewportWidth+'px'});
		} else {
			totalWidth = slideCount * 100;
			slideWidth = 100;
			$$(car_c)[0].setStyle({width:totalWidth+'%'});
			$$(car_w)[0].setStyle({width:slideWidth+'%'});
		}
        }


        //if a selector has been provided for the controls and the slideCount is less than or equal to visibleSlides then hide the controls completely
        if (car_ctrl&&args.visibleSlides >= slideCount-(args.circular?1:0)) {
            presentControls = $$(car_ctrl);
            if (presentControls.length) presentControls[0].hide();
        }

        //if a selector has been provided for the controls and the slideCount exceeds the visibleSlides then set us up the bomb (the controls), otherwise ignore this
	if (car_ctrl&&args.visibleSlides < slideCount-(args.circular?1:0)) {
                for (x=0;x<slideCount-(args.circular?1:0);x++) {//Setup controls
                    if ($$(car_j)[0]) $$(car_j)[0].insert('<a href="javascript:" class="carousel-jumper'+(x==0?' carousel-selected':'')+'" '+(car_h?'style="display:none"':'')+' rel="'+args.name+'_slide-'+(x+1)+'">'+(x+1)+'</a>');
                    $$(car_c+'>div:nth-child('+(x+1)+')')[0].writeAttribute("id",args.name+"_slide-"+(x+1));
                }

		//Only do show/hide of controls if hideControls is true
		if (car_h) $$(car_w,car_ctrl+' .carousel-control',car_ctrl+' .carousel-jumper').each(function (e) { //include the controls also just incase they are overlapping the wrapper.
			e.observe('mouseover',function() {//Setup mouse events to show/hide controls
					clearTimeout(car_timeout[car_inc]);
					$$(car_ctrl+' .carousel-control',car_ctrl+' .carousel-jumper').each(function (e) {e.show();});
				}).observe('mouseout',function() {
					clearTimeout(car_timeout[car_inc]);
					car_timeout[car_inc] = setTimeout("$$('"+car_ctrl+" .carousel-control','"+car_ctrl+" .carousel-jumper').each(function (e) {e.hide();})",1000);
				});
			});
	}

	//Init carousel
	new Carousel($$(car_w)[0],$$(car_s), $$(car_ctrl+' .carousel-control',car_ctrl+' .carousel-jumper'),{
		afterMove: car_ctrl?function (cObj)  { //For some reason the default behavior of this plugin doesn' add the carousel-selected style to jumpers unless they're clicked.
			$$('.carousel-jumper').each(function(e){e.removeClassName('carousel-selected')})
			var cur = $$('.carousel-jumper:[rel="'+cObj.current.id+'"]')[0];
			if (cur == undefined) var cur = $$('.carousel-jumper:[rel="'+cObj.controls[0].rel+'"]')[0];
			if (cur) cur.addClassName('carousel-selected');
		}:false,
		auto:args.auto!=undefined?args.auto:true,
		circular:args.circular,
		effect:args.effect?args.effect:"scroll",
		frequency:args.delay?args.delay:4,
		visibleSlides:args.visibleSlides?args.visibleSlides:1,
                wheel:args.wheel!=undefined?args.wheel:true,
                disabledClassName:args.disabledClassName?args.disabledClassName:'disabled',
                duration:args.duration?args.duration:1
	});
});
}

