/**
 * jQuery Alternation Markup Plugin
 * 
 * Copyright 2009, nojimage (http://php-tips.com/)
 * 
 * Licensed under The MIT License Redistributions of files must retain the above
 * copyright notice.
 * 
 * @filesource
 * @version 1.0
 * @author nojimage <nojimage at gmail.com>
 * @copyright 2009 nojimage
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link http://php-tips.com/jquery/2009/12/jquery-alternation-js 
 * @modifiedby nojimage <nojimage at gmail.com>
 * 
 */
(function($)
{
    jQuery.fn.alternation = function(params)
    {
        
        var options = {
            classname : 'alter',
            each : 2,
            callback : null
        };
        
        options = jQuery.extend( {}, options, params);
        
        var idx = 0;
        jQuery(this).children().each(function()
        {
            if (idx++ % options.each == (options.each - 1)) {
                jQuery(this).addClass(options.classname);
                if (typeof options.callback == "function") {
                    options.callback(this);
                }
            }
        });
    }

    jQuery.extend( {
        "alternation" : function(params)
        {
            
            var options = {
                selector : '.alternation'
            };
            options = jQuery.extend( {}, options, params);
            
            jQuery(options.selector).each(function()
            {
                jQuery(this).alternation(options);
            });
        }
    });
})(jQuery);
