jQuery(document).ready(function($) {

  // All site colours
  var styles = ['green', 'yellow', 'blue', 'pink'];
  var splash = null;

  // Tesh current body class
  if ($('html').hasClass("splash")) {
    splash = true;
  };

  // Get cookie if it exists
  var currentCookie = $.cookie('style');

  if (currentCookie && !splash) {
    // set style for this page based on current cookie
    $('html').attr('class', currentCookie);
  } else {

    // get random style
    var randomColor = styles[Math.floor(Math.random() * styles.length)]

    // set html class to random style
    $('html').attr('class', 'style-' + randomColor);

    // set new cookie based on random style
    $.cookie('style', 'style-' + randomColor, {path: '/'});
  };

  // get selected stylesheet
  $('#colour_selector li a').click(function(e){
    // kill default action
    e.preventDefault();

    // get the selected style
    var style = $(this).attr('rel');

    // set style for this page
    $('html').attr('class', style);

    // set session cookie for this style
    //$.cookie('style', style);
    $.cookie('style', style, {path: '/'});
    
  })

  // attach fancybox events
  $("a.popup").fancybox();

})
