
var mycarousel_itemList = [
   {link_target: 'pages/referenzen_entega.html', img_alt: 'BCP Gold Award', url: '../images/stage/querdenker.gif'},
  {link_target: 'pages/referenzen_sw_leipzig.html', img_alt: 'ENERGIE PLUS, Magazin mit neuem Layout', url: '../images/stage/swl_magazin.gif'},
    {link_target: 'pages/referenzen_eby.html', img_alt: 'Ausgezeichnetes Magazin zum Kulturpreis Bayern', url: '../images/stage/bayerns_beste.gif'}

];

function mycarousel_initCallback(carousel) {
    $('.stageControl').css({opacity: 0.7});
    $('.stageControl').hide();
    // pause autoscrolling and show the controls if the user moves with the cursor over the clip.
    carousel.clip.mouseenter(function(){
        carousel.stopAuto();
    }).mouseleave(function(){
        carousel.startAuto();
    });

    $('#homeStageModule').mouseenter(function(){
      $('.stageControl').fadeIn();
      carousel.stopAuto();
    }).mouseleave(function(){
      $('.stageControl').fadeOut();
      carousel.startAuto();
    });

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

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.startAuto(0);
        carousel.prev();
        return false;
    });
};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    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 mycarousel_getItemHTML(item)
{
   var tmpHtml = '<a href="' + item.link_target + '"><img alt="' + item.img_alt + '" src="' + item.url + '"/></a>';
   return tmpHtml;
};

// ride the carousel...
$(document).ready(function() {
    jQuery("#homeStageModule").jcarousel({
        scroll: 1,
        auto: 3,
        wrap: 'circular',
        animation: 800,
        buttonNextHTML: '<a href="#" class="stageControl"></a>',
        buttonPrevHTML: '<a href="#" class="stageControl"></a>',
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}

    });
});
