
var stopautoscroller = false;
function mycarousel_initCallback(carousel) {

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
		carousel.startAuto(0);
        stopautoscroller = true;
    }, function() {
        stopautoscroller = false;
		carousel.startAuto(4);
    });

	jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        stopautoscroller=true;
		carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        stopautoscroller=true;
        carousel.prev();
        return false;
    });
};
var mycarousel_itemList = new Array();
function getCarouselItemList() {
	var d = document.getElementById("mycarousel");
	if(d) e = d.getElementsByTagName("img")
	if(e.length>2) 
		for(var i=0; i<e.length-2; i++) {
			mycarousel_itemList.push({url:e[i].src, title: e[i].alt});
		}
}
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="371" height="265" alt="' + item.title + '" />';
};

// Ride the carousel...
jQuery(document).ready(function() {
   getCarouselItemList();
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
		auto: 4,
		wrap: 'circular',
        initCallback: mycarousel_initCallback,
	 	itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
    	itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
       
	    // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
