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);
};


function my_itemFirstInCallbackBefore (carousel, item, i, state, evt) {
	$('#curr').animate({ opacity: 0 }, 100);
	$('.jcarousel-item.current').find('.image img').animate({ 
        width: "126px",
       	left: "0",
        top: "0"
      }, 100 );

	$('.jcarousel-item.current').removeClass('current');
	
}
function my_itemFirstInCallbackAfter (carousel, item, i, state, evt) {
	var curr = $(item).next().next().next();
	

	$('.jcarousel-item').css('zIndex','11');
	$('#curr .name embed').attr('flashvars', 'textalign=left&offsetTop=0&textcolor=#000000&hovercolor=#CCCCCC&linkcolor=#000000&w=270&h=25&txt=' +curr.find('.name').text());
    var embed = $('#curr .name embed');
    $('#curr .name embed').remove();
    $('#curr .name').append(embed);

    $('#curr .position').text(curr.find('.position').text());
    $('#curr .logo img').attr('src',curr.find('.logo img').attr('src'));
    
    curr.find('.image img').animate({ 
        width: "250px",
       	left: "-72px",
        top: "-46px"
      }, 100 );

    
    curr.addClass('current');
    curr.css('zIndex','22');

   	$('#curr').animate({ opacity: 1 }, 100);
   	$(".jcarousel-item.current").hover(
      function () {
     	 return 1;
      }, 
      function () {
		return 1;
      }
    );
}

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



/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<div class="item"><a href="' + item.url + '"><span class="image"><img src="' + item.src + '" /></span> <span class="desc"><span class="company">' + item.company + '</span> <span class="name">' + item.name + '</span> <span class="position">' + item.position + '</span> <span class="logo"><img src="' + item.logo + '" /></span></span> </a></div>';
};

 


jQuery(document).ready(function() {
   
    jQuery('#mycarousel').jcarousel({
        wrap: 'circular',
        auto: 4,
        scroll: 1,
        initCallback: mycarousel_initCallback,
        itemFirstOutCallback: {onBeforeAnimation: my_itemFirstInCallbackBefore},
        itemFirstInCallback: {onAfterAnimation: my_itemFirstInCallbackAfter},
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
        
    });
    
    /*
    $(".jcarousel-item").hover(
      function () {
     	
        $(this).append($('<span class="info"><span class="n">' + $(this).find('.name').text() + '</span><span class="p">' + $(this).find('.position').text() + '</span></span>'));
        $(this).css('zIndex', 22);

      }, 
      function () {
        $(this).find("span.info").remove();
        $(this).css('zIndex', 11);
      }
    );*/

    
});

