/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
 var carousel_1;
function carousel_1_initCallback(carousel) {
		carousel.selected=1
		jQuery('.carousel_1_control a').bind('click', function() {
	    	//alert(this.className)
			carousel.startAuto(0);
	        carousel.scroll( this.className);
	        return false; 
	    });

    jQuery('#box_carousel_prev').bind('click', function() {
        carousel.next();
        carousel.startAuto(0);

        return false;
    });

    jQuery('#box_carousel_next').bind('click', function() {
        carousel.prev();
        carousel.startAuto(0);

        return false;
    });
    
        // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

};



function carousel_1_beforeAnimation(carousel,element,i,status){
		$('#carousel_1_slide_'+carousel.selected);    
    var idx = carousel.index(i, carousel.options.size);
		carousel.add(i,carousel.get(idx).html())
  	}
        	
function carousel_1_afterAnimation(carousel,element,index,status){
    var idx = carousel.index(index, carousel.options.size);
		carousel.selected=idx
		$('#carousel_1_slide_'+idx);
		}

function carousel_1_itemVisibleOutCallback(carousel, item, i, state, evt){
   	if (i>carousel.options.size || i<0){
    	carousel.remove(i);
    	}
  	carousel.startAuto();
		};
	

// setup the carousel...
jQuery(document).ready(function() {
    jQuery("#carousel_1").jcarousel({
        start: 1,
        size: 3,
		auto: 4,
        animation: 1900,
        scroll:1,
        wrap: 'circular',
        initCallback: carousel_1_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback: {
  					onBeforeAnimation: carousel_1_beforeAnimation,
  					onAfterAnimation: carousel_1_afterAnimation
						},
				itemVisibleOutCallback:carousel_1_itemVisibleOutCallback
    });
});
