function mcgallery_itemLoadCallback(carousel, state)
{
	// Disable autoscrolling if the user clicks the prev or next button.



 	jQuery('#mcgallery-next').bind('click', function() {
        carousel.startAuto(2);
		carousel.next();
	 
        return false;
    });

    jQuery('#mcgallery-prev').bind('click', function() {
         carousel.startAuto(2);
		carousel.prev();
	
        return false;
    });
	
	
	
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
    // Since we get all URLs in one file, we simply add all items
    // at once and set the size accordingly.
    
	//if (state != 'init')
   //     return;

  //  jQuery.get('/dynamic_ajax.txt', function(data) {
  //      mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
  //  });
};

function mcgallery_itemAddCallback(carousel, first, last, data)
{
	  // Simply add all items at once and set the size accordingly.
    var items = data.split('|');

    for (i = 0; i < items.length; i++) {
        carousel.add(i+1, mcgallery_getItemHTML(items[i]));
    }

    carousel.size(items.length);
	
  
};

/**
 * Item html creation helper.
 */
function mcgallery_getItemHTML(url)
{
    return '<img src="' + url + '"  alt="" />';
};

jQuery(document).ready(function() {
    jQuery('#mcgallery').jcarousel({
		auto: 2,
		 scroll: 1,
		  wrap: 'circular',
		 vertical: true,
		 buttonNextHTML: null,
        buttonPrevHTML: null,
        itemLoadCallback: mcgallery_itemLoadCallback
    });
});

