/*
    jQuery.dropInfo.js v1.0
	Copyright (C) 2011 Daniel Harrison
	Date: Fri Feb 11
	
	Requires:
		- jQuery 1.4.x

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

(function($){  
	$.fn.dropInfo = function(options) {

		return this.each(function() { 

			// Internal vars
			var opts = $.extend({}, $.fn.dropInfo.defaults, options);
			
			//set obj vars
			var outer = $(this);
			var inner = $(this).children(".drop-down-info-inner");
			var header = inner.children("h2");
			var minHeight = header.outerHeight();
			var maxHeight = inner.outerHeight();
			
			
			//set css
			header.css('cursor', 'pointer');
			outer.css('height', minHeight);
			header.text(header.text()+' '+opts.openSymbol);
			
			header.click(
				function(){
					if(outer.height() <= minHeight){ //if closed - make open
						//close all others
						outer.parent().children(".drop-down-info-outer").animate({ height: minHeight}, opts.speed);
						//open this one
						outer.animate({ height: maxHeight}, opts.speed);
						//change + - on all children
						outer.parent().children(".drop-down-info-outer").children(".drop-down-info-inner").children("h2").each(function(i) {$(this).text($(this).text().replace(opts.closedSymbol, opts.openSymbol));});
						//change + - on this
						header.text(header.text().replace(opts.openSymbol, opts.closedSymbol));
					}else{ //if open - make closed
						$(this).parent().parent().animate({ height: minHeight}, opts.speed);
						//change + - on this
						header.text(header.text().replace(opts.closedSymbol, opts.openSymbol));
					}
				}
			);

		});  
	};  
	
	// plugin defaults - added as a property on our plugin function
	$.fn.dropInfo.defaults = {
		speed: 200,
		closedSymbol: '-',
		openSymbol: '+'
	};
})(jQuery);
