$(document).ready(function(){

  $('html').addClass('js-on');
 
  // the two hex functions are from http://www.benwatts.ca/wp-content/storage/colourific/colourific.js
  // 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); 
  }

  // generate some random rgb color values
  var r = Math.floor(Math.random()*256);
 	var g = Math.floor(Math.random()*256);
 	var b = Math.floor(Math.random()*256);

  var r2 = Math.floor(Math.random()*128);
 	var g2 = Math.floor(Math.random()*128);
 	var b2 = Math.floor(Math.random()*128);
  
  // colorize stuff
	$('#navigation a').colorize(getHex(r,g,b), getHex(r2,g2,b2), [1,2,1],"backgroundColor");
	$('h2').colorize(getHex(r,g,b), getHex(r2,g2,b2), [1,1,1],"color");
 
  // set behaviours for #navigation
  $('#navigation dt a').each(function(){
    var linktext = $(this).text();
    linktext = linktext.substr(0,1).toUpperCase();
    $(this).text(linktext);
    $(this).parent().next().hide();
    // attach behaviour to the #navigation links
    $(this).bind("mouseover",function(){
         $("#navigation a").stop();
         $("#navigation a").fadeTo(1,0.1);
         $(this).fadeTo(1,1);
         $('h1').hide();
         var bgColor = $(this).css('background-color');
         $(this).attr('rel',bgColor);
         //$(this).css('color','#000');
         //$(this).css('background-color','#fff');
         $('#navigation dd').hide();
         $(this).parent().next().fadeIn('fast');
       }).bind("mouseout",function(){
         var bgColor = $(this).attr('rel');
         //$(this).css('color','#fff');
         //$(this).css('background-color',bgColor);
         $(this).parent().next().fadeOut('fast');
         $('#navigation a').fadeTo(1,1);
         $('h1').show();
    });
  });
  
});