/*  some jittery color functions
 *
 *  changes color and margins slightly
 *  requires JQuery
 *
 *    russell holt
 *    rsl@russellholt.com
 * 
 */


/*  jitter_rgba_color

    slightly randomize the given rgba color within the given range
    returns a css rgba string of the form "rgba(r,g,b,o)"
    
    does not change the opacity

    range is the total distance that the randomized values will fall within,
    ie, + or - range/2
    
    example:
        jitter_rgba_color(100,100,100,0.5,10)
    may return
        "rgba(105,9)"
*/
function jitter_rgba_color(red, green, blue, opacity, range)
{
	x = Math.round(range/2);
	r = red + x - Math.round(Math.random() * range);
	g = green + x - Math.round(Math.random() * range);
	b = blue + x - Math.round(Math.random() * range);
	
	return "rgba(" + r + ',' + g + ',' + b + "," + opacity + ")";
}


// function sidebarcolors() {
//  
//  $("#sidebar a").each(function(i) {      
//      this.style.background = jitter_rgba_color(51,69,69,0.3 + 0.3*(i%2),10);
//  });
// }


/*
    sets the color and margins for my posts and project blocks
*/ 
function zap(sizes) {
    
	$("#sidebar a").each(function(i) {		
		this.style.background = jitter_rgba_color(51,69,69,0.3 + 0.3*(i%2),10);
	});
	    
    $(".post").each(function(i) {
        if (sizes) {
            this.style.marginLeft = (Math.round(Math.random() * 1000) % 5 + 10 ) + "%";
        }
        this.style.background = jitter_rgba_color(30,42,61,0.8,20);
    });

    $(".xproj").each(function(i) {
        if (sizes)
            this.style.marginLeft = (Math.round(Math.random() * 1000) % 8 + 20) + "%";
        this.style.background = jitter_rgba_color(100,180,100,0.3 + 0.1*(i%2),3); // 0.2 + 0.1*(i%2)
    	
    });
    
    $(".xmisc").each(function(i) {
        this.style.background = jitter_rgba_color(38,51,51,0.7,25);
        // if (sizes)
        //     this.style.marginLeft = (Math.round(Math.random() * 1000) % 6 + 21) + "%";
    });    
    
}
