/*
<strong>whereas .toggle() just cycles between show() and hide(), powerToggle is better!</strong>
<em>powerToggle allows you to specify any functions to toggle between.</em>
This plugin was born from a need I had for a toggle fade function, but I figured - why not make it 100% customisable?

If all you need is a toggleable fade, just use the default config and write this:
<code>
$('p').powerToggle();
</code>
to fadeIn if the element is hidden, and fadeOut if not

or how about something like this:
<code>
$('p').powerToggle({inFunc: "slideDown", outFunc: "slideUp"});
</code>
for a toggleable slide effect? (yes yes, I know you can do it with .slideToggle already)

but you can even do something like this:
<code>
$('p').powerToggle({inFunc: function() {
		$(this).addClass("in");
	},
	outFunc: function() {
		$(this).removeClass("in");
	}});
</code>
for your own custom toggles!

By default it assumes "out" is hidden and "in" is visible, but you can override that by passing a third parameter, testFunc, check this code out:
<!--break-->
<code>
$('p').powerToggle({
	 inFunc: function() {
 		 $(this).addClass("in");
 		 $(this).slideUp();
	 },
	 outFunc: function() {
 		 $(this).fadeOut();
		 $(this).removeClass("in");
	 },
	 testFunc: function() {
 		 return !$(this).hasClass("in");
	 }
 });
</code>
so if your "p" tag has the class "in", it'll run outFunc, otherwise inFunc will be called.

I think the most common usage will probably be as a fadeToggle function, but the ability to customize with anon functions gives it vast potential for any time you need to toggle an element or series of elements between two states. Hope you enjoy my first plugin!*/
jQuery.fn.powerToggle = function(settings) {
// version 0.5

	// setup the defaults/override if sent
	var settings = jQuery.extend({
		inFunc: "fadeIn",
		outFunc: "fadeOut",
		testFunc: function() {
			return (this.css("display") == "none");
		}
	}, settings);

	var inIsString = (typeof(settings.inFunc)==typeof("a string"));
	var outIsString = (typeof(settings.outFunc)==typeof("a string"));

	// give functions access to $(this)
	jQuery.fn.pt_testFunc = settings.testFunc;
	jQuery.fn.pt_inFunc = settings.inFunc;
	jQuery.fn.pt_outFunc = settings.outFunc;

	this.each(function() {
		if(jQuery(this).pt_testFunc()) {
			if(inIsString) {
				// inFunc is (assumedly) already a member of jQuery (eg fadeIn etc)
				eval("jQuery(this)."+settings.inFunc+"();");
			} else {
				// we were been sent an anonymous function; run it
				jQuery(this).pt_inFunc();
			}
		} else {
			if(outIsString) {
				eval("jQuery(this)."+settings.outFunc+"();");
			} else {
				jQuery(this).pt_outFunc();
			}
		}
	});
	// return the jQuery object to allow chaining eg $("p").powerToggle().text("hello");
	return this;
};