var SCROLL = {
    init: function(){
        var self = SCROLL;

        self.IMAGES = $.map([1,2,3,4,5,6,7,8,9,10,11], function(val){
            return "/media/img/b" + val + ".jpg"; });
        self.SCROLL_CYCLE = 2; // seconds between cycles

        var ordered = [];
        var oc = function(a){ // object convertor, allows "in" testing for arrays
            var o = {};
            for(var i=0;i<a.length;i++)
                o[a[i]]='';
            return o;
        }
        do{
            var x = Math.floor(Math.random()*self.IMAGES.length);
            if(!(x in oc(ordered)))
                ordered.push(x);
        }while(ordered.length != self.IMAGES.length);

        self.ordered = ordered;
        self.current = 0;
        self.alternator = true;
        self.cycle();
    },
    cycle: function(){
        var self = SCROLL;
        
        var img = self.alternator ? $("#scroll li img")[1] : $("#scroll li img")[2];
        img.src = self.IMAGES[self.ordered[self.current]];
        
        self.current = self.current == self.ordered.length - 1 ? 0 : self.current+1;
        self.alternator = !self.alternator;
        self.timer = setTimeout("SCROLL.cycle()",self.SCROLL_CYCLE*1000);
    }
};
$(SCROLL.init);
