/*
NTHFIX - 16/04/10
VERSION 2.1
BY whitneyit.com and evelution.net

NTHFIX is distributed under the MIT License
Read more about the MIT License --> http://www.opensource.org/licenses/mit-license.php

This script is just a beta test version, download and use it at your own risk.
The NTHFIX developer shall have no responsibility for data loss or damage of any kind by using this script.
*/

(function($){
 	$.fn.extend({ 
 		nthFix: function(options) {
			var defaults = {
				bot: false,
				css: {marginRight: 0},
				sel: '.item',
				cut: 2,
				rev: false
			};
			var options =  $.extend(defaults, options);
    			return this.each(function() {
				var o = options;
				if (o.bot === true) { o.bot = {marginBottom: 0}; }
				if ($(this).attr('rel')) { o.cut = $(this).attr('rel'); }
				var total = $(this).find(o.sel).size();
				var remainder = total % o.cut;
				var actual = total - remainder;
				var lines = actual / o.cut;
				switch (o.cut) {
					case 'first':
						$(this).find(o.sel).eq(0).css(o.css);
					break;
					case 'last':
						$(this).find(o.sel).eq(total-1).css(o.css);
					break;
					default:
						for (x = 1; x <= lines; x++) {
							$(this).find(o.sel).eq(o.rev ? (x-1)*o.cut: (x*o.cut)-1).css(o.css);
						}
					break;
				}
				if (o.bot !== false) { $(this).find(o.sel).slice(total-(remainder ? remainder : o.cut), total).css(o.bot); }
    			});
    		}
	});
})(jQuery);