/**
 * $Rev: 200 $
 */

var BUBBLE_TOP    = ['ba-top.png', 'bb-top.png', 'bc-top.png'];
var BUBBLE_BOTTOM = ['ba-bottom.png', 'bb-bottom.png', 'bc-bottom.png'];

var OFFSET_MIN = 0;
var OFFSET_MAX = 50;

function rand(min, max) {
    return min + Math.floor(Math.random() * max);
};

function getRandomBubbleStyle() {
    
    var top, bottom, offset;
    
    top    = BUBBLE_TOP[rand(0, BUBBLE_TOP.length)];
    bottom = BUBBLE_BOTTOM[rand(0, BUBBLE_BOTTOM.length)];
    offset = rand(OFFSET_MIN, OFFSET_MAX);
    
    var ret = {"top": top, "bottom": bottom, "offset": offset};
    
    //console.log(ret);
    
    return ret;
}

function applyBubbleStyle($bubble, style) {
    
    var top    = style.top || BUBBLE_TOP[0];
    var bottom = style.bottom || BUBBLE_BOTTOM[0];
    var offset = style.offset || 0;
    
    $bubble.css("margin-left", offset + "px");
    $bubble.find(".title").css("background-image", "url(/img/bable/" + top + ")");
    $bubble.find(".meta").css("background-image", "url(/img/bable/" + bottom + ")");
}

function randomize() {
    $(".bubble").each(function(i, bubble) {
        //console.log(arguments);
        applyBubbleStyle($(bubble), getRandomBubbleStyle());
    });
}

$(function(){randomize();});