var carousel_arr = new Array(), new_item = '';

function scrollCarousel(){
	$('.jcarousel-next').hover(function(){$(this).css('cursor','pointer')},function(){$(this).css('cursor','default')}).trigger('click');
}
function carouselInitCallback(carousel)
{
  $.each($('#storieslist').children(),function(i){
    var carousel_info = new Object();
    carousel_info.html = $(this).html();
    carousel_info.wide = $(this).css("width");
    carousel_arr.push(carousel_info);
  });
  /*
    TODO Create navigation
  */
  $('.jcarousel-next,.jcarousel-prev').insertAfter('.jcarousel-container');
  var auto_carousel = setInterval("scrollCarousel()", 5000);
}
function carouselInCallback(carousel,item,i,state,evt)
{
  var idx = carousel.index(i, carousel_arr.length);
  new_item = carousel.add(i,carousel_arr[idx-1].html);
  new_item.css('width',carousel_arr[idx-1].wide)
}
function carouselOutStart(carousel, item, i, state, evt)
{ 
}
function carouselOutCallback(carousel,item,i,state,evt)
{
 carousel.remove(i);
}
function hasaCarousel(){

     $("#storieslist").jcarousel({
            auto: 5,
            scroll:2,
            wrap:'circular',
            initCallback: carouselInitCallback,
            itemVisibleInCallback: {onBeforeAnimation: carouselInCallback},
            itemVisibleOutCallback: {onBeforeAnimation: carouselOutStart, onAfterAnimation: carouselOutCallback},
          	easing:'easeInOutCubic',
          	animation:1500
          });
}
