$(document).ready(function(){
    // Filter sliding up and down (on the homepage of the slider formats)
    $('.trigger-filter').toggle(function(){
        // scroll up
        $('.filter-wrap').animate({'height': 304}, 500, function(){
            $('.filter .arrow').css('background-position', '0 -8px');
        });

    }, function(){
        // scroll down
        $('.filter-wrap').animate({'height': 25}, 500, function(){
            $('.filter .arrow').css('background-position', '0 0');
        });
    });

    // More info click capture the iframe
    $('.iframe #slider a.info').click(function(e){
        e.preventDefault();
        parent.window.location = $(this).attr('href');
    });

    sBaseurl = $('base').attr('href');

});

// automatically rotate
var duration = 3000;
iInterval = 0;

function moveNext(){
    CF.moveTo('next');
}

function startAutoRotate(){
    iInterval = window.setInterval(moveNext, duration);
    $('.controls .toggleplay').html('stop');
}

function stopAutoRotate(){
    clearInterval(iInterval);
    $('.controls .toggleplay').html('start');
}

// get called after construction of Content Flow
var contentFlowReady = function(){
    // index iMiddenItemId request
    iIndex = 0;

    // the carousel center on the appropriate item
    //setTimeout('CF.moveTo(' + iIndex + ');', 1000);
    CF.moveTo(iIndex);

    // automatically rotate
    startAutoRotate();

    $('.controls .toggleplay').click(function(e){
       e.preventDefault;

       if($(this).html() == 'stop'){
           stopAutoRotate();
       } else {
            moveNext();
            startAutoRotate();
       }

    });

}

