function autoslide() {
	var x=document.x;
	var t=x+1;
	var z=x;
	var s=t;

	if(x==document.slider_count)
		s=1;
	
	$("#ja-scroll_"+x).animate(
    	{left: '-=311px'},2000,function(){
    		$("#ja-scroll_"+z).css( "left", "321px" );
    	}
	);
	
	$("#ja-scroll_"+s).animate(
	    	{left: '-=311px'},2000
	);
	
	if(x<document.slider_count)
		x++;
	else
		x=1;
	document.x=x;
}

$(document).ready(function() { //perform actions when DOM is ready
  var z = 0; //for setting the initial z-index's
  var inAnimation = false; //flag for testing if we are in a animation
  
  $('#pictures img').each(function() { //set the initial z-index's
    z++; //at the end we have the highest z-index value stored in the z variable
    $(this).css('z-index', z); //apply increased z-index to <img>
  });

  function swapFirstLast(isFirst) {
    if(inAnimation) return false; //if already swapping pictures just return
    else inAnimation = true; //set the flag that we process a image
    
    var processZindex, direction, newZindex, inDeCrease; //change for previous or next image
    
    if(isFirst) { processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1; } //set variables for "next" action
    else { processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1; } //set variables for "previous" action
    
    $('#pictures img').each(function() { //process each image
      if($(this).css('z-index') == processZindex) { //if its the image we need to process
        $(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
          $(this).css('z-index', newZindex) //set new z-index
            .animate({ 'top' : '0' }, 'slow', function() { //animate the image back to its original position
              inAnimation = false; //reset the flag
            });
        });
      } else { //not the image we need to process, only in/de-crease z-index
        $(this).animate({ 'top' : '0' }, 'slow', function() { //make sure to wait swapping the z-index when image is above/under the gallery
          $(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease); //in/de-crease the z-index by one
        });
      }
    });
    
    return false; //don't follow the clicked link
  }
  
  $('#next a').click(function() {
    return swapFirstLast(true); //swap first image to last position
  });
  
  $('#prev a').click(function() {
    return swapFirstLast(false); //swap last image to first position
  });

	document.x=1;
	document.slider_count=$(".slider_item").length;
	setInterval("autoslide()", 10000);

if($("#client_scroll").length){
    marqueeInit({
            uniqueid: 'client_scroll',
            style: {
                    'padding': '0px',
                    'width': '850px',
                    'height': '100px',
                    'margin': '0',
                    'padding': '0',
                    'vertical-align': 'top'
            },
            inc: 10, //speed - pixel increment for each iteration of this marquee's movement
            mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
            moveatleast: 2, //Minimum speed for 'cursor driven' marquee when mouse is off of it.
            neutral: 250, //Size of neutral area for 'cursor driven' marquee
            savedirection: true //(true, false, or 'reverse') Directional behaviour of 'cursor driven' marquee that has a moveatleast property when moused out.
    });

}

});
