Array.prototype.shuffle = function arrayShuffle(){
  var tmp, rand;
  for (var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i];
    this[i] = this[rand];
    this[rand] =tmp;
  }
};

$(document).ready(function(){
    if ($('#imageCycle').length) {
        var idx = parseInt(/header_(\d+)\.jpg/g.exec($('#imageCycle img').attr('src'))[1]);
        var headerImages = [];
        for (var i = 1; i <= 7; i++) {
            if (i == idx) {
                continue;
            }
            headerImages.push(i);
        }
        headerImages.shuffle();
        var headerImages2 = headerImages.slice(0); // Clone
        headerImages2.push(idx);

        function headerImage()
        {
            if (headerImages.length == 0) {
                headerImages = headerImages2.slice(0); // Clone
            }
            var $curr = $('#imageCycle img');
            var $next = $curr.clone();

            $next.hide().bind('load', function() {
                $curr.fadeOut(2000, function() {
                    $(this).remove();
                });
                $(this).fadeIn(2000);
                setTimeout(headerImage, 6000);
            })
            .attr('src', $next.attr('src').replace(/header_(\d+)\.jpg/g, 'header_' + headerImages.pop() + '.jpg'))
            .appendTo('#imageCycle');
        };
        setTimeout(headerImage, 6000);
    }
});