var margin = 0;
var value = 1;

function CarouselMove( index ) {
    var element = document.getElementById( 'carousel-pictures' );
    var diff = ( ( index - 1 ) * 1000 );
    if ( index < value ) {
	if ( diff != Math.abs( margin ) ) {
	    element.style.marginLeft = ( margin + 20 ) + "px";
	    margin += 20;
	}
    } else {
	if ( diff != Math.abs( margin ) ) {
	    element.style.marginLeft = ( margin - 20 ) + "px";
	    margin -= 20;
	}
    }
    value = index;
}

function MovePicture( element, value ) {
}

function sleep(timeout) {
    var loop = true;
    var current = new Date();
    var now;
    var cTimestamp = current.getTime();

    while( loop ) {
	now = new Date();
	nTimestamp = now.getTime();

	if( ( nTimestamp - cTimestamp ) > timeout)
	    loop = false;
    }

}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
	    carousel.startAuto(0);
	});
    
    carousel.buttonPrev.bind('click', function() {
	    carousel.startAuto(0);
	});
    
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
	    carousel.stopAuto();
	}, function() {
	    carousel.startAuto();
	});
};

jQuery(document).ready(function() {
	jQuery('#mycarousel').jcarousel({
		auto: 6,
		    wrap: 'last',
		    initCallback: mycarousel_initCallback
		    });
    });


