function tx_mcscontentslideshow_init( container, direction, interval, speed ){
  var currentPosition = 0;
  var autoSlide = true;
//  var slideWidth = jQuery("#"+container).width();
  var slideWidth = 900;
  var slides = jQuery("#"+container+" .tx_mcscontentslideshow_slide");
  var numberOfSlides = slides.length;
  var tx_mcscontentslideshow_direction = direction?direction:'right';
  var tx_mcscontentslideshow_interval = interval?interval:6000;
  var tx_mcscontentslideshow_speed = speed?speed:400;

  // Remove scrollbar in JS
  jQuery("#"+container).css("overflow", "hidden");

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  .css({
    "float" : "left",
    "width" : slideWidth
  });


  // Set #slideInner width equal to total width of all slides
  jQuery("#slideInner").css("width", slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  jQuery("#"+container)
    .prepend('<span class="control" id="leftControl">Move left</span>')
    .append('<span class="control" id="rightControl">Move right</span>');
  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  jQuery(".control")
    .bind("click", function(){ autoSlide = false; tx_mcscontentslideshow_slide( (jQuery(this).attr("id")=="rightControl")?'right':'left' ); });

  // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ jQuery("#leftControl").fadeOut(); }
    else{ jQuery("#leftControl").fadeIn() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ jQuery("#rightControl").fadeOut(); }
    else{ jQuery("#rightControl").fadeIn() }
	if(autoSlide)
		window.setTimeout(function(){tx_mcscontentslideshow_slide();}, tx_mcscontentslideshow_interval);
    }

	function tx_mcscontentslideshow_slide( direction )
	{
		if(!direction && !autoSlide) return;
		direction = direction?direction:tx_mcscontentslideshow_direction;
		currentPosition = (direction=="right") ? currentPosition+1 : currentPosition-1;
		if(currentPosition>=numberOfSlides)
			currentPosition = 0;
		manageControls(currentPosition);
		jQuery("#slideInner").animate( { "marginLeft" : slideWidth*(-currentPosition) }, tx_mcscontentslideshow_speed );
	}
}

