 /*jQuery Colourific-v 1.0-January 2008-by ben watts (http://www.benwatts.ca/sandbox/jquery-colourific/)*/
 
 $(document).ready(function(){
    setupColourific();
 });
 

 function setupColourific(){
    var elem = $(".colorific");
    var chars = elem.text().split("");
    elem.text("");
    for (var i=0; i<chars.length; i++){
        changeColour(chars[i], elem); 
    }
  }
 
 // changeColour
 function changeColour(e, elem){
    // random values between 0 and 255, these are the 3 colour values
    var r = Math.floor(Math.random()*256);
    var g = Math.floor(Math.random()*256);
    var b = Math.floor(Math.random()*256);
    var n = Math.floor(Math.random()*20);
    if (n % 2 == 0){
        n = 30 + n;
    } else {
        n = 40 - n;
    } 
    // puts the hex value inside this element (e is a jquery object)
    var nc = $("<span>").text(e);
    nc.css("color", getHex(r,g,b))
    nc.css("font-size", n)
    elem.append(nc);
 }
 // intToHex()
 function intToHex(n){
    n = n.toString(16);
    // eg: #0099ff. without this check, it would output #099ff
    if( n.length < 2) 
        n = "0"+n; 
    return n;
 }
 // getHex()
 // shorter code for outputing the whole hex value
 function getHex(r, g, b){
    return '#'+intToHex(r)+intToHex(g)+intToHex(b); 
 }



