/**
 * jQuery am.random-class plug-in 0.1
 *
 * http://www.articulatedman.com
 *
 * Copyright (c) 2009 Articulated Man
 *
**/

/**
 * Applies a randomly select class to a given DOM element from a provided list of classes
 *
 * @example $('body').random_class(['red','green','blue','yellow'])
 * @desc Randomly selects one of the four classes and assigns it to the body tag
 *
 * @example $('#content').random_class(['red','green','blue','yellow'])
 * @desc Randomly selects one of the four classes and assigns it to the DOM element with ID of content
 *
 * @example $('body').random_class(['red','green','blue','yellow'], { use_cookie: false })
 * @desc Randomly selects one of the four classes and assigns it to the body tag, but does not save it to a cookie
 *
 * @classes (Array) - required list of classes to be radomly selected from
 *
 * @option use_cookie (Boolean) - set to false to disable persistent behavior between page loads
 * @option cookie_name (String) - name of the cookie to store class in
 *
**/

jQuery.fn.random_class = function(classes,options) {

  el = this;

  settings = jQuery.extend({
    use_cookie:  true,
    cookie_name: 'random_class'
  }, options);

  if (!classes.length) alert("No classes defined for jquery.am.random_class");

  if ( settings.use_cookie && $.cookie( settings.cookie_name ) ){
    random_class = $.cookie( settings.cookie_name );
  } else {
    var i = Math.floor(Math.random() * classes.length );
    random_class = classes[i];

    if ( settings.use_cookie ) $.cookie( settings.cookie_name, random_class, { path: '/'} );
  }

  jQuery( el ).addClass( random_class );

  return this;
};