jQuery.noConflict();
jQuery(document).ready(function() {
	
	
		
	// carousel
    
    // settings
    var slideWidth = 310;
    var duration = 500;
    var slidesDiv = jQuery('#slides');
    
    // variables
    var ctr = 0;
    var slidesTotal;
	
	
   	slidesTotal = jQuery('#slides').find('.slide').size();  
    jQuery('#slides').css({ 'width' : ((slidesTotal * (slideWidth+20)))+'px' }); 
    
    jQuery('#slides').show();
    jQuery('#prevSlide').show();
    jQuery('#nextSlide').show();
    jQuery('#counter').text(jQuery('#slides div p').eq(ctr).html());
    
    // handle button clicks
    jQuery('#prevSlide').click(function() {
        handleClick('prev');
        return false;
    });
    
    jQuery('#nextSlide').click(function() {
        handleClick('next');
        return false;
    });
    
    function handleClick(btn)
    {
        if(btn == 'next' && ctr < (slidesTotal-3)) {
            ctr ++;
            moveSlider();
        } else if(btn == 'prev' && ctr > 0) {
            ctr --;
            moveSlider();
        }
    }
    
    function moveSlider()
    {
        offset = (ctr == 0) ? 0 : (ctr*10);
                
        xLoc = "-"+(offset+(ctr * slideWidth))+"px";
        slidesDiv.animate({left:xLoc}, duration);
        
        var slideText = jQuery('#slides div p').eq(ctr);
        
        jQuery('#counter').text(slideText.html());
        
    }
    
    jQuery('#ng-container').jcarousel(
		{
	        scroll: 1,
	        visible: 3,
	        initCallback: ngCarousel_initCallback,
	        auto: 4
	    }
	);

});

function ngCarousel_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();
    });
};
