jQuery.fn.autoHide = function(interval,fadingInterval,num){

    var promos = this.children('li'),
    visible = num || 1,
    fadingTime = fadingInterval || 'slow',
    idx_cloned = 0,
    idx_next = visible,
    $self = this,
    intervalId = null;
    if (promos.length <= visible) return this;
    //create visible elements to avoid jumps
    var cloned = promos.css({
        opacity:0
    }).filter(':lt('+visible+')').clone(false).addClass('cloned').prependTo(this);
    //autopositionize elements to avoid jumps during animations. I suposse all elements are equiespaciated
    var pos = cloned.next().position();
    for (var i = 0;i<visible;i++)
    {
        $(cloned[i]).css({
            position:'absolute',
            top:pos.top*i,
            left:pos.left,
            opacity:1,
            'z-index': (visible*2)-i

        }).show();
        
    }

function nextPromo(){

    $self.children('.cloned').each(function(i) {
        $(this).css('z-index', (visible*2)-i)
    });

    var old = $self
    .children().eq(idx_cloned)
    .animate({
        opacity:0
    },fadingTime,function(){
        $(this).remove();
    });

    var pos = old.position();
    promos.eq(idx_next)
    .clone(false).addClass('cloned')
    .insertAfter(old).css({
        position:'absolute',
        top:pos.top,
        left:pos.left,
        opacity:0,
        "z-index":num
    }).animate({
        opacity:1
    },fadingTime,function(){
        if ($.browser.msie) this.style.removeAttribute('filter');
        $(this).removeClass('added');
    });

    if (++idx_cloned == num) {
        idx_cloned = 0;
    }

    if (++idx_next == promos.length) {
        idx_next = 0;
    }
}

this.bind('inview', function (event, visible) {
    if (visible) {
        if (!intervalId) {
            intervalId = setInterval(nextPromo,interval);
        }
    } else {
        if (intervalId){
            clearInterval(intervalId); intervalId = null;
        }
    }
});
return this;
}

$(document).ready(function() {
	$('#footer div.promotion ul').autoHide(5000,1000,1);
});